Fun with code (since 2006)

Rendering spectrums with Sound.extract()


10.21.08 Posted in Actionscript 3 by

Yesterday I wanted to try the Sound.extract() method added in Flash Player 10, I came to this (Flash Player 10 only) little test, where a simple waveform of an external mp3 is rendered.

The power of Sound.extract() is that you can render a waveform of a sound before playing it, which was not the case of SoundMixer.computeSpectrum(). More than that, Sound.extract() is more precise than computeSpectrum().

As you can imagine, you have millions of samples in a usual sound, so if you want to render it you would normally need a huge bitmap that we could scroll.

In fact there are different approaches for handling this, mine was very simple, trick on x-axis and jump some values to get an average wave which is enough here. Just to play with it, you can select an area to loop.

Well in fact this is the kind of thing where we could never stop adding stuff :)

Sources (saved for Flash CS3 but to be compiled with Flash CS4)



57 Responses to “Rendering spectrums with Sound.extract()”

  1. Khaled says:

    Hi nice post is there a way to combine
    multiple sound data like mixing them
    and save them to hard drive ?

  2. sksamy says:

    Hi,

    your implementation of waveform and control is excellent.

    Can you share the action script & mxml

  3. sksamy says:

    can you provide flex version of this

  4. Awesome article Thibault. I decided to contribute a bit to the topic having beginner programmers in mind. Check my article: http://www.marinbezhanov.com/web-development/14/actionscript-3-sound-extract-demystified-or-how-to-draw-a-waveform-in-flash/

  5. I know, this post is soooooo old.
    But i’ve found an issue.
    If the file is shorter than one second, the extract method return 0.
    C’est fâcheux…

  6. Faisal says:

    Hello all, i am new at bytearray. I am building an application for sound mixing. when the user upload a mp3 file the application check that weather the file is clipped or not clipped, a clipped sound file are those which touch odb again and again. have you guys any idea how to achieve this in Flash as3.

  7. song says:

    at first,thank you for code.
    and i have a question in your code.
    why code there”do
    {
    step–;
    }
    while (step % 4);”
    what is meanning above?would you please tell me why?thank you again.

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh

ByteArray.org
Fun with code since 2006.