11 Replies Latest reply on Mar 31, 2007 8:53 AM by kglad

    Timing of sounds

    whoismariowilliams
      Is there anyway to be more accurate with the timing of two sound objects dynamically in actionscript? I know that I could use the start method to position both streams to the second but is there a way to sync them more precisely? Thanks.
        • 1. Re: Timing of sounds
          kglad Adobe Community Professional & MVP
          you can start them to within a few milliseconds of accuracy unless the user's cpu is tied up doing something.
          • 2. Re: Timing of sounds
            whoismariowilliams Level 1
            Just by using the sound.start(secondOffset) function?

            I thought that was just an approximation.
            • 3. Re: Timing of sounds
              kglad Adobe Community Professional & MVP
              it is. but you can apply the start() method to within a few millisecond accuracy using, for example, getTimer().
              • 4. Re: Timing of sounds
                whoismariowilliams Level 1
                Oh, OK thanks. I thought that it automatically rounded to the nearest second.
                • 5. Re: Timing of sounds
                  kglad Adobe Community Professional & MVP
                  i think you're confusing two different things:

                  the start() method "secondOffset" parameter has nothing to do with WHEN a sound starts to play. it specifies at what point (time-wise) in the sound file the sound starts. it does not control WHEN the sound starts.

                  the sound starts within milliseconds of the start() methods execution. you may not hear anything if there's dead-space in the sound file and the start() method directs the sound object to start in that dead-space.

                  to specify WHEN a sound starts, you control WHEN you execute your start() method. and controlling when the start() method is applied can be done very accurately.
                  • 6. Re: Timing of sounds
                    whoismariowilliams Level 1
                    No, sorry. Basically, I'd like to overlap two sounds. I'm not so much concerned with when they start, only that they play correctly in relation to each other. And for example, if I had one sound playing and then wanted a user to add a second sound I could make sure that the timing between the two sounds was accurate at greater precision than a second. So, basically:

                    private function AddSecondSound(path:String):void {
                    pos:number = FirstSound.position
                    SecondSound.start(pos, 1)
                    }

                    I was just concerned that the first parameter is in seconds, not milliseconds.
                    • 7. Re: Timing of sounds
                      kglad Adobe Community Professional & MVP
                      well, that code will be way off. the position method returns the number of MILLISECONDS the FirstSound is playing. correct it by dividing by 1000 to use as a sound offset in the start() method and see if that gets you close enough to what you want.
                      • 8. Re: Timing of sounds
                        whoismariowilliams Level 1
                        Sorry, I knew that I needed to divide it by 1000. I'll just check it out and see what happens. Thanks.
                        • 9. Re: Timing of sounds
                          kglad Adobe Community Professional & MVP
                          you're welcome.

                          actually, when i tested the start() method it seems to be accurate to much more than 1 millisecond. i can detect differences up to .00001 offset. at that point it sound like simultaneous sounds are playing to me. at .0001 they offset is detectable by me.
                          • 10. Re: Timing of sounds
                            whoismariowilliams Level 1
                            I was actually using the following :

                            mySoundChannel1 = mySound1.play
                            mySoundChannel2 = mySound2.play

                            instead of start(). On my development machine the sounds were simultaneous but when I deployed it on a remote server there was a very noticeable difference (maybe a tenth of a second). Is there a way to close that gap? Would a dedicated server or Flash Media Server load that second sound faster?
                            • 11. Re: Timing of sounds
                              kglad Adobe Community Professional & MVP
                              that doesn't make sense. is that supposed to be:

                              mySoundChannel1 = mySound1.play()
                              mySoundChannel2 = mySound2.play()

                              if so, that makes no sense unless mySound1 and mySound2 are movieclips and you have a sound attached to their timelines and that makes no sense given the discussion above.

                              so, i just can't make sense of your last message.