Sound Amplitude Visualization Programming
This video shows how to create sound visuals that animate to the beat by creating a channel for the sound object. That way we can access the left and right peaks.
// Define the sound object and the sound channel
var snd:Sound = new Sound();
var req:URLRequest = new URLRequest("mp3_files/raquel my body.mp3");
snd.load(req);
var channel:SoundChannel;
channel = snd.play();
status_txt.text = "The song is now playing";
// Enter Frame Event
// We are going to use this for more sound control
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
leftpeak_txt.text = ""+(Math.round(channel.leftPeak * 100));
rightpeak_txt.text = ""+(Math.round(channel.rightPeak * 100));
leftBar.height = (Math.round(channel.leftPeak * 100));
rightBar.height = (Math.round(channel.rightPeak * 100));
}
// Sound completion event function and its listener
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event){
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
status_txt.text = "The song is over";
}