Simple 3-band EQ with Flash Player 10
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 musicdsp.org and might not be the highest fidelity but should be fairly efficient.
You can also view this online example. (requires Flash Player 10)




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…
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.
@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
@spender
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.
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 ; } _eqL.compute(_sampleBufferL); _eqR.compute(_sampleBufferR); i = 0; while (i < BUFFER_SIZE) { l = _sampleBufferL[i]; r = _sampleBufferR[i]; _out_snd.samplesCallbackData.writeFloat(l); _out_snd.samplesCallbackData.writeFloat(r); 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.
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.