Fast Fourier Transform for Flash

FFT simple usage example

There is smth new I would like to share with Flash community: ASFFT Project. Well project is too loud name as far as it is only small library that allows users to decompose images using Fast Fourier Transform in to Real and Imaginary parts. But if you dig more in to the title you will find lots of amazing possibilities it brings to you. The problem is that it is pretty slow and can’t be used on processing video frames for example but it is fast enough to do different image manipulations without freezing Flash Player.

The lib will contain 2 classes “FFT2D” and “FFT”. First one is to work with two dimensional data mostly presented as images. The second one is for streaming (or not) one dimensional data. Usually used in sound signal manipulations/transformation.
At this very moment only FFT2D class available. I will add one dimensional FFT class in near future.

Simple demo example of FFT usage
Project page at Google Code

26 Responses to “Fast Fourier Transform for Flash”


  1. 1 John C

    Did you code the algorithm from scratch or have you found a way to use the native fourier transform in the SoundMixer.computeSpectrum()?

  2. 2 Eugene

    this one has nothing to do with SoundMixer.computeSpectrum(). It is written from scratch to use the power of Alchemy for extreme data analyze. Currently available class is FFT2D that is 2 dimensional (image based) FFT computation.

  3. 3 John C

    Nice work. I just noticed the C code in there. I’ve only ever heard of FFT being used for sounds, didn’t realise it could be used for image manipulation.

    J

  4. 4 nicoptere

    you are my hero.
    this can be sooooo useful.
    keep up!

  5. 5 makc

    How does it compare to http://rest-term.com/archives/1345/ ?

  6. 6 Rezmason

    This is excellent work. Regarding a 1D FFT: SoundMixer.computeSpectrum(true) has baffled me for months. Its output has a quality that I’ve never been able to replicate. If your FFT1D offering does the trick– which seems likely, after looking at FFT2D– you’ll effectively be freeing the whole community from the inadequacies of computeSpectrum.

    Thanks in advance.

  7. 7 Eugene

    @makc u can easily compare it. as for the first look this one supported RGB data. and i think this version is faster

  8. 8 makc

    well yes, that operates on Vector.-s, not pixels, but it makes sense in case anyone wants to run it on anything else than images.

  9. 9 makc

    Vector.{Number}-s that was

  10. 10 Eugene

    @makc if you read my post and look trough the source u would see that this one used not only for pixels but also for vectors and ByteArrays and simply gives you a chance to reuse Pixel bender filters for data re-processing. and that along with this class also 1D version is coming soon with ability to work with simple 1d data such as sound signal.

  11. 11 makc

    yep, I looked at http://code.google.com/p/in-spirit/source/browse/trunk/projects/ASFFT/src/ru/inspirit/math/FFT2D.as but only noticed initFromXXXBitmap() at first. I assume setDataVector() is general-purpose one?

  12. 12 Eugene

    @makc not really. as for me the best source is ByteArray as far as it can be used to combine Pixel Bender usage as filter processor. u also can work via BitmapData object

  13. 13 makc

    say, can you help me with this bit of code:
    re = new Vector. (w * w, true);
    im = re.concat ();
    var fftTest2:FFT2D = new FFT2D;
    fftTest2.setDataVector (re, FFT2D.REAL_RAW_DATA);
    fftTest2.setDataVector (im, FFT2D.IMAGINARY_FFT_DATA);
    fftTest2.forwardFFT ();
    re = fftTest2.getDataVector (FFT2D.REAL_FFT_DATA);
    trace (re.length); // traces 0
    what did I miss?

  14. 14 Eugene

    @makc well u have to init instance first. init(width, height, numChannels);
    u also dont need to set fftTest2.setDataVector (im, FFT2D.IMAGINARY_FFT_DATA); for the transform to work.

  15. 15 makc

    Thanks. But:

    [Fault] exception, information=RangeError: Error #1125: The index 10000 is out of range 10000.
    Fault, setDataVector() at FFT2D.as:317

  16. 16 Eugene

    @makc can u send me the full code u use to produce this error.

  17. 17 makc
  18. 18 Eugene

    @makc i assume the problem is cause Lib required data to fill the allocated buffer. so u should pass the buffer of required length not the one u just randomly selected

  19. 19 makc

    humm, what is required length?

    btw, it magically works on powers of two, e.g. for w=512 I have:

    time: 3011 ms
    time: 579 ms <- yours

  20. 20 Eugene

    @makc i corrected your code there. from 255 to 256. cause this is the power of 2 of provided 255 by you. so Lib created buffer of 256×256 and required u to fill it.

  21. 21 makc

    there was also code completion error, IMAGINARY_FFT_DATA instead of IMAGINARY_RAW_DATA. any way, I am getting 3.5 to 5.5 times faster times :)

  22. 22 Lieven

    Eugene can you be more precise in when the fft class will be available?

    Love your work!

  23. 23 Shawn

    Also anxiously awaiting the FFT implementation. Any idea when that will be up??

    Thanks man!

  24. 24 Nate

    Amazing work! I would be fantastic if you could explain a bit more about the FFT classes you have for sound in a blog post. I know you have some sample code on your google code site, but explaining the methods a bit more would be most helpful. I am checking out FFTSpectrumAnalyzer class specifically. Thanks man, you’re doing great work and benefiting the community big time! :-)

  25. 25 Nate

    To add to the above post in the FFTSpectrumAnalyzer, just a little background on these methods: initLogarithmicAverages, initLinearAverages and analyzeSpectrum. Thanks again! I will keep digging as well.

  1. 1 Schnelle Fourier-Transformation (1D + 2D) für ActionScript | zeroseven labs

Leave a Reply