Very low latency audio output on iOS?

Hi there,

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) ?

Thanks !

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, …

up ! anybody has any ideas about that ?

Bump

I’m trying to do something similar on iOS as well.

No one has found a workaround for low latency using only Unity?

@jonlab: did you find a way to lower the latency using Unity or did you end up using the separate Audio engine?

I’m using a totally reparate Audio engine for now. And latency is much better.

Hey @jonlab what engine did you end up going with? I’m trying to do something similar.

My own one, with an iOS AudioUnit and a C sample based synthesizer.

@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 wrote a C# plugin, so everything is driven from Unity, but all the loadings and heavy audio is done in C.

Sounds awesome, I’m sure there would be some interest in that plugin as an asset. I would pay for it.

+1
I would also pay for that type of solution on the asset store.
@jonlab Please consider it!

Well, actually this is really a very specific one for now, but I will think about this.

bonkers that Unity doesn’t have a take on low-latency audio itself.

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 :slight_smile:

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?

What is “Amazing Audio Engine”? Is that a plugin?

I just made Native Audio asset store plugins which can make a native call to both iOS and Android’s fastest native way from one central interface. https://www.assetstore.unity3d.com/#!/content/107067

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.

I have compiled all of my findings in here : Native Audio - Unity Plugins by Exceed7 Experiments

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!

1 Like