title: Trying to draw a waveform with PHP and afreiday/php-waveform-png
body: <p>I have a waveform player but uses flash to generate a PNG waveform which isn't even accurate so I decided to use PHP and installed LAME Encoder on my CentOS 6.4. I found this script on github '<a href="https://github.com/afreiday/php-waveform-png" rel="nofollow noreferrer">afreiday/php-waveform-png</a>' and it works, based on the file you upload you get the waveform of the audiotrack. The only problem is that it's 'peaky'. An example:
  <img src="https://i.stack.imgur.com/IdITq.jpg" alt="example script from github"></p>
  
  <p>As you can see in the example (a EDM track with a singing part and bassdrop hard clap part) it's just not very useful, you can't scroll to the break because you can't see where it is. Unless you look closely at the very red area in the middle. So I know it's out there and the script works, but as I said before, it's just to 'peaky' and random.</p>
  
  <p>What I want is something like the picture below where you can obviously see the different parts in the track (taken from zippyshare with the same audiofile:
  <img src="https://i.stack.imgur.com/jfIG9.jpg" alt="what i want"></p>
  
  <p>The part of the code where it draws the lines seperately looks like this:</p>
  
  <pre><code>$v = (int) ($data / 255 * $height);
  if (!($v / $height == 0.5 &amp;&amp; !$draw_flat))
  
  // draw the line on the image using the $v value and centering it vertically on the canvas
    imageline(
      $img,
      // x1
      (int) ($data_point / DETAIL),
      // y1: height of the image minus $v as a percentage of the height for the wave amplitude
      $height * $wav - $v,
      // x2
      (int) ($data_point / DETAIL),
      // y2: same as y1, but from the bottom of the image
      $height * $wav - ($height - $v),
      imagecolorallocate($img, $r, $g, $b)
    );
  </code></pre>
  
  <p>Where $v is the volume.
  Now I tried adding something to get rid of the peaks but that didn't work out well:</p>
  
  <pre><code>if(isset($previous)) {
      $diff = abs($v-$previous);
      $perc = $diff / $v * 100;
      if($perc&gt;40) {
          $v = $previous;
      }
  }
  </code></pre>
  
  <p>Ofcourse that didn't do the trick but I thought I had something to work with there but it's not. Anybody an idea on how to solve this problem or had a similar experience?</p>
  
  <p>If an alternative to that script is better, let me know. Can't figure this out.</p>