Hi all,
I'm having issues with achieving something I'm sure you guys can assist.
I'm trying to iterate over a Wave file and process 20ms of the audio data each time. However, I'm getting confused with the bytes arrays and conversions and I'd be grateful if someone can assist on this with examples...
At the end I will need to handle several types (2-channels, 16Khz etc.) but for now I have a ready
8000hz, 1 channel 16bit file.
I'm using
NAudio for reading the file.
What I have tried:
WaveFileReader wHeader= new WaveFileReader(FullFileName);
byte[] data = new byte[wHeader.Length];
int read = wHeader.Read(data, 0, data.Length);
short[] shortBuffer = new short[read / 2];
int tBuf = 159;
short[] InpBuf = new short[tBuf];
int offst = 0;
Buffer.BlockCopy(data, 0, shortBuffer, 0, data.Length);
for (int i = 0; i < read; i += 2)
{
Buffer.BlockCopy(shortBuffer , offst, InpBuf, 0, tBuf);
offst += tBuf+1;
Process20ms(InpBuf);
Array.Clear(InpBuf, 0, InpBuf.Length);
}
Anyways, this doesn't work well, when I'm comparing the
inpBuf chunks to the full
shortBuffer I can see that the data in inpBuf[0] to inpBufp[78] is identical, but afterwards i get 00000 till inpBuf[159].
After inpBuf[160] I'm getting totally different data.
So, I'm confused with the Byte, Short, Blockcopy and samples, although it sounds very easy to achieve once I have the full audio data array.
Once I understand this I believe it will be much easier to process Stereo (2 channels) files as well.
Thanks...