Hi all,
I have some audio related questions on the iPhone. This relates to imported/game audio, NOT to iPod music:
-
I have read it is not possible to play more than 1 compressed audio at once. Is it possible to play a compressed audio (sound track) and uncompressed SFX at the same time?
-
Is it possible to poll an audio clip for its current position in milliseconds while it is playing? Or do I need to run a seperate timer at the same time as the audio clip plays (this relates to Q3)?
-
Is it possible to get a callback (etc) when music starts playing, as there is often a delay from when the script starts the music to when it actually plays?
Thanks a lot!
Hi Dreamora
Thanks for your responses.
What do you mean by (2)?
Do you mean you aren’t sure about uncompressed audio, but compressed audio is definitely ‘no’?
So, in regards to (3), there is no way to sync something with the start of a sound from within Unity?
- Are we able to hook into Unity’s script and call some native iPhone/XCode routines wherever we want? That way we can move sound handling to outside the engine?
-
Correct.
-
with the precision you mentioned, no
-
At the time, no. You would use NSUserDefaults ↔ playerprefs to do so.
with 1.1 and iPhone Advanced, you can expose obj c functionality to the scripting from what mentioned, then that would be possible.
but it won’t change anything to the behavior, the problem is that you work with a phone, not a pc
When you say there is a delay before a clip starts playing, can you be more specific? Do you mean before the sound occurs based on some initial silence in the clip or when the clip actually starts being played by engine. I have not seen significant evidence of the latter (at least not that I have every noticed).
If it’s the former then there are a variety of tools that will let you instrument this dead space and either remove it or understand how to compensate for it in you synchronization effort. I’ve done this and a few times and it seems to work fine.
HanulTech: A delay of 200 - 300ms before the clip starts, especially on compressed sounds
I too confirm the 200 to 300ms delay on compressed audio.
I’m currently on a project with over 200 mp3’s, and can assure you to anticipate delays in excess of 0.5 of a second on iPhone 3G and iPod gen 1… The iPod Gen 2 and the 3GS will ‘sometimes’ have a delay of .1 or so of a second, but otherwise appear to be near instant.
Sadly, there’s no way I’m aware of to accurately check the status of an mp3. (The hardware will flag that its ‘playing’ even if the file has not begun playing yet).
Sorry I thought he said the sound clip in question was uncompressed. Definitely a delay with compressed clips.
To the poster, since you can only play one at a time anyway, why not start playing the compressed clip briefly to play and then stop it, then start it again when you need it to play. Should remain in memory uncompressed on the hardware player until another clip is played, no?
Fantastic work-around, thanks HanulTech.
If I can ‘pop-out’ of Unity into Objective-C and execute a few commands before ‘popping-back-in’ I think all would be ok. I’ve started another thread about this 
you would schedule things to happen outside.
you don’t pop out, do stuff and popin again, at least if you don’t want the user to wait for 0.5s on each operation before the game continues
Yeah, just a figure of speech 