11.25.2008

Javascript Audio Generation

I haven't looked into the actual source code of this ... But javascript just joined the audio-generation racket, check this out:
http://ajaxian.com/archives/generating-and-playing-sound-in-javascript

And a couple of days ago somebody made a drum machine with (only) javascript:

That comes complete with an audio visualizer built in JS, but I suspect it gets the hits etc. from the switches themselves instead of the audio generated.

I love this renesaince of coding that's making music production much more easy to experiment with...

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.