I've researched a bit and I discovered a way to generate sounds dynamically on 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)
}
}
I would just like to know how I can make it generate the exact frequency I need, for example 100Hz.
Thanks!
Assuming 44.1kHz sample rate:
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);
If you haven't already, check out http://lab.andre-michelle.com/. The man does some cool stuff.
He has some sound synthesis examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With