0

I have a music sequencing app for iOS that uses AUSamplers and effects audio units.

The main playback loop is implemented using a render notify callback to send note on & off events to the samplers. I have notes successfully playing on beat by calculating buffer offsets and passing those to the MusicDeviceMIDIEvent calls.

I'm now trying to implement an automation feature that lets you define changes to effect parameters over time. For an initial test, I'm repeatedly ramping the master mixer volume from 0 to 1 every bar (i.e. every 2 sec at 120 bpm).

I'm using AudioUnitScheduleParameters to schedule immediate events, once per render callback. However, the actual volume change seems to be slightly delayed. This is very obvious at the beginning of a bar when the volume drops from 1 to 0; any notes scheduled at the beginning of that bar play briefly at full volume before dropping to 0 and ramping up as expected. I have verified that parameter event has been scheduled at a buffer offset before the note on event.

My current workaround is to run the automation "ahead" of the audio, where I add some offset to the sample count used to calculate the current volume level. I've determined the offset just by experimenting, though, and I'm not confident in the solution.

Is there some reason I'm missing that would cause scheduled parameter events to be delayed?

Jayson
  • 1,689
  • 14
  • 26

1 Answers1

0

2 buffer delays may be the time required to pass a parameter update message from a downstream audio unit callback to an upstream callback that has already been called and is currently running (already mid-process mixing incoming audio buffers)

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Hm, maybe, but I'm doing all this in the PreRender stage, and I'm triggering the sampler at the same time. Are you saying the effect units have a different delay than the sampler? Is there a way to calculate this delay instead of just guessing and hoping it works on different CPUs? – Jayson Dec 04 '15 at 15:15
  • By the time you trigger the sampler, the mixer may already be mixing the buffer using older parameters. Try changing audio unit buffer sizes and see if the offset changes with it. Note that the OS sometimes changes audio unit buffer sizes from other than the requested size. – hotpaw2 Dec 04 '15 at 15:22
  • I dropped the buffer size to 256 and saw the same results; I had to then have a delay of 4 buffers to get them to sync up, still 1024 frames. – Jayson Dec 04 '15 at 15:58
  • Does your avaudiosession setting allow mix-with-others? – hotpaw2 Dec 04 '15 at 16:32
  • It did, and that was something I was meaning to change. It didn't help the delay though. – Jayson Dec 04 '15 at 16:39
  • Another test might be to try reseting your iOS device after removing the mix-with-others to see if another app is interfering. – hotpaw2 Dec 04 '15 at 20:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97014/discussion-between-jayson-and-hotpaw2). – Jayson Dec 04 '15 at 20:04