Antti Kupila

Personal Blog, Portfolio and Online playground

View over the green room at Sid Lee, Montreal

SoundFX, out-of-the-box audio filters with actionscript 3

We had a project where we would have needed to apply something like a lowpass filter in real time on an audio track. Doing some research for this quickly triggered even further interest in audio programming. I also realized it’s not as scary as it first seems and a whole lot of fun. We deployed on Flash player 9 so we ended up going with another approach. Still, this is what came out of that.

While all the audio stuff isn’t as hard as it looks when reading the docs it can still be intimidating to a lot of developers. Hopefully this post will help out those guys. The key focus here was to keep the syntax as similar to the one we’re familiar with from display objects, the SoundFX class does all the heavy lifting. Take a look at the following syntax:

[as]
var sound : SoundFX = new SoundFX( new URLRequest( “music.mp3″ ) );
sound.filters = [ new CutoffFilter( 12000 ) ];
sound.play( );
[/as]

When you don’t have to worry so much about the nitty gritty stuff of making it work you can focus on the fun creative part. You can do basically anything you can do with display object filters, animate the properties etc. It’s a lot of fun ;)

A simple demo of how this works (flash player 10 required):

Go crazy with the filters :)
A couple small shortcuts will help you too:

  • Double click: default value
  • Shift + double click: maximum value
  • Command/ctrl + double click: minimum value
  • Shift + command/ctrl + double click: middle value
  • Click on visualizer to pause/resume playback (pretty cool if you’ve added some echo)
  • Double click visualizer to randomize all knobs

An added bonus here is added control over audio streaming. As with NetStreams you can specify how many seconds should be loaded before playback starts.

Source (includes SoundFX and the demo)

The filters are currently ported from C source at musicdsp.com (awesome resource!). Once i look a bit more into the math & magic behind the effects i’ll try to post new effects. Of course i’m more than happy to include any other people’s effects too, creating new effects is pretty simple.

Comments

65 Comments
  1. 2009-03-06, 21:43 by Bookmarks for March 6th from 15:32 to 15:32 « what i say // jon burger

    [...] SoundFX, out-of-the-box audio filters with actionscript 3 – Antti Kupila – [...]

  2. 2009-03-07, 11:59 by FlashBookmark

    Wow very nice, is it using fp10 features?

  3. 2009-03-09, 17:29 by LaKriss and other sweet stuff! » Blog Archive » Sound Effects

    [...] We’re planning to use flash 10’s new sound features at some point, so my mate Antti and colleague here at Sid Lee did this awesome little thing while testing the new features. Go play! [...]

  4. 2009-03-17, 0:56 by alparslan

    it`s very interesting. thank you

  5. 2009-03-18, 6:50 by Generative art assignment, Cellular Automata | Andy Li's Blog

    [...] i want to try a long time ago have been used in this Flash assignment: dynamic sound creation, SoundFX, Async-threading, Vector, FP10’s drawing API, [...]

  6. 2009-03-26, 21:58 by Caio Lazzuri

    this is awesome dude! you’re a fucking monster.

  7. 2009-04-01, 4:06 by efish

    I’m looking for this, nice work, good luck. Wish my soundX project can achive the same success.

  8. 2009-04-01, 4:17 by efish

    found an err in DelayFilter.as line 135
    public function set useMilliseconds(useMilliseconds : Boolean) : void {
    //135, it should be _useMilliseconds = useMilliseconds; right?
    useMilliseconds = useMilliseconds;
    if ( channelCopy ) channelCopy.useMilliseconds = useMilliseconds;
    }

  9. 2009-04-14, 22:52 by off1

    Very interesting. Looking to implement some mods on my own projects.

    THANX!

  10. 2009-05-19, 12:31 by Chicca

    It’s a very good work.
    But the loops parameter doesn’t seem to work. Do you know why?

    Chicca

  11. 2009-06-02, 16:54 by A.K.

    What song is it, and where can i find more music like it?

  12. 2009-06-06, 10:58 by theguaz®

    I came here because i was looking 4 nike lab info and i leave with the most valuable example of filters with flash10.

    So many thank’s men u make my day!

  13. 2009-06-10, 20:44 by SoundFX a library for realtime Sound Effects - blog.xperiments.es

    [...] info: out of the box audio filters with actionscript3 [...]

  14. 2009-07-04, 15:28 by nathan

    very nice – gonna have some fun with these; also and moreover, thanks for detailing the approach of porting c and giving the source for good effects!

    very much appreciated.

  15. 2009-07-16, 14:32 by Nicolas

    Hi,

    This filters are really really great,

    There is just something missing for my current swf :

    I need to change the volume and the pan during the sound, but there is no SoundChannel objet returned.

    Can you explain why ? Is there another way to handle volume and pan ?

    Thanks !

  16. 2009-07-16, 15:35 by Antti Author comment

    Hey Nicolas. You can pass in a SoundTransform when you call play(). Due to the architecture i can not return a SoundChannel when calling play (the way it works with the normal Sound). The main reason for this is to have the API as close to the Sound one.
    What you can do though is to modify the class so that you can get the SoundChannel. A reference to it is stored internally once it’s been created (SoundFX.as line 208), just dispatch an event and write a getter.

  17. 2009-07-18, 17:53 by Nicolas

    Hi Andy,

    Thanks for your quick reply (btw, you should add a “receive response option” to keep inform your reader)

    I understand the getter, but what’s the dispatcher for ? your internal SoundChannel is not accessible at the beginning ?

    Thanks, again.

    Nicolas

  18. 2009-08-05, 19:33 by j dennis

    is there any way to just get the wave scope code to work in the jw player as a plugin ?

  19. 2009-08-14, 10:52 by Chris Brown

    WOW, that’s awesome

  20. 2009-09-14, 16:58 by J

    great stuff!… don’t forget to check out the libraries here as well

    http://sazameki.org/

    some good Flash 10 audio libs and filters

  21. 2009-10-04, 12:05 by przemeko

    Hello.
    I have problem with very short mp3 files. If mp3 is shorter than 1 second soundFX don’t play any sound.

    Any suggestion?

  22. 2009-11-03, 23:01 by افکت گذاری بر روی صدا در as3 | مقالات آموزشی فلش

    [...] demo [...]

  23. 2009-11-26, 19:10 by Martial

    Hey that’s really great!

    But sadly if you try to play more than 3 sounds simultaneously with a filter, the fps down to 14/15 and mess all the stuff..

    I wonder if there is a way to optimize this !

  24. 2009-12-14, 14:09 by peko

    Thank you very much for this example!

  25. 2009-12-15, 18:39 by Matt

    This looks awesome, but getting it to work is a different story!

    Getting errors in both DelayFilter and FlangeFilter.

    Here is line 52 in DelayFilter: private var buffer : vector.;

    What is “”? Never seen anything like this in AS before!

  26. 2009-12-15, 18:44 by Matt

    Sorry, I should have known that it wouldn`t display!

    It seems that the problem is “Number” between greater than and less than symbols.

    This is one reason why I don`t like using Flex! Other people`s projects/code NEVER seem to compile right the first time!

  27. 2009-12-23, 15:00 by ziggomatic

    awesome work!

    could you please tell me the name of the artist of the song you use in
    this demo?

  28. 2009-12-23, 22:54 by Antti Author comment

    Martial: It was built to play one sound only. It could definitely be optimized to do multiple sounds (all filtered) if you wanted to. Having identical filters for all would be easiest

    Matt: You’ll need to compile with the Flex SDK 4. Vector is a new datatype added in Flash player 10.

    ziggomatic: Justice – New Jack

  29. 2010-01-04, 15:25 by Matt

    Thanks Antii! I just got Flash CS4 and it compiled without a hitch! Yes, I`m doing all my work in the Flash IDE, but it`s what I`m used too!

    Awesome stuff!

  30. 2010-02-11, 7:15 by audiosapien

    Nice work! There’s a pretty cool AS3 dynamic sound library for Flash 10 by the guys at Sonoflash, it’s worth a look.

    http://www.sonoflash.com

  31. 2010-02-16, 14:07 by Joe

    This is outstanding! Thanks for sharing : )

  32. 2010-02-17, 18:22 by Pierre

    Hey, is there anyway to use a non-external MP3 / URL with this? Like just simply calling an embedded Sound in a swf?

    Maybe I missed it in the documentation, but please let me know if this is possible.

    Thanks!

  33. 2010-02-27, 22:36 by CatMaestro

    Hey, that’s a cool feature.
    Can you please tell why when I try doing the play button and the spectrum in seperated swf’s with localconnection between them, they work in any browser except of the IE.

    Thanks in advance!

  34. 2010-02-28, 22:27 by przemeko

    Hello
    About “optimized to do multiple sounds”.
    Can You give me any suggest how to do this ?

    For example:
    sndA = new SoundFX(new URLRequest(‘drums.mp3′));
    sndB = new SoundFX(new URLRequest(‘bass.mp3′));
    sndC = new SoundFX(new URLRequest(‘string.mp3′));

    When i try to play this sounds simultaneously the third one is always NOT synchronized! (all mp3 are 70 secunds long)

  35. 2010-03-09, 10:24 by Sean

    Hi there.

    I have not used Flex and are used to using Flash. Is there any chance of getting this to work in Flash, CS4, AS3. When I publish (Flash Player 10) using the script supplied at the top of the page .I keep on getting the error

    1180: Call to a possibly undefined method cutoffFrequency.

    I am keen to get this to work as I am working on a multi-user sound performance using UNION and would like the multiple online performers to change the EQ, or add effects, even very simple effects, to the sounds in real time.

    Any help would be appreciated.

    Thanks

    Sean

  36. 2010-03-09, 14:08 by Alperian

    The filters are fantastic although the resonance one was back to front (for me at least). Fantastic. How much of this functionality is built in to AS3? I am off to have a poke around.

  37. 2010-04-28, 11:06 by Matt

    Antti, I just got the filters working in an audio mixer I am making! Your classes are awesome and easy to read. I had to rip them apart a bit because I am using graphics that were created in the Flash IDE (knobs, text fields, etc…). Sorry about this!

    While I was testing the cutoff filter, I realized that it`s responsiiveness is less noticible the higher the frequency is. Most synth cutoff filters I`ve used seem to have a consistent effect on the sound as the dial is turned. What I figured out is that on most synths, cutoff must be implemented with a logarithmic response across the frequencies. I am making another knob class called “LogKnob” and will try to use it with cutoff and see if it makes a difference! What do you think?

  38. 2010-05-02, 5:43 by Matt

    Antti,

    I got the cutoff knob working logarithmically and it seems fine!

    Also, is there any way to turn the “low-pass” filter into a “hi-pass” filter? I imagine that it might only involve multiplying one or two variables by -1, but then again, I`m not a specialist in wave theory! Have you ever looked into that? It would be a cool addition to the filters!

    Thanks again!

  39. 2010-07-02, 6:08 by Nicklas

    Really impressive, hope i can achive something close to this soon :)

  40. 2010-07-21, 10:24 by Playing Audio with Flash « CODE@蝴蝶。夢

    [...] http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ 有呢個好正既 sound filter, 識做 echo, phase, feedback, cutoff, resonance 個d effect [...]

  41. 2010-07-22, 1:37 by Andrew Stone

    Great work, very impressed although I feel you should implement pitch and time filter.
    Pro tip: CTRL + C CTRL + V some of the filters from below if possible =).
    http://code.google.com/p/popforge/source/browse/#svn/trunk/flash/PopforgeLibrary/src/de/popforge/audio/processor/effects

  42. 2010-10-06, 1:00 by InspiritGames

    wow i am a dj now!) nice sample!

  43. 2010-10-11, 21:40 by encaps

    Simply Amazing! great Job! :P

  44. 2010-10-20, 19:25 by shoe

    yeah, this is truely epic. The controls are SO smooth and SO sweet. Beyond what I thought flash was capible of. Justice pwn as well, great choice.

  45. 2010-11-12, 1:07 by Doug Banks

    I need this effect (filters on sound) for NetStream resources, as opposed to Sound. I’d like to follow this example but I can’t find an equivalent event that notifies listened when sound data shows up in NetStream (there’s one for Video data).

    ???

  46. 2010-11-13, 15:30 by Cleveland

    hey, nice blogreally like it and added to bookmarks. keep up with good work

  47. 2010-11-23, 22:08 by Adam

    Hi,

    Great work mate, I have found this really useful. Do you know if there is a way to save an edited audio file with this class. For example add the echo effect to an audio file and then save a new processed file?

    Cheers.

  48. 2011-01-03, 18:18 by AS3 CODE Library (API) - Mijimiji Blog

    [...] SoundFX – Out-of-the-box audio filters with ActionScript 3 http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ [...]

  49. 2011-01-06, 17:49 by Hello

    The song is Newjack by Justice for those who wanted to know.
    Took me a while to remember where I’ve heard it before, lol.

  50. 2011-01-31, 20:40 by Dourado

    PUfff…Excellent work!

  51. 2011-02-02, 16:08 by AS3 Code Libraries (APIs) « bytecoderz blog

    [...] SoundFX – Out-of-the-box audio filters with ActionScript 3 http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ [...]

  52. 2011-02-11, 16:05 by Jorge Luis

    Hi there,

    Thank you for sharing. :)

    It looks very well produced.

    JL

  53. 2011-10-31, 15:35 by ActionScript Фреймворк | НОВОЕ ИЗМЕРЕНИЕ

    [...] SoundFX — звуковые фильтры для AS3. ALF — библиотека для обработки звука в Flash. as3sfxr — порт C++ приложения sfxr. Генерирует звуковые эффекты как в старых-добрых олдскульных играх (дополнительная ссылка на проект:www.superflashbros.net/as3sfxr/). as3lameencoder as3wavsound — предоставляет возможность проигрывания .wav классов средствами Flash. [...]

  54. 2012-03-02, 19:06 by Generating Sound in AS3 « danielmurrayaudio

    [...] I am currently looking into run-time dsp on audio files opened by flash however its causing me some problems… (suggestions much appreciated ) there are however many great libraries for as3 that help with complex operations such as filtering (http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/). [...]

  55. 2012-04-12, 8:23 by 类库收集 | 嘟嘟晨的个人站点

    [...] http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ [...]

  56. 2012-07-08, 18:30 by [转]AS3 Code Libraries (APIs) | 南龙的小站

    [...] SoundFX – Out-of-the-box audio filters with ActionScript 3http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ [...]

  57. 2012-07-08, 23:33 by azrafe7

    To use Sound objects or embedded Sound objects (with FlashDevelop) instead of using URLRequest see http://flashpunk.net/forums/index.php?topic=4296.0

  58. 2012-07-13, 8:57 by AS3 经典的代码库 | badyoo RIA技术博客 AS3 flash adobe AIR

    [...] SoundFX – Out-of-the-box audio filters with ActionScript 3 http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ [...]

  59. 2012-08-10, 23:04 by Cameron

    Any info on how to increase performance? I’m working on making a sequencer that plays multiple sounds at once, and performance starts to chug as the number of sounds increases. Also if I try to edit some more complicated parameters (‘length’ in the delay filter, for example), the program also slows to a craw.

  60. 2012-09-03, 21:48 by Alain

    nice!!

  61. 2012-10-22, 5:04 by AS3 Class Library

    [...] SoundFX – Out-of-the-box audio filters with ActionScript 3 http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/ [...]

  62. 2013-01-21, 19:06 by HollowedP

    It’s bery awesome work! Thanks for sharing.
    But doed this class support loops???
    I can’t set it by loops parameter.

  63. 2013-02-01, 9:47 by Очень много полезных штук для AS3 #2 | BomBear

    [...] напишут более подходящий перевод). — Часть 4: класс Tone SoundFX — звуковые фильтры для AS3. ALF — библиотека для [...]

  64. 2013-02-14, 17:50 by Andrew Bramwell

    Hi there,

    Im trying to implement this within my project but I am getting this error

    1046: Type was not found or was not a compile-time constant: StreamingEvent.

    but what is strange is when im typing my imports it gives me suggestions that lead to importing “StreamingEvent” so flash is finding the files but somehow not using or forgetting about them.

    any ideas on how to fix this? does it require AIR?

    Many Thanks

  65. 2013-07-20, 22:05 by Oleg

    You seem somehow great!