c# - Wave file - processing specific chunk of audio data -
i'm trying iterate on wave file , send 20ms of every iteration. assuming i'm using 8khz, 1 channel, 16bit audio file, have below code using naudio:
wavefilereader wheader = new wavefilereader(fullfilename); byte[] data = new byte[wheader.length]; int read = wheader.read(data, 0, data.length); short[] samplebuffer = new short[read / 2]; short[] inpbuf; (int = 0; < read; += 2) { inpbuf = new short[159]; //20ms? buffer.blockcopy(data, 0, samplebuffer, 0, read); inpbuf = samplebuffer; process20(inpbuf); //send 20ms of audio data inside inpbuf }
i can see complete audio data inside samplebuffer (generated wave sine) cannot divide these 20ms inpbuf , see inpbuf contains whole audio data.
once understand issue i'll able move on stereo , different audio formats.
any appreciated, thanks.
the problem related blockcopy operation
buffer.blockcopy(data, 0, samplebuffer, 0, read);
you copying whole input buffer start each time because have not defined offset
see blockcopy documentation
Comments
Post a Comment