I'm trying to iterate over a wave file and send 20ms of it every iteration. Assuming I'm using a 8khz, 1 channel, 16bit audio file, I have the 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;
for (int i = 0; i < read; i += 2)
{
InpBuf = new short[159]; //20ms?
Buffer.BlockCopy(data, 0, sampleBuffer, 0, read);
InpBuf = sampleBuffer;
Process20(InpBuf); //Send 20ms of audio data which inside InpBuf
}
I can see that the complete audio data is inside sampleBuffer now (generated wave sine) but I cannot divide these 20ms into InpBuf and I see that InpBuf contains the whole audio data.
Once I understand this issue I'll be able to move on to stereo and different audio formats.
Any help is appreciated, thanks.