This project has moved. For the latest updates, please go here.

mp3 to sample array

Jun 8, 2015 at 9:13 PM
How can I use NAudio library to get sample float array from mp3 file?

Here is my code:
        float[] buffer = new float[2000];

        AudioFileReader reader = new AudioFileReader(filePath);
        reader.Read(buffer, 0, 2000);
After that buffer is always empty (only zeros inside).
Jun 12, 2015 at 5:50 PM

you read only the first 2000 samples of your mp3 file, which are all zeros when some silence is in there at start.

Besides that, it is a obviously very dangerous approach to assume it owns a fixed number of samples.
I recommend writing a While Loop and exit after you got 2000 samples if that is what you want. If you want the whole file as float array, run the While Loop completely through and better use a List of Float to store the samples dynamically.