如何在闪光灯上合成精确的频率?

Luc*_*cas 5 flash audio actionscript frequency actionscript-3

我研究了一下,我发现了一种在flash上​​动态生成声音的方法:

import flash.media.Sound;

var mySound:Sound = new Sound();

mySound.addEventListener(SampleDataEvent.SAMPLE_DATA, sineGenerateSound);

mySound.play();

function sineGenerateSound(event:SampleDataEvent):void{ 

 for(var i:int=0;i<4092;i++){  

  var n:Number = Math.sin((i+event.position)/Math.PI/4); 
  event.data.writeFloat(n)
  event.data.writeFloat(n)
 } 
}
Run Code Online (Sandbox Code Playgroud)

我想知道如何让它产生我需要的确切频率,例如100Hz.

谢谢!

Ada*_*ith 8

假设采样率为44.1kHz:

var freq:Number = 100; // example, 100 Hz, set this somewhere outside the for loop   
var n:Number = Math.sin((i+event.position)*freq*2.0*Math.PI/44100.0);
Run Code Online (Sandbox Code Playgroud)