How to Calculate Frequency & Amplitude in Flash AS3 with Flash Player 9

流过昼夜 提交于 2019-12-24 04:06:08

问题


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:


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



来源:https://stackoverflow.com/questions/1803671/how-to-calculate-frequency-amplitude-in-flash-as3-with-flash-player-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!