Example code of AudioDriverKit stopped to work on macOS 12.0.1

Hi,

Example code of AudioDriverKit from WWDC2021 stopped to work correctly for me. It builds and loads but when I want to record sine wave immediately after startIO function stopIO is called. It happens on both MacBook Air and Mac mini with macOS 12.0.1. I discovered it because my audio driver also stopped to work correctly - exactly the same problem I described above. Earlier I was testing both example code and my audio driver on macOS 12 public beta and everything was ok.

Below I paste logs from console when I start recording:

default	12:54:19.161261+0100	kernel	StartIO: Start IO: device 2
default	12:54:19.161274+0100	kernel	StartIO: Start IO: device 2
default	12:54:19.161092+0100	coreaudiod	 HALS_IOEngine2::StartIO: starting IO on device SimpleAudioDevice-UID
default	12:54:19.161279+0100	kernel	StartIO: Start IO: device 2
default	12:54:19.161138+0100	coreaudiod	 HALS_IOEngine2::_StartIO(435) on Context 443  state: Prewarm: 0 Play: 0 State: Stopped
default	12:54:19.161374+0100	CAReportingService	    CAReportingService.mm:157   service type 9 set for reporter  897648164879
default	12:54:19.161437+0100	coreaudiod	 		HALS_IOEngine2::_StartIO(435) on Context 443  state: Prewarm: 0 Play: 1 State: Running
default	12:54:19.161761+0100	coreaudiod	 HALS_Device::_GetCombinedVolumeScalar: client 246 (pid 517) is not present and has a combined volume scalar is 1.000000
default	12:54:19.161798+0100	coreaudiod	 HALS_Device::_GetCombinedVolumeScalar: client 246 (pid 517) is not present and has a combined volume scalar is 1.000000
default	12:54:19.161808+0100	coreaudiod	 HALS_IOUADevice::HandlePropertiesChanged: Object: 431: SimpleAudioDevice-UID
default	12:54:19.162034+0100	coreaudiod	   'goin', 'glob', 0
default	12:54:19.162580+0100	coreaudiod	     CAReportingClient.mm:508   message {
    "device_is_aggregate" = 0;
    "input_avail_phys_formats" = "{ [16/48000/1 lpcm], [16/44100/1 lpcm] }";
    "input_avail_virt_formats" = "{ [32/48000/1 lpcm], [32/44100/1 lpcm] }";
    "input_bits_per_channel" = 32;
    "input_bytes_per_frame" = 4;
    "input_bytes_per_packet" = 4;
    "input_channels_per_frame" = 1;
    "input_device_source_list" = Unknown;
    "input_device_transport_list" = BuiltIn;
    "input_device_uid_list" = "SimpleAudioDevice-UID";
    "input_format_id" = lpcm;
    "input_frames_per_packet" = 1;
    "input_num_tap_streams" = 0;
    "input_scalar_volume" = "1.000000";
    "io_buffer_size" = 15;
    message = StartHardware;
    "output_num_tap_streams" = 0;
    "output_scalar_volume" = "1.000000";
    "sample_rate" = 48000;
}: (
    897648164879
)
error	12:54:19.163011+0100	coreaudiod	206515            HALS_IOUAUCDriver.cpp:500   Throwing Exception: ret != kIOReturnSuccess Failed to register event link
error	12:54:19.163100+0100	coreaudiod	206515              HALS_IOUAEngine.cpp:157   Failed to register io thread!
default	12:54:19.163950+0100	kernel	StopIO: Stop IO: device 2
default	12:54:19.163968+0100	kernel	StopIO: Stop IO: device 2
default	12:54:19.163974+0100	kernel	StopIO: Stop IO: device 2
default	12:54:19.163166+0100	coreaudiod	 HALS_IOContext_Legacy_Impl::IOWorkLoop: failed to register io thread
error	12:54:19.163310+0100	coreaudiod	206515              HALS_IOUAEngine.cpp:180   Throwing Exception: error != 0 Failed to disassociate event link 22
error	12:54:19.163482+0100	coreaudiod	206515              HALS_IOUAEngine.cpp:187   Failed to unregister io thread!
default	12:54:19.163613+0100	coreaudiod	 HALS_IOEngine2::StopIO: stopping IO on device SimpleAudioDevice-UID
default	12:54:19.163744+0100	coreaudiod	 HALS_IOEngine2::_StopIO(435) on Context 443  state: Prewarm: 0 Play: 1 State: Running
default	12:54:19.164082+0100	coreaudiod	 HALS_IOUADevice::HandlePropertiesChanged: Object: 431: SimpleAudioDevice-UID
default	12:54:19.164134+0100	coreaudiod	   'goin', 'glob', 0
default	12:54:19.164289+0100	coreaudiod	     CAReportingClient.mm:480   stopping (
    897648164879
)
default	12:54:19.164542+0100	coreaudiod	     CAReportingClient.mm:508   message {
    "session_duration" = "0.003519058227539062";
}: (
    897648164879
)
error	12:54:19.165611+0100	Audacity	 HALC_ProxyIOContext::IOWorkLoop: the server failed to start, Error: 0x77686174
default	12:54:19.165045+0100	coreaudiod	 IO Stopped Context 443 after 0 frames.
default	12:54:19.165199+0100	coreaudiod	 HALS_IOContext_Legacy_Impl::IOThreadEntry: 443 SimpleAudioDevice-UID (SimpleAudioDevice-UID): stopping with error 2003329396
default	12:54:19.165220+0100	coreaudiod	 HALB_PowerAssertion::Release: releasing power assertion ID 34859 of type 'PreventUserIdleSystemSleep' with name: 'com.apple.audio.context443.preventuseridlesleep' on behalf of 517
error	12:54:19.165390+0100	coreaudiod	 HALS_IOContext_Legacy_Impl::StartIOThread: the IO thread failed to start, Error: 2003329396 (what)

Any advice? Thank you and regards

Hi,

Looks like this may be a bug. You should report it, which should also give you visibility into the issue.

In the meantime, you can try to workaround this by setting a block for IO Callbacks.. This is only available in the current betas, as the API page notes.

Thank you for response.

I've already reported it through Feedback Assistant - bug FB9778734. It is open and I am waiting for response.

Huh, adding that no-op callback on 12.1 beta really does work. What a strange bug.

Example code of AudioDriverKit stopped to work on macOS 12.0.1
 
 
Q