I’m working on a musical app (a virtual instrument) and for this app I’d like (obviously) a very low audio output latency.
In theory, I should be able to control the audio output buffer size and count with AudioSettings.SetDSPBufferSize(), but unfortunately, it doesn’t seems to work. The sound continues to work, but the buffers configuration doesn’t change. I tried several values without any success…
(I tested on an iPad 3 under iOS 6.1.3 - Unity 4.2.1)
The lowest latency I can achieve is 256 x 4 buffers (with “Best latency” in Audio Projects Settings in Editor). I’d like something better, maybe 128 x 2…
Is there any way to achieve this without having to roll my own native Audio Unit (plugin) ?
I did a test on an Android device (ACER A700 tablet), and we have the same behaviour : actually the AudioSettings.SetDSPBufferSize() seems to work only in the Editor.
Any thoughts about that ?
Well, I implemented a plugin using iOS low level Audio Units. Latency is now minimal (I still have something like 1/60 s of latency due to the app logic and input running at 60 Hz).
But of course I cannot use Unity Audio engine. I now have to run my own Audio Engine in parallel with an API to load samples, play samples, position sources, …
@jonlab Interesting, are you still using Unity at all for the visuals? If so is audio to visual communication hard? Or are you doing everything strictly in objective-c?
I had the same problem, the solution is mind blowing:
Set DSPBuffer size in project settings to “Default” , not low latency , not good latency, “Default” is the secret sauce, only then you will be able to adjust dsp buffer size from script, i was able to go as low as 64 buffer size on my ipad mini with retina display for my music app, and the result is extremely low latency, almost the same as the one you get in garage band, enjoy
Hi, I am trying to get very low latency working on iOS too. Just for the record, I tried F. salka’s app on my iPad 2 in the wild hope that I would finally see a Unity app with very low latency - but sadly despite what you say it is still far away from the results I can get implementing Audio Units via the Amazing Audio Engine.
Devs, I noticed Unity is getting worked on on the audio front for the upcoming unity 5. Any plans to allow very low latency for iOS? I really think this is the one thing preventing proper music apps from being built on Unity, something I and many others in this thread are looking for.
@jonlab , were you able to mix audio in unity with audio from your custom engine, or did you have to route everything through the new plugin and disable audio in unity completely?
There are various ways of playing audio at native side, here’s my choice :
On iOS it uses OpenAL. It is faster than AVAudioPlayer, AudioToolbox, and SystemSound. Speaking of AudioUnit, the lowst audio technology of iOS that jonlab talked about, OpenAL is a cross platform library that happen to maps to AudioUnit on iOS. It means its latency must be equal to or more than AudioUnit.
On Android it uses AudioTrack, I confirmed it to be faster than SoundPool and no meaningful difference from C++ side OpneSL ES of NDK.
wow thanks for making this! I had been pretty discouraged from making mobile audio projects in unity after this. I will definitely check it out, looks very thorough, well done!