Sound.extract() rocks!

When Tinic Uro was implementing the dynamic audio features he was also giving us a very nice present called Sound.extract(). And it is simply awesome!

I wrote a simple experiment yesterday night using the popforge library. Yes — you can use it still with the new features and it is a great help. I just had to convert the sample data into a format for popforge.

The experiment is a simple flanger applied to an MP3. André wrote the flanger about a year ago but it is still fun listening.

The sourcecode will also show you how to loop sounds using Sound.extract(). It is a very safe way so that you get always as much data as you need.

There is only one problem right now. I wanted to use the new FileReference features so that you can load your own MP3s into the flanger. But unfortunately there is currently no easy way to do this. You would have to load the bytes, then create a SWF at runtime and inject the MP3. Then you could load that SWF with Loader.loadBytes() and once that is complete you can extract the sound. I thought doing that would be a little bit too much for a small demo :)


  1. Posted May 21, 2008 at 4:29 pm | Permalink

    I had the same problem with the FileReference class and posted about it yesterday .
    If just these small problems are resolved this stuff will rock so much!

  2. Richard
    Posted May 22, 2008 at 2:03 am | Permalink

    Hallo Joa,
    ich habe in den letzten Tagen mit 8bitboy rumgespielt und komme nun auf die Idee Geräusche damit zu machen.
    Also anhand von kurzen Mods will ich kleine Geräusche durch Mausklicks abspielen.
    Hab bis dahin auch alles hinbekommen, leider ist die Zeit zwischen Klick und Soundstart zu lang, dass’s wiederum kein Spass mehr macht.
    Wie kann ich meinen kleinen Mod in voller Länge vorher auf SWF drucken, so dass ich nachher einfach abspielen lassen kann?

    Falls die Erklärung dazu zu lang wird, kannst du mir auch einfach die entsprechende Klasse/n oder Funktion/en nennen.

    Vielen Dank und Lob fürs Engagement für die Community,

  3. Richard
    Posted May 22, 2008 at 1:24 pm | Permalink

    Ok, ist der Anfang.
    Aber wie das Zusammenspiel zwischen AudioBuffer und Mod-Format funktioniert weiss ich noch nicht, da ich null Ahnung vom Mod-Format habe.


  4. Posted May 23, 2008 at 3:28 pm | Permalink

    I’ve cracked the mp3 FileReference loading. Take a look here:

    Gimme a shout if you want more info…

  5. Posted May 23, 2008 at 4:37 pm | Permalink

    Hey Spender,

    that is pretty cool. Why are you not sharing your code? I think everyone would appreciate it.


  6. Posted May 23, 2008 at 7:14 pm | Permalink

    Don’t worry. I’m on it!

  7. Posted May 23, 2008 at 9:48 pm | Permalink

    Hey Joa,

    Take a look at our site now. :)

  8. Posted May 27, 2008 at 1:47 am | Permalink

    hey joa,

    You say “I just had to convert the sample data into a format for popforge.”

    Any chance you could outline the steps?



  9. Posted May 28, 2008 at 3:13 pm | Permalink

    Samples in the popforge library are represented using the Sample class. Therefore you have to read the floating point values and feed those into Sample objects. That’s about it.

  10. Shui
    Posted Jan 27, 2009 at 2:36 pm | Permalink

    I can’t hear a thing :|

  11. Posted Jul 29, 2009 at 3:01 pm | Permalink


    Its very very awesome :)

  12. Posted Mar 14, 2010 at 6:21 pm | Permalink


    Thank you for this!

    What I am particularly interested in is your looping code. I am building a 10-channel mixer and am doing the mix-down processing in Pixel Bender. Everything works great, but the full extent of the mp3 is not getting played because it is only playing TotalSamples/BufferSize and then looping back. I tried to implement your code, and it worked, however there is a short delay at the end of each loop. This delay/skip is the same even if I increase the buffer size. Is there anything I can do to improve it and remove the skip?

    Thank you for any help you can give. There aren`t many people doing this sort of thing with audio, so it can often be hard to find answers. I`m just waiting for you and Andre to someday write a book on Flash audio programming!


  13. Posted Mar 14, 2010 at 7:47 pm | Permalink

    MP3 files are not loopable by default. This is a problem of the format since a short amount of silence is added to the audio. If you want to have seamless loops you should take a look at Ogg/Vorbis or google for “mp3 encoder delay”.

  14. Posted Mar 15, 2010 at 4:19 am | Permalink

    Thanks for the reply Joa.

    My sounds are .wav files that have been embedded in the library and converted to mp3s from within Flash. Using your code on only one sound loops it perfectly with no gap. It`s only when I try processing 10 at a time, in a for loop, that the gap starts showing up!

    I can`t figure it out and it`s driving me crazy! Increasing the “buffer size” doesn`t make a difference. It has to be a small error on my side. I can send/post the code – only if you have time, of course.

  15. Posted Mar 23, 2010 at 9:22 am | Permalink


    I don`t know if you were refering to mp3s created within the Flash IDE, but if so, you were right! Apparently Flash does add silence to mp3s as well! It doesn`t show up if you loop a sound using, but if you try and extract the sound into a byteArray, around 1000ms of silence is extrracted along with it. To solve the problem, I just calculate the total number of samples when the sounds are first loaded, and then I use this number within the processSound() function to check if the extract position has exceeded (totalSamples – 2048). If it has, I then execute the looping code.

  16. djankey
    Posted Oct 28, 2011 at 12:58 am | Permalink


    please check this code:

    Try to record more than 2-3 seconds and then listen saved mix. Mixed sound is distorted after couple of seconds of recording
    Wav encoder is working ok…
    How to fix this?

    Thanks in advance!

2 Trackbacks

  1. […] Sound! Joa Ebert – Simple Astro Synthesizer (polyphone!) Joa Ebert – Astroboy (8Bitboy updated) Joa Ebert – Astroflanger (Sound.extract) Simple 3-band EQ with Flash Player […]

  2. […] Sound.extract() rocks!, por Joa Ebert […]