Yes, a Flash equalizer. We all heard it mentioned before…for some reason the word equalizer has been adopted to mean spectral analyser when mentioned along with Flash.


An equalizer will process the sound boosting or attenuating frequencies while a spectral analyser will only show you the spectral content of the audio.
Now with the new functionality of Flash Player 10 I hope this means that people will call things by their correct name since we now will have applications with both analysers and equalizers.


So with that off my chest, here is the code for an actual equalizer.

The algorithm is taken from this c++ snippet on and might not be the highest fidelity but should be fairly efficient.


You can also view this online example. (requires Flash Player 10)

Related posts:

  1. Flash Player 10 Sound API changes, SampleData and SampleDataEvent
  2. AS3 example…waveform display
  3. Simple rotating preload icon class
  4. Random thoughts on Vectors and samplesCallbackData
  5. Tweaking the samplesCallbackEvent loop

23 Responses to “Simple 3-band EQ with Flash Player 10”

Comments (18) Pingbacks (5)
  1. Well, it is a very neat trick for crashing my IE7 instantly anyhow :) I get this error when I try to change a slider:

    Error: Error #1023: Stack overflow occurred.

    If I say dismiss all, IE7 just closes instantly!

    BTW – I have Flash player – WIN 10,0,1,218 (debug) which might not be the version everyone else is using from labs…

  2. Hi,

    Good work! This stuff is fun, eh?

    You may want to consider doing all your calculations within a loop without external method calls. So, in Main.samplesCallback, your processing loop is calling _eq.compute on a sample by sample basis. I have found that the cost of function calls in this inner loop is very expensive. It would be better to pass _samples to the EQ instance, and operate on the entire buffer in a loop that has no external dependencies (i.e. does not call user defined methods). This will substantially reduce the number of function calls, and you’ll get much better performance that way.

    I’m also wondering if it is safe to pass both channels through the same filter. There is clearly some sort of feedback in the compute method, meaning that previous values passed to the compute function will affect its current output. Bearing this in mind, you are bleeding left and right channel data into one another by reusing the same filter for both the left and right channels.

  3. @Aran
    Thanks for pointing that out. I cannot test it in IE right now since I seem to have messed up my Flash player activeX install when trying to install FP10 on top of FP9, which usually works when using KewBee PluginSwitcher, but not this time :(

    Good points.
    It’s obvious that even with the speed of AVM2 working with audio will mean a lot of effort spent optimizing, especially if doing processing on many tracks.
    And well spotted about the stereo issue.
    I will make an updated version implementing your suggestions.

  4. Ok, I did some testing and I don’t manage to improve the performance by removing the function calls inside the loop for filling the buffer.
    In fact it’s even marginally slower.

    Basically What I did was this:

    while (i < BUFFER_SIZE) {
    	_sampleBufferL[i] = _samples.readFloat();
    	_sampleBufferR[i] = _samples.readFloat();
    	i  ;
    i = 0;
    while (i < BUFFER_SIZE) {
    	l = _sampleBufferL[i];
    	r = _sampleBufferR[i];
    	i  ;

    In the EQ class I then loop through the _sampleBuffer and write over the sample with the modified value.

    I did use an extra loop to split up the values from the _samples into separate vectors for the left and right channels, but I also tested by processing the two channels as one so I did not need that loop, and still the method of calling the EQ.compute function for each iteration is still somewhat faster.

    I have updated the source in the the original link to process the channels independently, which made an audible improvement, as well as having it display the average time it takes for each samplesCallbackEvent to process.

    If you are interested in the modified source I used for testing the approach suggested by spender (as I understood it at least) you can grab it here.

  5. ah well. maybe the improvement was more pronounced with me because of the way I am chaining several fx together… method calls really slowed things down.

  6. VerifyError: Error #1014: Class could not be found.

    at global$init()


  7. How can I make multi-band equalizer (like 5 band or 10 band or so on) … ? Somebody Please help me ..!!!

  8. Using your original script, I modified your script to run in Flex using the latest version of Flash 10. I also updated it to allow for 5-bands instead of only three. You can read my post about it for more information.

    Thanks so much for putting this out there. I looked for weeks for an answer on this, but had such a hard time with the math of it all. It’s been years since college and my math skills just aren’t what they used to be.

  9. hi,

    great work. especially by using the extract function.
    but i ve some problem with the SamplesCallbackEvent (is not a compile-time constant). Can someone tell me how can u fix it so that i can run it?

  10. This doesn’t display for me just blank page. That and the source won’t recompile. Written for FP9 ?

  11. It’s written for a beta of Flash Player 10, and the API was changed for the release version. So it’s not working with any stable versions of the player unless you make a few minor changes.

  12. I’d like to add more bands to this equalizer. Any idea how I would go about creating peaking filters? I’ve seen someone make a 5 band EQ out of this one but they seem to have made four low pass filters and one high pass instead of one low, one high, and three peaking.

  13. Great hammer of Thor, that is pweoruflly helpful!

  14. I’m also interested by a X band EQ (at least 5), any ideas ?

  15. Hi friends,
    This example works fine….but while you playing the mp3 i cannot seek the desired position… plays from the beginning
    if i change the position…If there anything to do with samplesCallback(event:SamplesCallbackEvent) function…

  16. This does not work anymore, I tested but the swf does not open, do you know any solution?.

  17. Ok I solved, to fix it:

    SamplesCallbackEvent is deprecated, so:

    private function samplesCallback(event:SamplesCallbackEvent):void{}

    private function onCallback(event:SampleDataEvent):void {}

    (Obviously you can change the function’s name)

    So must change this too:

    _out_snd.addEventListener(“samplesCallback”, samplesCallback);

    _out_snd.addEventListener(SampleDataEvent.SAMPLE_DATA, onCallback);

    Finally must give a greatest Buffer Size, 512 was not working to me, I was made all changes but this code was still not working for me, but when I set a greatest Buffer Size, then the trick was success.

    In resume:

    1. Use SampleDataEvent.SAMPLE_DATA because SamplesCallbackEvent is deprecated.

    2. You must to give a greatest BUFFER_SIZE, for example: 4096 because 512 does not work, at least for me.

    Thanks alot for this usefull code, now I’ll try to expand it to work with 5 or 10 bands.



Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 BlixtSystems Suffusion theme by Sayontan Sinha

Switch to our mobile site