views:

631

answers:

1

How can I calculate Frequency & Amplitude in As3 with FP9. I got the all raw byte using

SoundMixer.computeSpectrum(_testbytes, false, 0);
var g:Graphics = this.graphics;  
g.clear();       
g.lineStyle(0, 0x6600CC);
g.moveTo(0, PLOT_HEIGHT);            
var m:Number = 0;
for (var i:int = 0; i < 256; i++) {
    m = (_testbytes.readFloat() * 100);
    g.lineTo(i*2 , 100 - m);
}
g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);

Now Can I get the frequency & amplitude data from it?

+1  A: 

Hi Tanmoy.

If you have a closer look at the computeSpectrum() documentation, you will see the second parameter sets the FFT mode.

FFT stands for FastFourierTransform, basically if you use FFT over a waveform you go to the frequency domain which means instead of raw values, you have values that are sorted for you by frequency.

All you need to change in your code is :

SoundMixer.computeSpectrum(_testbytes, true);

Now in _testbytes you will have 512 values, 256 for the left channel and 256 for the right channel. For each channel the numbers are sorted by frequencies, low to high ( low, mid-low, mid-high, high I guess ).

That's all, you got the frequencies now. SoundTransform has volume, which is another way of saying amplitude I guess. If you feel like doing Math.max() on some of those frequencies or the leftPeak and rightPeak, go for it.

If you want to get nerdy with this, just lookup FFT on wikipedia or DSP(Digital Signal Processing) or Sound Processing, otherwise, the as3 documentation for computeSpectrum should be enough.

As for sample rate, this cool as library seems to do the hard work for you.

HTH, George

George Profenza
Hi George,Thanks for giving me a direction. In amplitude I am trying to calculating peak value from Sound Channel, is that wrong? another thing how can get the sample rate of any mp3 sound file?Thanks Again.Tanmoy
Tanmoy Mitra
I see, the updated answer seems to fit now ^_^
George Profenza