1
votes

i'm new with sounds in actionscript 3 and im having some troubles with detailed milliseconds project, which is very important it be accurate...

I'm running a sound which have a 'click' every 500 ms, i want to play other sound 250 miliseconds after the first one started... so, at first, i just tried to make all by the simplest way, with this:

import flash.display.MovieClip;

var som:som1 = new som1;
var som2:som2 = new som2;

som.play(0,100);

var myInterval:uint = setInterval(myFunction, 250);

function myFunction():void{
    som2.play(0,100);
    clearInterval(myInterval);
}

And it having a delay of 350 ms after first sound started...

So, in the second try i created a button for start/stop this code above... and i discovered is: On first time play, i got a 350 ms delay, but at the second time (after stop and play it again), it's working perfect, 250 ms as i wanted!

So, my solution was make a silent first play, without sound, just in background, for 'load' it, with this:

var firsttime:Boolean = true;
var transform1:SoundTransform = new SoundTransform();
transform1.volume = 0;

if (firsttime == true){
        Som1Channel = som.play(0,1);
        Som1Channel.soundTransform = transform1;
        firsttime == false;

} 

and it's working perfect... but that all was just test for main application, which is going to have a 25 seconds sound. And the user cant wait 25 seconds until sound starts.

Does anyone have other solution to this? The most important thing is to load the sound before it starts, is it possible? because it's already on my library, so, its not a loader case... Thanks!!

1

1 Answers

0
votes

Your test measurements are inaccurate. Flash Sounds have a high latency for over 50ms to 300ms depending on the system. As such they are not usable for what you are trying to do. You need to use ane or any external sound playing system to achieve accuracy (low latency). There is no known way to reduce latency on Flash Sound, the sampledataevent was introduced in FP 10 to give one way for developer to synchronize sounds but that system is not meant for low latency responsive sound (sampledataevent can go up to 1000ms latency).

Bottom line, using Flash Sound API, there's no way to synchronize the playing of sounds accurately due to their high latency. There's no work around and no possibility to reduce that latency to the lowest industry standard (30ms). What you are trying to achieve cannot sadly be done in Flash.