I am very new to digital audio programming and am not sure on if what I am doing is correct to get the desired outcome. I am trying to take a .wav file, and save the individual samples in an array so i can analyze them. I am using NAudio AudioFileReader, the following code prints out a vast number of floating point numbers, I have no idea if they would be correct, or they are being altered when converted. Ideally I would like them as 32 bit integers. Any advice on how to get there and understand greatly appreciated.
AudioFileReader readertest = new AudioFileReader("C:\\Users\\minford\\Downloads\\Kalimba.wav");
int bytesnumber = (int)readertest.Length;
var buffer = new float[bytesnumber];
readertest.Read(buffer,0,bytesnumber);
for(int i = 0; i <buffer.Length; i++){
Console.Write(buffer[i]+ ", ");
}
Yes, this will print out all the samples as floating point normalised into the range +/- 1.0.
And yes, you will see lots of numbers as there will be many thousands of samples per second.
I'm not sure why you need them as 32 bit integers. It's likely that the original samples are 16 bit integers, which is the most common choice for WAV files. You can use WaveFileReader
to read the raw data out into a byte array, and then use any one of several techniques for converting byte array to short array.