Convert FFT data to FFT output on ComputeSpectrum

I use SoundMixer.computeSpectrum, but I need to get some data on the fly from the microphone (and I can not use SoundMixer with the microphone).

I'm having trouble translating FFT data (from this class ), as shown in this excellent example of spectral analysis , to fit the output ByteArrayfrom computeSpectrum. My existing code is built to process data received from computeSpectrum(s FFTset to true).

Any help is appreciated!

+3
source share
1 answer

, , m_mag . , computeSpectrum, ByteArray :

import flash.utils.ByteArray;

var fftBytes:ByteArray = new ByteArray();
for(var i:uint = 0; i < N/2; i++)
{
    var re:Number = m_tempRe[i];
    var im:Number = m_tempIm[i];
    var mag:Number = re*re + im*im;
    // Old method: write to vector
    // m_mag[i] = Math.sqrt(sample);
    // New method: write to ByteArray
    fftBytes.writeFloat(mag);
}
// microphone is mono, so make a copy to match computeSpectrum stereo output
fftBytes.writeBytes(fftBytes, 0, fftBytes.length);

fftBytes , computeSpectrum. , ByteArray, , computeSpectrum , . , , m_mag , ByteArray.

, SAMPLE_RATE N 44100 9 . computeSpectrum 256 , 44100 .

+2

All Articles