Search code examples
ioscore-audioaudiounithal

AudioUnitRender hang on AUSampler


I have a music-making app that uses AUSampler & AURemoteIO units to play back user-defined notes. I'm having an issue where after some use, the call to AudioUnitRender on the sampler never returns, hanging the audio thread and silencing the audio output. The CPU usage also shoots up at this point, as the audio thread continuously spits out error messages to the device console (not the debugger output):

May 11 11:45:12 <device name> mediaserverd(CoreAudio)[2296] <Notice>: HALS_IOContext.cpp:1496:IOWorkLoop_HandleOverload: HALS_IOContext::IOWorkLoop_HandleOverload: Overload on context 96 current time: 11788974 deadline: 11788958

This message is being logged by _os_log_impl inside the AUSampler render (specifically VoiceEnvelope::GetRunFrameCount).

Does anyone have suggestions on why this may be happening and how to avoid it?


Solution

  • I discovered the issue. I was passing offsets greater than the size of the buffer into MusicDeviceMIDIEvent which would cause the issue. This was happening due to occasional jumps in the timestamp provided to the render callback. I was able to fix the issue by checking for and ignoring events with offsets greater than the frame count for the current callback.