Storing a wav file in an array

I need a quick method to store all samples of a wav file in an array. I am currently working on this issue by playing music and storing values ​​from the Example Provider, but this is not very elegant.

From the NAudio demo, I have an Audioplayer class using this method:

private ISampleProvider CreateInputStream(string fileName) { if (fileName.EndsWith(".wav")) { fileStream = OpenWavStream(fileName); } throw new InvalidOperationException("Unsupported extension"); } var inputStream = new SampleChannel(fileStream, true); var sampleStream = new NotifyingSampleProvider(inputStream); SampleRate = sampleStream.WaveFormat.SampleRate; sampleStream.Sample += (s, e) => { aggregator.Add(e.Left); }; // at this point the aggregator gets the current sample value, while playing the wav file return sampleStream; } 

I want to skip this move of getting sample values ​​during file playback, instead I want the values ​​to be immediately, without waiting for the end of the file. Basically, like the wavread command in matlab.

+4
source share
1 answer

Use AudioFileReader to read the file. It is automatically converted to IEEE float patterns. Then we call the Read method to read the block of samples into the float [] array.

+1
source

Source: https://habr.com/ru/post/1469356/


All Articles