Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Audio Generation Actionscript 3

I'm looking into making a music theory lab application, where you can see the graphical relation between music theory concepts. I would like this to be available online, so Flash and Silverlight come to mind.

But I would like to dynamically generate tones and chords etc from user input. This is something I know is a very underdeveloped area in the Flash Player. So my question is what is the current state of features for dynamic audio generation on both the Flash and Silverlight players?

like image 472
BefittingTheorem Avatar asked Sep 20 '09 09:09

BefittingTheorem


2 Answers

From Flash Player 10 and onwards you don't need to do any hacky type stuff. There is an API to generate sound dynamically.

This blog post has a quick introduction. His code reads samples from an mp3 but you can write samples any way you want to.

As always the docs have lots of info too, along with this code sample which should get you going pretty quickly.

var mySound:Sound = new Sound();
function sineWaveGenerator(event:SampleDataEvent):void {
    for ( var c:int=0; c<8192; c++ ) {
        event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
        event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
    }
}

mySound.addEventListener(SampleDataEvent.SAMPLE_DATA,sineWaveGenerator);
mySound.play();
like image 161
grapefrukt Avatar answered Oct 10 '22 00:10

grapefrukt


You may try out The Synthesis ToolKit in AS3 which is ported from C++ by me :)

It's different from standingwave and popforge, STK in AS3 provides real-life instruments like flute and clarinet for you to use which the first two don't.

like image 26
Andy Li Avatar answered Oct 10 '22 02:10

Andy Li