Display a audio waveform using C#

29,122

Solution 1

Visualize the data... Wow! You should check out the WAV file spec here and perhaps here and then re-think whether this is something you actually want to tackle. (The second link is actually a better, more streamlined overview. Take a look at the data section to see if it's something you want to work with.)

Don't get me wrong. Maybe this is exactly what you want to do, and it might be fun. You should just know what you're getting into!

Also, here's a Code Project component that you could use outright or look at for ideas.

Solution 2

I see this is an old question but in case someone is interested here is a solution:

Use the NAudio library: http://naudio.codeplex.com/

Here is a video tutorial on how to use NAudio to display waveforms: http://www.youtube.com/watch?v=ZnFoVuOVrUQ

Share:
29,122
Adir
Author by

Adir

Updated on July 16, 2022

Comments

  • Adir
    Adir almost 2 years

    I've already searched at Stackoverflow and google, but haven't found what I'm looking for.
    So far I got the audio raw data(WAV File) and I want to visualize it.

            private void Form1_Load(object sender, EventArgs e)
        {
            FileStream fs = new FileStream("D:\\tada.wav", FileMode.Open);
            BinaryReader reader = new BinaryReader(fs);
            char[] data = new char[4];
            long fsize;
            long wfxSize;
            long dataSize;
            WaveFormatEx wfx;
    
            //RIFF
            reader.Read(data, 0, 4);
    
            fsize = reader.ReadInt32();
    
            //WAVE
            reader.Read(data, 0, 4);
    
            //FMT
            reader.Read(data, 0, 4);
            wfxSize = reader.ReadInt32();
    
            byte[] wfxBuffer = new byte[wfxSize];
            reader.Read(wfxBuffer, 0, (int)wfxSize);
            wfx = new WaveFormatEx(wfxBuffer);
    
            //DATA
            reader.Read(data, 0, 4);
            dataSize = reader.ReadInt32();
            byte[] dataBuff = new byte[dataSize];
            reader.Read(dataBuff, 0, (int)dataSize);
            reader.Close();
    
            //Visualize the data...
        }
    

    I know I need to convert the raw data into samples and then check for the peak for each sample and draw lines, but I really don't know how to do it(except for the drawing).

  • Adir
    Adir almost 14 years
    By "Visualize the data" I meant display a simple waveform based on amp, not 3D Visualization... Anyway this code project component is really helpful, thanks.
  • Irakli
    Irakli over 4 years
    2 of 3 links are not valid