
Yesterday i went to the 2009 Flash Camp in Berlin which was well organized by the Berlin Flex Labs User Group. Many thanx to Bettina Schulz and Mathias Stäbler for this nice event.
I had the chance to listen to Thomas Reppa giving a good introduction to PureMVC (slides available here), to Cedric Madelaine talking about Actionscript 3D Engines and especially to André Michelle talking about the phenomenal Hobnox Audiotool.
He gave some really good insights about starting to program a virtual synthesizer based on actionscript and showed us in a step by step workshop how get something out of the speaker.
Here is a little code example about how to get a basic sinus tone:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
import flash.events.SampleDataEvent;
public class Main extends Sprite
{
private var sound:Sound;
private var phase:Number;
private var value:Number;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
phase = 0.0;
value = 0.0;
sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleDataHandler);
sound.play();
}
private function sampleDataHandler(e:SampleDataEvent):void
{
var amplitude:Number;
for (var i:int = 0; i < 3072;++i)
{
amplitude = Math.sin(phase * 2.0 + Math.PI);
phase += 220.0 / 44100.0;
amplitude = phase * 2.0 - 1.0;
value += (amplitude -value) * .01;
if (phase > 1.0) phase -= 1.0;
e.data.writeFloat(value);
e.data.writeFloat(value);
}
}
}
}
So basically this is a good starting point for experimenting with sound. Flashplayer 10 needed and like André Michelle said: “Protect your ears !”
More information on Hobnox Audiotool under http://opensource.hobnox.com/source/ or the checkout url for svn
http://svn.opensource.hobnox.com/trunk
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.