Chapter 31 Example 6 actionscript.. forked:1favorite:0lines:19license : MIT License modified : 2010-02-05 06:35:33 Embed Tweet package { import flash.display.Sprite; import flash.events.SampleDataEvent; import flash.media.Sound; public class ch31ex6 extends Sprite { public function ch31ex6() { var sound:Sound = new Sound(); sound.addEventListener(SampleDataEvent.SAMPLE_DATA, onBufferSound); sound.play(); } protected function onBufferSound(event:SampleDataEvent):void { //for every sample, from the requested position through 8k samples later for (var t:int = event.position; t < event.position + 8192; t++) { //to generate a wave with any amplitude (volume) and frequency (pitch) //amplitude * sin(frequency * time) //the sin of this has 1 peak every seconds--is a 1Hz wave var tNormalized:Number = (t / 44100) * (2 * Math.PI); //write middle-C (261Hz) at full (1.0) volume to the LEFT channel event.data.writeFloat(1.0 * Math.sin(tNormalized*261.626)); //write G4 (392Hz) at low (0.2) volume to RIGHT channel event.data.writeFloat(0.2 * Math.sin(tNormalized*391.995)); } } } } Code Fullscreen Preview Fullscreen as3bible generate sound position Sound addEventListener play SampleDataEvent.SAMPLE_DATA SampleDataEvent Math.sin Math.PI Sprite int Number sort new page view favorite forked pv0 forked from: Chapter 31 Exampl.. pravin.kadam05 forked:0 favorite:0lines:19 (diff:1)