AS3 drawWaveform()

by yansern on September 22nd, 2010

This is my reinterpretation of the draw waveform codes found on the article “Rendering spectrums with Sound.extract()” by Thibault Imbert at http://www.bytearray.org/?p=329. My objective is to figure out what all those ambiguous numbers (4, 4096, 128, etc) meant and put them into properly commented variables names.

I hope this would be an eye-opener for others who are struggling to understand (just like I did).

Syntax: ActionScript 3
Show lines - Hide lines - Show in textbox - Download
6 Comments
  1. Hey yansern, thanks a lot, this will help me!

    cheers!

  2. Me again.

    It still needs some time to do the analysis. I wouldn’t need it as precise as it is at the moment, just very rough. I tried tweaking around in the code and found this line:

    var sampleLength:Number = Math.floor((sound.length / 1000) * sampleRate);

    if I change the 1000 to something like 5000, it becomes much faster, but the graph is painted way over the boundaries of the waveform bitmap now…

    Do you have an idea to get the same (just less precise) result with less data?

  3. Dieter permalink

    Hallo Yansern.
    I really like your reinterpretation of Thibault’s code. It was the final touch to almost understand everything of his code!
    I’m just wondering how I would make a waveform that is drawn ‘absolute’ instead of ‘relative’ to a certain waveform width?

    example:
    I have two clip; one of 4 sec and one of 8 sec.
    When drawing those 2 waveform the length is almost identical.

    What I like to get is that the length of the wave of 8 sec is double as long as the one of 4 sec?
    Can you help me with this please? I’m making a audio-editor application for my school?

    Kind regards

  4. Richard Brookes permalink

    Awesome! thanks mate, the comments really made it simple to understand. Appreciate the effort and works right off. I was wondering if you have any ideas about how we can compare to wave patterns to check for similarities.

    Thanks once again!

    Cheers!

    Richard

  5. You may be interested in reading this article as well: http://www.marinbezhanov.com/web-development/14/actionscript-3-sound-extract-demystified-or-how-to-draw-a-waveform-in-flash/

    It gives further info about drawing waveforms in Flash that’s more beginner oriented.

  6. jimenez permalink

    thank you man, all day trying this! and it works

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS