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 :)

15 Responses to “Sound.extract() rocks!”


  • I had the same problem with the FileReference class and posted about it yesterday http://www.richapps.de/?p=146 .
    If just these small problems are resolved this stuff will rock so much!

  • 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 SWF.play() 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,
    Richie

  • Ok, AudioBuffer.as 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.

    Gruß,
    Richie

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

    http://www.flexiblefactory.co.uk/flexible/

    Gimme a shout if you want more info…

  • Hey Spender,

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

    Cheers

  • Don’t worry. I’m on it!

  • Hey Joa,

    Take a look at our site now. :)

  • hey joa,

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

    Any chance you could outline the steps?

    tia,

    atom

  • 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.

  • I can’t hear a thing :|

  • Yep!

    Its very very awesome :)

  • Joa,

    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!

    Matt

  • 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”.

  • 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.

  • Joa,

    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 sound.play(), 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.

Leave a Reply