Friday, 6 May 2011

How to Convert AIFF files to WAV using NAudio 1.5

Thanks to Giawa, the latest NAudio source code (to be released with NAudio 1.5) has an AIFF File Reader. This makes it very easy to convert from AIFF files to WAV (or simply into PCM format for inputs to other NAudio streams). Here’s how to do it:

public static void ConvertAiffToWav(string aiffFile, string wavFile)
    using (AiffFileReader reader = new AiffFileReader(aiffFile))
        using (WaveFileWriter writer = new WaveFileWriter(wavFile, reader.WaveFormat))
            byte[] buffer = new byte[4096];
            int bytesRead = 0;
                bytesRead = reader.Read(buffer, 0, buffer.Length);
                writer.Write(buffer, 0, bytesRead);
            } while (bytesRead > 0);


TriFu said...

Hi there,

I apologize I don't know where to send you this question,

but I was trying to build a web based music visualizer and needed a way to read the mp3 data so I can analyze the volumn and frequency so I can visualize on it. I've been searching your blog and also googling online but haven't found a tutorial on how to use NAudio to read the sound values?

Do you think you could post up a example of how one could do this? Thank you so much for your time.

Anonymous said...

great article!

Anonymous said...

Can you show an article on how to read sound from an mp3?

Specifically, how to read volume so that one can make visualizations based on the change in volume of the music playing?

Unknown said...

@Anonymous, with the NAudio source code there is an NAudio demo app that will show you how to play MP3 and show waveform.