Hey all. I’m getting some severe audio latency in my game (a 250-500ms). We’re using Cocos-2d for iPhone. We believe it might have something to do with preloading or audio buffers but we’re not sure how to approach those. Does anyone have any suggestions or can they explain what’s involved in dynamically preloading audio?
Some details about the audio, we’re using 16 bit 44kHz AIFFs and FLACs. Our banks are set to Ogg Vorbis compression at 80%.
This is being addressed via email@example.com, but for reference here is my response:
The primary cause of latency in FMOD is the output buffer size, this can be controlled with System::setDSPBufferSize and System::setSoftwareFormat. The default for iOS is 4 buffers of 1024 samples at 24KHz, which produces ~170ms of latency. To reduce this you could increase the sample rate from 24KHz to 48KHz, this would halve the latency but increase CPU cost. Alternatively you could reduce the buffer size from 1024 to 512, which you should test in game conditions for stutter but should be safe unless you require audio playback during screen lock.
Another cause of latency is decompression audio at play time, this could take the form of doing a System::createSound right before System::playSound if you are using the low level API or a getEvent without previously doing loadEventData if you are using the Designer API. If the above buffer tips don’t help could you elaborate a little more on how you are playing your sounds, also is this FMOD Ex or FMOD Studio?
Finally as a side note, regarding FSB Vorbis compression, setting 80% seems quite high, we map the Vorbis compression range of -1 to 10 to our range of 0 to 100. I’d recommend taking a look at this: http://www.vorbis.com/faq/#quality you can probably make some good size savings with lower values (without quality loss).