Ti.Media.Sound Problem - Playing multiple sounds in sync (unison) seems impossible

You must Login before you can answer or comment on any questions.

So Titanium.Media.Sound() has methods such as setTime, getTime, and play()...

I have an array of sounds (5 mp3's) which are 100kb a piece, and I am trying to play them in unison. However this proves to be a fruitless endeavor. I have attempted using the preload: true when creating the sound, doing the sound[i].play() and sound[i].pause() in a loop to force the sounds to preload, then using sound[i].setTime(0), then attempting to loop through each of these sounds by simply calling sound[i].play() causes each sound to play, but at .01 (one hundredth) of a second offset.

For instance, if I add a setTimeout that outputs sound[i].getTime() every second that the app is running I get:

Sound 0 plays, and is at 1.05 second, sound 1 is roughly at 1.04, sound 2 is at 1.03, sound 3 is at 1.02, sound 4 is at 1.01, etc..

In fact, at 0 seconds when playing, the output of sound[4].getTime() is actually a negative number.

Trying to use an event listener to listen for the complete event of the first sound and resetting the times to 0 does not help overcome the problem that gets progressively worse as all the sounds play, the loops themselves get progressively more out of sync.

Is doing this in titanium too problematic? Sound I not be using Media.Sound()?

I'm looking for any insight that could help address this, even if it is an external module.

3 Answers

Hello,

is this happening in iOS or Android? or both? Which SDK? In device or emulator?

Best,

Mauro

— answered 1 year ago by Mauro Parra
answer permalink
5 Comments
  • iOS, on the emulator the latency is only .01, on an iPod Touch it is .03 second delay.

    — commented 1 year ago by Zack Carlson

  • For further reference, the sound files are 100kb, but they're encoded at 320kbps.. would changing the file format have any impact?

    — commented 1 year ago by Zack Carlson

  • Sorry, the current SDK 1.8.0.1 I missed that.

    — commented 1 year ago by Zack Carlson

  • Show 2 more comments

GOOD NEWS EVERYONE! I have found something out that seems to be (tentatively) a great way to get this to "work". The problem is type type of audio file you use. I referenced this article: here which talks about the "most optimized, fastest file format for iphone when space is not an issue"... Encode your audio files in Linear PCM and this seems to tighten everything up. If I were to hazard a guess, the phone when calling "play()" on a .mp3() file needs to decompress the file before playing it. Anyway, I'm responding to this because I hope someone else benefits from it. Cheers!

— answered 1 year ago by Zack Carlson
answer permalink
3 Comments
  • Thanks for sharing!

    Best,

    Mauro

    — commented 1 year ago by Mauro Parra

  • Hello!

    Did you be able to play multi sound in unison?

    — commented 1 year ago by mutsuyuki tanaka

  • Yes, at least close enough. Utilizing the link above we created uncompressed audio files which played instantly.

    — commented 1 year ago by Zack Carlson

Your Answer

Think you can help? Login to answer this question!