I am busy with my project and came upon a obstacle I cannot overcome. I have imported an audio file, at this moment only using .wav files, into a byte array. After that I loop through to find the data chunk in the file. My problem now is to convert that byte array to a double array before it is sent to be converted into a Complex array for the final DFT conversion where the complex array is converted to an array of frequencies.
I have gone through multiple web pages and none of the suggested code snippets works on my code. I either get an array of zeros or an array of NaN.
The following code identifies the data chunk:
byte wav = File.ReadAllBytes(sPath);
int iChannel = wav;
int iBitsPerSample = wav;
int iPos = 12;
while (!(wav[iPos] == 100 && wav[iPos + 1] == 97 && wav[iPos + 2] == 116 && wav[iPos + 3] == 97))
iPos += 4;
int iChunkSize = wav[iPos] + wav[iPos + 1] * 256 + wav[iPos + 2] * 65536 + wav[iPos + 3] * 16777216;
iPos += 4 + iChunkSize;
iPos += 8;
int iSample = (wav.Length - iPos) / 2;
if (iChannel == 2)
iSample /= 2;
Following the above code, I need to convert the byte array to a double array. As far as I know the double array needs to be in wave format.
For the complex and DFT conversion I am using the AForge.Math library in conjuction with the Hamming Windowing Function to cancel out any noise in the data.
Steps of the code:
1. Import wav file to byte array
2. Convert byte array to double array
3. Convert double array to complex array
4. Use Hamming function to cancel out noise from the complex array
5. Convert complex array to frequencies with the use of DFT
6. End product - array with frequencies.
The frequency array goes through more loops but that part of the code is working. My goal is to import an audio file and export the frequencies of the notes saved in the audio file.
Can anyone help? Any advice would be appreciated.
Thank you in advance.