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:
-
var sound : SoundFX = new SoundFX( new URLRequest( "music.mp3" ) );
-
sound.filters = [ new CutoffFilter( 12000 ) ];
-
sound.play( );
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
36 Comments
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 – [...]
2009-03-07, 11:59 by FlashBookmark
Wow very nice, is it using fp10 features?
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! [...]
2009-03-17, 0:56 by alparslan
it`s very interesting. thank you
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, [...]
2009-03-26, 21:58 by Caio Lazzuri
this is awesome dude! you’re a fucking monster.
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.
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;
}
2009-04-14, 22:52 by off1
Very interesting. Looking to implement some mods on my own projects.
THANX!
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
2009-06-02, 16:54 by A.K.
What song is it, and where can i find more music like it?
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!
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 [...]
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.
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 !
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.
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
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 ?
2009-08-14, 10:52 by Chris Brown
WOW, that’s awesome
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
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?
2009-11-03, 23:01 by افکت گذاری بر روی صدا در as3 | مقالات آموزشی فلش
[...] demo [...]
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 !
2009-12-14, 14:09 by peko
Thank you very much for this example!
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!
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!
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?
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
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!
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
2010-02-16, 14:07 by Joe
This is outstanding! Thanks for sharing : )
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!
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!
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)
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
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.
Post a comment