11.24.2008

Adobe Flash cs4

Well, finally some cross-over ... Flash CS4 (Flash Player 10) has the ability to generate sound using math. So naturally a sine wave is a function of sine...

Here's a bit of code I put together to show this off:
import flash.events.*;
import flash.media.*;
var sound:Sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, onCallback);
var channel = sound.play();
function onCallback(e:SampleDataEvent):void {
var noise:Number = Math.round(Math.random()*100)/100;
for (var i:int = 0; i <>
var sample:Number=Math.sin((Number(i/Math.PI/2)/6)));
e.data.writeFloat(sample * noise);
e.data.writeFloat(sample * noise);
}}
My noise variable in there makes the tone jump from pitch to pitch in an aleatoric fashion. John Cage in 12 lines of code.

My goal with this process is to create a fully-functional synth in flash, or at least some sort of drum machine clone with all the data derived by math.

Oh, if you modify this so that sample = math.random() you get some decent white noise. I'm still working on controlling the volume of the sound before being generated, and some filtering. But right now I'm just focusing on emulating the waves.

No comments: