Poor Audio Timing - Is there a better alternative to OpenAL?
by Ryan Fields · in Torque Game Builder · 11/23/2009 (10:25 am) · 3 replies
Before setting out to build a rhythm game with TGB, I probably should have done some in depth reading on TGB's sole audio library, OpenAL. What I would have found (prior to buying the TGB license) is that OpenAL has some pretty unfortunate timing issues when it comes to retrieving the playback position of an audio file.
The tightest playback resolution I can track with OpenAL is one-hundredth of a second, which doesn't quite cut it for syncing anything to music. Much as I'd like to track playback position in microsecond increments, I'd settle for something that tracks playtime by the millisecond.
I know that DirectMusic can accomplish this (provided the hardware supports it), but I'm targeting OS X (and potentially the iPhone later) in addition to Windows.
Has anyone here tackled this issue already? I couldn't find much via forum searches. Has anyone found and replaced TGB's OpenAL dependency with something else that's cross-platform and higher precision (again, when hardware supports it)? Has anyone taken a hybrid approach? If I have to use multiple libraries to target multiple platforms, I will. I just have to discover what libraries out there might provide higher precision timing than the OpenAL implementation packaged with TGB.
The tightest playback resolution I can track with OpenAL is one-hundredth of a second, which doesn't quite cut it for syncing anything to music. Much as I'd like to track playback position in microsecond increments, I'd settle for something that tracks playtime by the millisecond.
I know that DirectMusic can accomplish this (provided the hardware supports it), but I'm targeting OS X (and potentially the iPhone later) in addition to Windows.
Has anyone here tackled this issue already? I couldn't find much via forum searches. Has anyone found and replaced TGB's OpenAL dependency with something else that's cross-platform and higher precision (again, when hardware supports it)? Has anyone taken a hybrid approach? If I have to use multiple libraries to target multiple platforms, I will. I just have to discover what libraries out there might provide higher precision timing than the OpenAL implementation packaged with TGB.
#2
If I get a yes, then it's just a matter of seeing how much of a time commitment is involved in getting FMOD into TGB.
11/23/2009 (11:29 am)
Thanks. I was just looking at that, and have already sent off an email to FMOD's sales department asking if their product can produce more accurate timing results than OpenAL.If I get a yes, then it's just a matter of seeing how much of a time commitment is involved in getting FMOD into TGB.
#3
After a small amount of hacking at the code, I was able to load OpenAL 1.1 DLLs. This change allowed me to replace OpenAL32.dll with the OpenAL-Soft implementation. OpenAL-Soft returns a MUCH more accurate playback cursor position. What this got me is a very good illusion of perfect sync for visual elements of the game. What it didn't get me is perfect sound sync, but the problem no longer lies with OpenAL.
Running under Windows 7 (haven't tried WinXP, OS X, or Linux yet), it seems like the fastest tick I can get is a 16ms tick when using object timers or the schedule function. With a bit of timing trickery, a 16ms or 32ms tick is fine for visual effects. Unfortunately, I need a tick that's somewhere between 1ms and 5ms when dealing with audio sync. I'm getting the impression that Torque can't do that without some pretty involved hacking.
11/23/2009 (5:41 pm)
Upon further research, I've discovered that some OpenALs are better than others. Though my problem still hasn't been completely solved, the following made a big difference.After a small amount of hacking at the code, I was able to load OpenAL 1.1 DLLs. This change allowed me to replace OpenAL32.dll with the OpenAL-Soft implementation. OpenAL-Soft returns a MUCH more accurate playback cursor position. What this got me is a very good illusion of perfect sync for visual elements of the game. What it didn't get me is perfect sound sync, but the problem no longer lies with OpenAL.
Running under Windows 7 (haven't tried WinXP, OS X, or Linux yet), it seems like the fastest tick I can get is a 16ms tick when using object timers or the schedule function. With a bit of timing trickery, a 16ms or 32ms tick is fine for visual effects. Unfortunately, I need a tick that's somewhere between 1ms and 5ms when dealing with audio sync. I'm getting the impression that Torque can't do that without some pretty involved hacking.
Torque 3D Owner Ronny Bangsund
Torque Cheerleaders