0 Replies Latest reply on Aug 11, 2008 1:46 AM by Gazoo101

    Sound Synchronization


      I've been scowering the web for the past few weeks trying to learn and find out how to best if at all handle sound synchronization in flash. As far as I have been able to tell its quite a problem and I've yet to find a solid solution to the issue. Specifically what I am trying to achieve is to play two mp3 files in succession with near-sample perfection. It's not fatal if there is a small discrepancy, but under no circumstances should there be a gap in between them.

      I've considered two approaches.

      1: Utilize flash timing mechanisms to sync the two mp3s and play them using the native flash/flex components.

      2: Write the two files to a new audio buffer and play the buffer.

      However - each of these possible solutions bring their own slew of problems:

      1. Timing in flash seems to be unpredictable at best. Determining the end of the first mp3 and using a timer to run the 2nd is completely out of the question. More often than not, the timing is off by 200-300 msec. A workaround is then to instead constantly poll the system checking ticks and estimating when the best bet to play the sound is. Once again flash's relative inaccuracy strikes. Ask flash how long a 5000 ms mp3 file is (recorded in 44100 khz) and it'll report back as "5041.632653061224". Then poll the position of the mp3 file as it plays and when it finishes, it'll show "4876.190476190476". That's 165 ms unaccounted for... Unacceptable... But what's important is the position of the mp3 file. As long as it's possible to estimate where to begin playing the next mp3 file given flashes somewhat odd position variable, all is well. But this variable only updates at the sample rate in ms which is "46.4" ms. While 40 ms is close to where I want to be in precision, I am unnerved by flash's other inaccuracies....

      2. The alternative then is to trash flash's timing and combine the two files manually. Easier said than done. I've seen examples of utilizing actionscript and flash to build a timed synthesizer which seems to work. This also involves writing your own audiobuffer. Unfortunately, the code generates wav files to play and not mp3s. My technical skills aren't quite up to snuff to write mp3 data for playback.

      So what is a man to do? Flash 10 seems to provide some nifty data extraction possibilities - but the product I am working on needs to work on a number of platforms and at the moment, flash 9 is the most wide spread. Flash 10 isn't actually released yet either...

      If anyone has any experience in the field or other suggestions - I'd be forever grateful...