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
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;
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 to inpBufp is identical, but afterwards i get 00000 till inpBuf.
After inpBuf 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.