import * as WavDecoder from 'wav-decoder' ; import { XAudioBuffer } from '../XAudioBuffer' ; import { readFile } from '../pio' ; export async function loadWave ( filePath ) { const fileData = await readFile ( filePath ) ; const decoded = await WavDecoder . decode ( fileData ) ; const audio = new XAudioBuffer ( { sampleRate : decoded . sampleRate , numberOfChannels : decoded . channelData . length , length : decoded . channelData [ 0 ] . length } ) ; for ( let i = 0 ; i < decoded . channelData . length ; i ++ ) { const chan = decoded . channelData [ i ] ; audio . copyToChannel ( chan , i , 0 ) ; } return audio ; }