title: Algorithm to draw waveform from audio
body: <p>I'm trying to draw a waveform from a raw audio file. I demuxed/decoded an audio file using FFmpeg and I have those informations: samples buffer, the size of the samples buffer, the duration of the audio file (in seconds), sample rate (44100, 48000, etc), sample size, sample format (uint8, int16, int32, float, double), and the raw audio data itself.</p>
  
  <p>Digging on the Internet I found this algorithm (more <a href="http://blogs.msdn.com/b/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx">here</a>):</p>
  
  <p>White Noise:</p>
  
  <p><img src="https://i.stack.imgur.com/t31Ek.png" alt="White Noise"></p>
  
  <p><strong>The Algorithm</strong></p>
  
  <blockquote>
    <p>All you need to do is randomize every sample from –amplitude to
    amplitude. We don’t care about the number of channels in most cases so
    we just fill every sample with a new random number.</p>
  </blockquote>
  
  <pre><code>Random rnd = new Random();
  short randomValue = 0;
  
  for (int i = 0; i &lt; numSamples; i++)
  {
      randomValue = Convert.ToInt16(rnd.Next(-amplitude, amplitude));
      data.shortArray[i] = randomValue;
  }
  </code></pre>
  
  <p>It's really good but I don't want to draw that way, but this way:</p>
  
  <p><img src="https://i.stack.imgur.com/M3QLO.png" alt="audacity"></p>
  
  <p>Is there any algorithm or idea of how I can be drawing using the informations that I have?</p>