PDA

View Full Version : slight lag in audio



bigarth
June 20th, 2007, 01:51 AM
i'm writing an application that plays a sound at a particular time. it is IMPERATIVE that the sound is played exactly on time. think of it as a metronome--it can't be off or else it will sound incorrect. for this metronome i have a timer set up at 150 milliseconds, and every time the timer fires it should play the sound. however, when i listen to the playback it sounds "off" so to speak. it doesn't play the sound at correct intervals. its almost correct but i feel as if it is lagging sometimes.

has anyone else run into this issue or have a recommended solution?

bigarth
June 20th, 2007, 12:36 PM
i've whipped up a quick sample application that anyone can try on their own computer, provided you have some sound to play.


import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.media.Sound;
import flash.net.URLRequest;

function playSound (param_event:TimerEvent) {
sound.play ();
}

var sound:Sound = new Sound ();
sound.load (new URLRequest ("sounds/AMB_MTM.mp3"));
var timer:Timer = new Timer (150);
timer.addEventListener (TimerEvent.TIMER, playSound);
timer.start ();

when i run this code the sound does not play at equal intervals. it "lags" sometimes and does not sound like there are equal gaps between the sounds. anyone else experiencing the same thing?