### virtual kern_return_t Start(IOService *provider) Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/start Starts the current service and associates it with the specified provider. ```APIDOC ## Start ### Description Starts the current service and associates it with the specified provider. This method is called after the system matches the provider to the driver's service. ### Method Instance Method ### Parameters #### Path Parameters - **provider** (IOService*) - Required - The provider object that matches the current service. ### Return Value - **kern_return_t** - kIOReturnSuccess on success, or another value if an error occurs. ### Discussion Override this method inherited from IOService. Use this method to configure driver data structures and setup associated hardware. Call RegisterService after configuration to indicate the service is running. Always call super early in the implementation. ``` -------------------------------- ### StartIO Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice/startio Tells the device to start I/O operations. ```APIDOC ## StartIO ### Description Tells the device to start I/O. Subclass and override this method to handle hardware-specific tasks during I/O startup. ### Method Instance Method ### Parameters - **in_flags** (IOUserAudioStartStopFlags) - Required - A flag to indicate I/O startup behavior. ### Return Value - **kIOReturnSuccess** (kern_return_t) - Returned on success, or another value if an error occurs. ``` -------------------------------- ### StartIO Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/startio Tells the clock device to start I/O operations. ```APIDOC ## StartIO ### Description Tells the clock device to start I/O. ### Method virtual kern_return_t ### Parameters - **in_flags** (IOUserAudioStartStopFlags) - Required - A value to indicate I/O startup behavior. ### Return Value - **kIOReturnSuccess** (kern_return_t) - Returned on success, or another value if an error occurs. ### Discussion The default implementation always returns kIOReturnSuccess. Subclass and override this method to handle hardware-specific tasks during I/O startup, then call the superclass to update the I/O state. ``` -------------------------------- ### Instance Method: init Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/init Handles the basic initialization of the service. This method is called shortly after your custom IOService subclass is instantiated and before the Start method is called. It's suitable for simple tasks that must occur before the service starts, such as allocating memory. ```APIDOC ## Instance Method: init ### Description Handles the basic initialization of the service. Override this method inherited from `IOService`. The system calls this method shortly after it instantiates your custom `IOService` subclass, and before it calls the `Start` method of your service. Limit the work you do in this method to simple tasks that must occur before your service starts. For example, use this method to allocate memory for your `ivars` structure. Always call `super` early in your implementation of this method. ### Method ```cpp virtual bool init(); ``` ### Return Value `true` if initialization was successful, or `false` if an error occurred. ### See Also - `Start` - `Stop` - `free` ``` -------------------------------- ### Implement StartIO for AudioDriverKit Source: https://developer.apple.com/documentation/audiodriverkit/creating-an-audio-device-driver Handles the start of audio I/O by mapping memory descriptors and initializing timers. ```cpp kern_return_t SimpleAudioDevice::StartIO(IOUserAudioStartStopFlags in_flags) { DebugMsg("Start I/O: device %u", GetObjectID()); __block kern_return_t error = kIOReturnSuccess; __block OSSharedPtr input_iomd; __block OSSharedPtr output_iomd; ivars->m_work_queue->DispatchSync(^(){ // Tell IOUserAudioObject base class to start I/O for the device. error = super::StartIO(in_flags); FailIfError(error, , Failure, "Failed to start I/O"); output_iomd = ivars->m_output_stream->GetIOMemoryDescriptor(); FailIfNULL(output_iomd.get(), error = kIOReturnNoMemory, Failure, "Failed to get output stream IOMemoryDescriptor"); error = output_iomd->CreateMapping(0, 0, 0, 0, 0, ivars->m_output_memory_map.attach()); FailIf(error != kIOReturnSuccess, , Failure, "Failed to create memory map from output stream IOMemoryDescriptor"); input_iomd = ivars->m_input_stream->GetIOMemoryDescriptor(); FailIfNULL(input_iomd.get(), error = kIOReturnNoMemory, Failure, "Failed to get input stream IOMemoryDescriptor"); error = input_iomd->CreateMapping(0, 0, 0, 0, 0, ivars->m_input_memory_map.attach()); FailIf(error != kIOReturnSuccess, , Failure, "Failed to create memory map from input stream IOMemoryDescriptor"); // Start the timers to send timestamps and generate sine tone on the stream I/O buffer. StartTimers(); return; Failure: super::StopIO(in_flags); ivars->m_output_memory_map.reset(); ivars->m_input_memory_map.reset(); return; }); return error; } ``` -------------------------------- ### StartDevice Method Signature Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/startdevice Defines the virtual method for starting I/O on a specified audio object. ```cpp virtual kern_return_t StartDevice(IOUserAudioObjectID in_object_id, IOUserAudioStartStopFlags in_flags); ``` -------------------------------- ### GetStartingChannel Instance Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/getstartingchannel Retrieves the starting channel index for the audio driver. ```APIDOC ## GetStartingChannel ### Description Retrieves the starting channel index for the audio driver. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Request Example N/A ### Response #### Success Response (uint32_t) - Returns the starting channel index as a 32-bit unsigned integer. #### Response Example ``` uint32_t startingChannel = GetStartingChannel(); ``` ``` -------------------------------- ### Instance Method: StartIO Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/startio Tells the stream to start I/O. This method can be overridden by subclasses to handle hardware-specific tasks during I/O startup. ```APIDOC ## Instance Method: StartIO ### Description Tells the stream to start I/O. ### Method `virtual kern_return_t StartIO(IOUserAudioStartStopFlags in_flags);` ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (kIOReturnSuccess) `kIOReturnSuccess` on success. #### Error Response Another `kern_return_t` value if an error occurs. For a list of error codes, see Error Codes. #### Response Example `kIOReturnSuccess` ### Discussion The default implementation always returns `kIOReturnSuccess`. Subclass and override this method to handle hardware-specific tasks during I/O startup, then call the superclass to update the I/O state. The framework expects this call to always succeed or fail. The hardware can take as long as it needs in this call, provided it always either succeeds or fails. ### See Also - `StopIO` - `IOUserAudioStartStopFlags` ``` -------------------------------- ### Start Service Implementation Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/start Override this method to configure driver data structures and hardware. Always call the super implementation early. ```cpp virtual kern_return_t Start(IOService *provider); ``` -------------------------------- ### Implement AudioDriverKit Driver Start Method Source: https://developer.apple.com/documentation/audiodriverkit/creating-an-audio-device-driver This C++ code implements the Start_Impl method for a custom AudioDriverKit driver. It initializes and configures a virtual audio device, registers it with the system, and handles potential errors during the process. Ensure necessary entitlements are configured for hardware communication if not using a virtual device. ```cpp kern_return_t SimpleAudioDriver::Start_Impl(IOService* in_provider) { bool success = false; auto device_uid = OSSharedPtr(OSString::withCString(kSimpleAudioDriverDeviceUID), OSNoRetain); auto model_uid = OSSharedPtr(OSString::withCString("SimpleAudioDevice-Model"), OSNoRetain); auto manufacturer_uid = OSSharedPtr(OSString::withCString("Apple Inc."), OSNoRetain); auto device_name = OSSharedPtr(OSString::withCString("SimpleAudioDevice"), OSNoRetain); kern_return_t error = Start(in_provider, SUPERDISPATCH); FailIfError(error, , Failure, "Failed to start Super"); // Get the service's default dispatch queue from the driver object. ivars->m_work_queue = GetWorkQueue(); FailIfError(ivars->m_work_queue.get() == nullptr, error = kIOReturnInvalid, Failure, "failed to get default work queue"); // Allocate and configure audio devices as necessary. ivars->m_simple_audio_device = OSSharedPtr(OSTypeAlloc(SimpleAudioDevice), OSNoRetain); FailIfNULL(ivars->m_simple_audio_device.get(), error = kIOReturnNoMemory, Failure, "Failed to allocate SimpleAudioDevice"); success = ivars->m_simple_audio_device->init(this, false, device_uid.get(), model_uid.get(), manufacturer_uid.get(), k_zero_time_stamp_period); FailIf(success == false, error = kIOReturnNoMemory, Failure, "Failed to init SimpleAudioDevice"); ivars->m_simple_audio_device->SetName(device_name.get()); // Add the device object to the driver. AddObject(ivars->m_simple_audio_device.get()); // Register the service. error = RegisterService(); FailIfError(error, , Failure, "failed to register service!"); return kIOReturnSuccess; Failure: return error; } ``` -------------------------------- ### Instance Method: StartDevice Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/startdevice Tells the driver to start I/O on an audio device or audio clock device. This method is available in DriverKit 21.0 and later. ```APIDOC ## StartDevice ### Description Tells the driver to start I/O on an audio device or audio clock device. ### Method ```cpp virtual kern_return_t StartDevice(IOUserAudioObjectID in_object_id, IOUserAudioStartStopFlags in_flags); ``` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters `in_object_id` (IOUserAudioObjectID) - Required - The identifier of the device on which to start I/O. `in_flags` (IOUserAudioStartStopFlags) - Required - A flag that indicates how to perform the I/O start operation. ### Request Example - None ### Response #### Success Response (kIOReturnSuccess) - `kIOReturnSuccess` on success, or another value if an error occurs. For a list of error codes, see Error Codes. #### Response Example - None ### Discussion The default implementation always returns `kIOReturnSuccess`. Subclass and override this method to handle hardware-specific startup, then call the superclass to update the I/O state. The framework expects this call to always succeed or fail. The hardware can take as long as it needs in this call, provided it always either succeeds or fails. This call results in a call to `StartIO` on the device. ### See Also - `StopDevice` - `IOUserAudioObjectID` - `IOUserAudioStartStopFlags` ``` -------------------------------- ### SetStartingChannel Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/setstartingchannel Sets the starting channel for the audio stream. ```APIDOC ## SetStartingChannel ### Description Sets the starting channel for the IOUserAudioStream. ### Method Instance Method ### Parameters #### Parameters - **in_starting_channel** (uint32_t) - Required - The starting channel index for the stream. ### Response - **kern_return_t** - Returns the status of the operation. ``` -------------------------------- ### SetStartingChannel Instance Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/setstartingchannel Use this method to set the starting channel for an audio stream. Requires DriverKit 21.0+. ```c kern_return_t SetStartingChannel(uint32_t in_starting_channel); ``` -------------------------------- ### GetStartingChannel Method Signature Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/getstartingchannel Retrieves the starting channel index for the audio stream. Available in DriverKit 21.0 and later. ```cpp uint32_t GetStartingChannel(); ``` -------------------------------- ### Initialize AudioDriverKit Service Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/init Override this method to perform basic initialization tasks before the service starts. Always call `super` early in your implementation. This method is called shortly after your custom `IOService` subclass is instantiated. ```cpp virtual bool init(); ``` -------------------------------- ### Performing I/O Operations Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice Methods to start and stop I/O operations for the audio device. ```APIDOC ## Performing I/O ### `StartIO` Tells the device to start I/O. ### `StopIO` Tells the device to stop I/O. ### `IOUserAudioStartStopFlags` Values that indicate I/O starts or stops. ``` -------------------------------- ### Working with Default Device Behavior Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice Methods to set and get whether the device can be a default input or output device. ```APIDOC ## Working with Default Device Behavior ### `SetCanBeDefaultInputDevice` Sets a Boolean value that indicates if this device can be the host’s default input device. ### `CanBeDefaultInputDevice` Returns a Boolean value that indicates if this device can be the host’s default input device. ### `SetCanBeDefaultOutputDevice` Sets a Boolean value that indicates if this device can be the host’s default output device. ### `CanBeDefaultOutputDevice` Returns a Boolean value that indicates if this device can be the host’s default output device. ### `SetCanBeDefaultSystemOutputDevice` Sets a Boolean value that indicates if this device can be the system’s default output device. ### `CanBeDefaultSystemOutputDevice` Returns a Boolean value that indicates if this device can be the system’s default output device. ``` -------------------------------- ### Update Timestamps and Start Timer Source: https://developer.apple.com/documentation/audiodriverkit/creating-an-audio-device-driver Updates the zero timestamp values and schedules the timer for the next callback. ```cpp // Clear the device's timestamps. UpdateCurrentZeroTimestamp(0, 0); auto current_time = mach_absolute_time(); // Start the timer. The first timestamp occurs when the timer goes off. ivars->m_zts_timer_event_source->WakeAtTime(kIOTimerClockMachAbsoluteTime, current_time + ivars->m_zts_host_ticks_per_buffer, 0); ivars->m_zts_timer_event_source->SetEnable(true); ``` -------------------------------- ### Get Preferred Stereo Channels - AudioDriverKit Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice/getpreferredchannelsforstereo Call this method to get the channel indices for the preferred stereo pair. Ensure you are using DriverKit 21.0 or later. ```c void GetPreferredChannelsForStereo(uint32_t *out_left_channel, uint32_t *out_right_channel); ``` -------------------------------- ### GET GetObjectID Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioobject/getobjectid Retrieves the unique identifier for an IOUserAudioObject instance. ```APIDOC ## GetObjectID ### Description Gets the object’s identifier. ### Method Instance Method ### Return Value - **IOUserAudioObjectID** - The object’s identifier. ### Discussion Use this identifier when looking up a driver’s objects with GetAudioObjectForObjectID. ``` -------------------------------- ### Getting Information About the Class Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioselectorcontrol Methods for retrieving class identification information. ```APIDOC ### Getting Information About the Class - `GetClassID` Gets the audio class identifier of the object. - `GetBaseClassID` Gets the audio class identifier of the base class object. ``` -------------------------------- ### StartIO Instance Method Signature Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/startio This is the signature for the StartIO instance method. Override this method to handle hardware-specific tasks during I/O startup. The framework expects this call to always succeed or fail. ```cpp virtual kern_return_t StartIO(IOUserAudioStartStopFlags in_flags); ``` -------------------------------- ### GET GetOwnerObjectID Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioobject/getownerobjectid Retrieves the object ID of the owner for an IOUserAudioObject instance. ```APIDOC ## GetOwnerObjectID ### Description Retrieves the object ID of the owner for an IOUserAudioObject instance. ### Method Instance Method ### Signature IOUserAudioObjectID GetOwnerObjectID(); ### Availability DriverKit 21.0+ ``` -------------------------------- ### Initialize an IOUserAudioBox instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobox/init Initializes the audio box with the provided driver, acquirability status, and UID. The no-argument init method is not supported and will return false. ```cpp virtual bool init(IOUserAudioDriver *in_driver, bool in_is_acquirable, OSString *in_box_uid); ``` -------------------------------- ### GET GetScalarValue Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiolevelcontrol/getscalarvalue Retrieves the current scalar value of the level control. ```APIDOC ## GET GetScalarValue ### Description Gets the scalar value of the level control. ### Method GET ### Endpoint GetScalarValue ### Response #### Success Response (200) - **value** (float) - The scalar value of the level control. ``` -------------------------------- ### Getting Information About the Class Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice Methods for retrieving class identifiers and information. ```APIDOC ## Getting Information About the Class ### `GetClassID` Gets the audio class identifier of the object. ### `GetBaseClassID` Gets the audio class identifier of the base class object. ### `IOUserAudioClassID` An identifier for the type of audio object. ``` -------------------------------- ### init Method Documentation Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice/init Initializes an instance of the audio device class within the DriverKit framework. ```APIDOC ## init ### Description Initializes an instance of the audio device class. ### Method Virtual Method ### Parameters - **in_driver** (IOUserAudioDriver*) - Required - The IOUserAudioDriver that owns this object. - **in_supports_prewarming** (bool) - Required - A Boolean value that specifies whether the device supports prewarming I/O. - **in_device_uid** (OSString*) - Required - A pointer to an OSString containing the device UID. - **in_model_uid** (OSString*) - Required - A pointer to an OSString containing the module UID. - **in_manufacturer_uid** (OSString*) - Required - A pointer to an OSString containing the manufacturer UID. - **in_zero_timestamp_period** (uint32_t) - Required - Indicates the number of sample frames the host can expect between successive timestamps returned from GetZeroTimeStamp(). ### Return Value - **bool** - true if initialization succeeded; false otherwise. ``` -------------------------------- ### Create an IOUserAudioBox instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobox/create Use this static method to allocate and initialize an audio box. Do not use this method when working with custom subclasses of IOUserAudioBox. ```cpp static OSSharedPtr Create(IOUserAudioDriver *in_driver, bool in_is_acquirable, OSString *in_box_uid); ``` -------------------------------- ### GetBaseClassID Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodriver/getbaseclassid Gets the audio class identifier of the base class object. ```APIDOC ## GetBaseClassID ### Description Gets the audio class identifier of the base class object. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters N/A ### Request Example N/A ### Response #### Success Response - **IOUserAudioClassID** (type) - The audio class identifier of the base class object. #### Response Example N/A ``` -------------------------------- ### init Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostereopancontrol/init Initializes an instance of a stereo pan control. ```APIDOC ## init ### Description Initializes an instance of a stereo pan control. ### Parameters - **in_driver** (IOUserAudioDriver) - The IOUserAudioDriver that owns this object. - **in_is_settable** (bool) - A Boolean value that indicates if the control can be set. - **in_control_value** (float) - A floating-point value that represents the control’s current stereo pan value. - **in_left_channel** (IOUserAudioObjectPropertyElement) - The IOUserAudioObjectPropertyElement for the left channel. - **in_right_channel** (IOUserAudioObjectPropertyElement) - The IOUserAudioObjectPropertyElement for the right channel. - **in_control_element** (IOUserAudioObjectPropertyElement) - An IOUserAudioObjectPropertyElement to identify the control. - **in_control_scope** (IOUserAudioObjectPropertyScope) - A IOUserAudioObjectPropertyScope indicating the control’s scope: input, output, global, or play-through. - **in_control_class_id** (IOUserAudioClassID) - The IOUserAudioClassID of the control. ### Return Value - **bool** - true if initialization succeeded; false otherwise. ``` -------------------------------- ### Get Current Client Sample Time Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getcurrentclientsampletime Use this method to obtain the current input and output sample times that the client has written to or read from the ring buffer. Available in DriverKit 21.0+. ```c void GetCurrentClientSampleTime(uint64_t *out_input_sample_time, uint64_t *out_output_sample_time); ``` -------------------------------- ### Accessing the Value Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobooleancontrol Methods for setting and getting the Boolean value of the control. ```APIDOC ## Accessing the Value ### `SetControlValue` Sets the Boolean value of the control. ### `GetControlValue` Gets the Boolean value of the control. ``` -------------------------------- ### GetSupportsPrewarming Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getsupportsprewarming Returns a Boolean value that indicates the clock device's support for prewarming. A device that supports prewarming can enable a minimal state that allows it to be ready to start audio I/O immediately on demand. This method synchronizes by using the work queue created by the object. ```APIDOC ## GetSupportsPrewarming ### Description Returns a Boolean value that indicates the clock device’s support for prewarming. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Return Value `bool` - `true` if the clock device supports prewarming; `false` otherwise. ### Discussion A device that supports prewarming can enable a minimal state that allows it to be ready to start audio I/O immediately on demand. This method synchronizes by using the work queue created by the object. ### See Also - `SetZeroTimeStampPeriod` - `GetZeroTimestampPeriod` - `SetOutputLatency` - `GetOutputLatency` - `SetInputLatency` - `GetInputLatency` ``` -------------------------------- ### GET /IOUserAudioBox/GetClassID Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobox/getclassid Retrieves the audio class identifier of the IOUserAudioBox object. ```APIDOC ## GET /IOUserAudioBox/GetClassID ### Description Gets the audio class identifier of the object. This method overrides the base class IOUserAudioObject. ### Method GET ### Endpoint IOUserAudioBox/GetClassID ### Response #### Success Response (200) - **IOUserAudioClassID** (type) - The audio class identifier of the object. ``` -------------------------------- ### Create IOUserAudioDevice Instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice/create Use this static method to allocate and initialize an instance of the audio device class. Ensure you provide all required parameters, including the owning driver, prewarming support, and various unique identifiers. ```c++ static OSSharedPtr Create(IOUserAudioDriver *in_driver, bool in_supports_prewarming, OSString *in_device_uid, OSString *in_model_uid, OSString *in_manufacturer_uid, uint32_t in_zero_timestamp_period); ``` -------------------------------- ### GetClockAlgorithm Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getclockalgorithm Gets the clock algorithm of the clock device. Available in DriverKit 21.0+. ```APIDOC ## GetClockAlgorithm ### Description Gets the clock algorithm of the clock device. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Request Example None ### Response #### Success Response - **IOUserAudioClockAlgorithm** (IOUserAudioClockAlgorithm) - The clock algorithm of the clock device. #### Response Example ```c IOUserAudioClockAlgorithm algorithm = GetClockAlgorithm(); ``` ### Discussion This method synchronizes by using the work queue created by the object. ### See Also - `SetClockAlgorithm` - `IOUserAudioClockAlgorithm` - `SetClockIsStable` - `GetClockIsStable` ``` -------------------------------- ### init Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiolevelcontrol/init Initializes an instance of a level control for an audio driver. ```APIDOC ## init ### Description Initializes an instance of a level control. ### Method Virtual Function ### Parameters - **in_driver** (IOUserAudioDriver) - Required - The IOUserAudioDriver that owns this object. - **in_is_settable** (bool) - Required - A Boolean value that indicates if the control can be set. - **in_decibel_value** (float) - Required - A floating-point value that represents the level control’s current value in decibels. - **in_decibel_range** (IOUserAudioLevelControlRange) - Required - A IOUserAudioLevelControlRange that describes the minimum and maximum values of the level control. - **in_control_element** (IOUserAudioObjectPropertyElement) - Required - An IOUserAudioObjectPropertyElement to identify the control. - **in_control_scope** (IOUserAudioObjectPropertyScope) - Required - A IOUserAudioObjectPropertyScope indicating the control’s scope: input, output, global, or play-through. - **in_control_class_id** (IOUserAudioClassID) - Required - The IOUserAudioClassID of the control. ### Return Value - **bool** - true if initialization succeeded; false otherwise. ``` -------------------------------- ### init Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/init Initializes an instance of the audio stream class. ```APIDOC ## init ### Description Initializes an instance of the audio stream class. ### Parameters - **in_driver** (IOUserAudioDriver) - Required - The IOUserAudioDriver that owns this object. - **in_direction** (IOUserAudioStreamDirection) - Required - A IOUserAudioStreamDirection for the stream’s direction: input or output. - **in_io_memory_descriptor** (IOMemoryDescriptor) - Required - A pointer to a IOMemoryDescriptor. The stream maps the descriptor’s buffer to the Host for doing audio I/O. ### Return Value - **bool** - true if initialization succeeded; false otherwise. ``` -------------------------------- ### IOUserAudioControl init Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiocontrol/init Initializes an instance of an audio control. Available in DriverKit 21.0+. ```APIDOC ## IOUserAudioControl init ### Description Initializes an instance of an audio control. ### Method `virtual bool init(IOUserAudioDriver *in_driver, bool in_is_settable, IOUserAudioObjectPropertyElement in_control_element, IOUserAudioObjectPropertyScope in_control_scope)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (true) - **bool** - `true` if initialization succeeded; `false` otherwise. #### Response Example ``` true ``` ### See Also - `IOUserAudioDriver` - `IOUserAudioObjectPropertyElement` - `IOUserAudioObjectPropertyScope` ``` -------------------------------- ### GetControlValue Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostereopancontrol/getcontrolvalue Gets the floating-point stereo pan value of the control. Available in DriverKit 21.0+. ```APIDOC ## GetControlValue ### Description Gets the floating-point stereo pan value of the control. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Request Example N/A ### Response #### Success Response - **float** - The floating-point stereo pan value of the control. #### Response Example ``` float stereoPanValue = GetControlValue(); ``` ### Discussion This method synchronizes by using the work queue created by the object. ### See Also - `SetControlValue` - `SetPanningChannels` - `GetPanningChannels` ``` -------------------------------- ### Accessing Selected Values Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioselectorcontrol Methods for setting, getting, and managing selector values and their descriptions. ```APIDOC ### Accessing the Selected Values - `SetCurrentSelectedValues` Sets the current selections of the selector. - `GetCurrentSelectedValues` Gets the current selections of the selector. - `GetControlValuesCount` Gets the number of available selector values. - `AddControlValueDescriptions` Add value descriptions to the selector control. - `RemoveControlValueDescriptions` Removes value descriptions from the selector control. - `GetControlValueDescriptions` Gets value descriptions used by the selector control. ``` -------------------------------- ### Instance Method: init Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioobject/init-26qwx Initializes an empty object. Available in DriverKit 21.0+. ```APIDOC ## Instance Method: init ### Description Initializes an empty object. ### Method `init()` ### Endpoint N/A (Instance Method) ### Parameters This method does not take any parameters. ### Request Body N/A ### Response #### Success Response (bool) - **`true`**: Initialization succeeded. - **`false`**: Initialization failed. ### Response Example ``` // Example of how the return value might be used: bool success = [audioObject init]; if (success) { // Initialization successful } else { // Initialization failed } ``` ### Discussion This no-arg initializer always returns `false`. ``` -------------------------------- ### GetControlValueDescriptions Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioselectorcontrol/getcontrolvaluedescriptions Gets value descriptions used by the selector control. Available in DriverKit 21.0+. ```APIDOC ## GetControlValueDescriptions ### Description Gets value descriptions used by the selector control. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (This is a method signature, not an API endpoint with a typical response) #### Response Example None ### Signature ```c size_t GetControlValueDescriptions(IOUserAudioSelectorValueDescription *out_control_value_descriptions, size_t in_num_value_descriptions); ``` ### Parameters - **out_control_value_descriptions** (IOUserAudioSelectorValueDescription *) - A pointer to a buffer of type `IOUserAudioSelectorValueDescription`, with a size of `in_num_value_descriptions`. On return, this buffer contains the value descriptions. - **in_num_value_descriptions** (size_t) - The number of descriptions in `out_control_value_descriptions`. ### Return Value - **size_t** - The number of values populated in the `out_control_value_descriptions` buffer. ### Discussion This method synchronizes by using the work queue created by the object. ### See Also - `SetCurrentSelectedValues` - `GetCurrentSelectedValues` - `GetControlValuesCount` - `IOUserAudioSelectorValue` - `AddControlValueDescriptions` - `RemoveControlValueDescriptions` - `IOUserAudioSelectorValueDescription` ``` -------------------------------- ### IOUserAudioBox init Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobox/init Initializes an instance of the audio box class. This method is available in DriverKit 21.0 and later. ```APIDOC ## IOUserAudioBox init ### Description Initializes an instance of the audio box class. ### Method `virtual bool init(IOUserAudioDriver *in_driver, bool in_is_acquirable, OSString *in_box_uid);` ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (true) - `bool` - `true` if initialization succeeded; `false` otherwise. #### Response Example N/A ### Discussion Always pass in the `IOUserAudioDriver` and arguments. The no-argument `IOUserAudioBox/init()` always returns `false`. ### See Also - Creating an Audio Box (`Create`) - `IOUserAudioDriver` ``` -------------------------------- ### GET GetBaseClassID Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice/getbaseclassid Retrieves the audio class identifier of the base class object for an IOUserAudioDevice. ```APIDOC ## GET GetBaseClassID ### Description Gets the audio class identifier of the base class object. This method overrides the base class IOUserAudioObject. ### Method GET ### Endpoint GetBaseClassID ### Response - **IOUserAudioClassID** (type) - An identifier for the type of audio object. ``` -------------------------------- ### GetCustomPropertyValueWithQualifier Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiocustomproperty/getcustompropertyvaluewithqualifier Gets the custom property value for a given qualifier. Available in DriverKit 21.0+. ```APIDOC ## GetCustomPropertyValueWithQualifier ### Description Gets the custom property value for a given qualifier. ### Method `virtual kern_return_t GetCustomPropertyValueWithQualifier(OSObject *in_qualifier_data, OSObject **out_data); ` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (kIOReturnSuccess) Returns `kIOReturnSuccess` on success, or another value if an error occurs. #### Response Example None ### Discussion Use this method to get the custom property’s data value, optionally adding a qualifier to further refine the action. For example, if a given property exists on multiple devices, use a device identifier as the qualifier to indicate which device to get the value from. The base class returns the custom property value set on the object without looking at contents of the qualifier data. If the returned value should depend on the qualifier, subclass `IOUserAudioCustomProperty` and override this method. ### See Also - `SetQualifierAndDataValue` - `GetCustomPropertyInfo` - `IOUserAudioCustomPropertyInfo` ``` -------------------------------- ### IOUserAudioLevelControl: free Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiolevelcontrol/free Documentation for the free instance method used to release resources for the level control. ```APIDOC ## free ### Description Frees the level control. ### Method Instance Method ### Signature `virtual void free();` ### Availability DriverKit 21.0+ ``` -------------------------------- ### GetAvailableSampleRates Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getavailablesamplerates Gets the available sample rates of the clock device. Available in DriverKit 21.0+. ```APIDOC ## GetAvailableSampleRates ### Description Gets the available sample rates of the clock device. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters `out_sample_rates` (double *) - Required - A pointer to a buffer of type `double` whose size corresponds to `in_num_rates`. After the call completes, this buffer contains the available sample rates. `in_num_rates` (size_t) - Required - The number of rates in the `out_sample_rates` buffer. ### Return Value A `size_t` that indicates how many rates were set in the `out_sample_rates` buffer. ### Discussion This method synchronizes by using the work queue created by the object. ### See Also * `SetSampleRate` * `GetSampleRate` * `SetAvailableSampleRates` * `GetNumberAvailableSampleRates` ``` -------------------------------- ### GetOutputLatency Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getoutputlatency Gets the output latency of the clock device. Available in DriverKit 21.0 and later. ```APIDOC ## GetOutputLatency ### Description Gets the output latency of the clock device. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Request Example N/A ### Response #### Success Response - **uint32_t**: The output latency of the clock device. ### Response Example N/A (Method returns a value) ### Discussion This method synchronizes by using the work queue created by the object. ``` -------------------------------- ### Getting Information About the Class Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobooleancontrol Methods for retrieving class identification information for the IOUserAudioBooleanControl object. ```APIDOC ## Getting Information About the Class ### `GetClassID` Gets the audio class identifier of the object. ### `GetBaseClassID` Gets the audio class identifier of the base class object. ``` -------------------------------- ### Create and Configure Audio I/O Buffers and Streams Source: https://developer.apple.com/documentation/audiodriverkit/creating-an-audio-device-driver Allocate shared memory for I/O ring buffers and create user audio stream objects for input and output. Configure stream properties like name, available formats, and current format. ```cpp OSSharedPtr output_io_ring_buffer; OSSharedPtr input_io_ring_buffer; const auto buffer_size_bytes = static_cast(in_zero_timestamp_period * sizeof(uint16_t) * channels_per_frame); error = IOBufferMemoryDescriptor::Create(kIOMemoryDirectionInOut, buffer_size_bytes, 0, output_io_ring_buffer.attach()); FailIf(error != kIOReturnSuccess, , Failure, "Failed to create output IOBufferMemoryDescriptor"); error = IOBufferMemoryDescriptor::Create(kIOMemoryDirectionInOut, buffer_size_bytes, 0, input_io_ring_buffer.attach()); FailIf(error != kIOReturnSuccess, , Failure, "Failed to create input IOBufferMemoryDescriptor"); // Create an output/input stream object and pass in the I/O ring buffer memory descriptor. ivars->m_output_stream = IOUserAudioStream::Create(in_driver, IOUserAudioStreamDirection::Output, output_io_ring_buffer.get()); FailIfNULL(ivars->m_output_stream.get(), error = kIOReturnNoMemory, Failure, "failed to create output stream"); ivars->m_input_stream = IOUserAudioStream::Create(in_driver, IOUserAudioStreamDirection::Input, input_io_ring_buffer.get()); FailIfNULL(ivars->m_input_stream.get(), error = kIOReturnNoMemory, Failure, "failed to create input stream"); // Configure stream properties: name, available formats, and current format. ivars->m_output_stream->SetName(output_stream_name.get()); ivars->m_output_stream->SetAvailableStreamFormats(stream_formats, 2); ivars->m_stream_format = stream_formats[0]; ivars->m_output_stream->SetCurrentStreamFormat(&ivars->m_stream_format); ivars->m_input_stream->SetName(input_stream_name.get()); ivars->m_input_stream->SetAvailableStreamFormats(stream_formats, 2); ivars->m_input_stream->SetCurrentStreamFormat(&ivars->m_stream_format); // Add a stream object to the driver. error = AddStream(ivars->m_output_stream.get()); FailIfError(error, , Failure, "failed to add output stream"); error = AddStream(ivars->m_input_stream.get()); FailIfError(error, , Failure, "failed to add input stream"); ``` -------------------------------- ### Define IOUserAudioStartStopFlags Enumeration Source: https://developer.apple.com/documentation/audiodriverkit/audiodriverkit/iouseraudiostartstopflags The enumeration type used to indicate I/O start or stop states. ```C enum IOUserAudioStartStopFlags : uint64_t; ``` -------------------------------- ### Instance Methods Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiodevice Additional instance methods available for the IOUserAudioDevice class. ```APIDOC ## Instance Methods ### `GetCurrentClientIOTime` ### `SetIOOperationHandler` ### `SetWantsStreamFormatsRestored` ``` -------------------------------- ### GET GetStreamDirection Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostream/getstreamdirection Retrieves the direction of the audio stream, indicating whether it is an input or output stream. ```APIDOC ## GetStreamDirection ### Description Gets the direction of the stream: input or output. ### Method Instance Method ### Return Value The direction of the stream, as a IOUserAudioStreamDirection value. ``` -------------------------------- ### init (IOUserAudioObject) Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioobject/init-1ar2z Initializes an instance of the audio object base class using the provided IOUserAudioDriver. ```APIDOC ## init ### Description Initializes an instance of the audio object base class. Always pass in the IOUserAudioDriver. The no-arg initializer, init, always returns false. ### Method Initialization Method ### Parameters #### Path Parameters - **in_audio_driver** (IOUserAudioDriver) - Required - The IOUserAudioDriver that owns this object. ### Response #### Success Response - **Boolean** - Returns true if initialization succeeded, false otherwise. ``` -------------------------------- ### IOUserAudioSliderControl - Accessing the Value Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioslidercontrol Details on how to set, get, and manage the value and range of an IOUserAudioSliderControl object. ```APIDOC ## Accessing the Value ### `SetControlValue` Sets the value of the slider control. ### `GetControlValue` Gets the value of the slider control. ### `SetRange` Sets the range of possible values for the slider. ### `GetRange` Gets the range of possible values for the slider. ### `IOUserAudioSliderRange` A type that indicates minimum and maximum values for slider controls. ``` -------------------------------- ### GetSupportsPrewarming Instance Method Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getsupportsprewarming Call this method to determine if a clock device supports prewarming. A device supporting prewarming can enter a minimal state to be ready for immediate audio I/O on demand. This method synchronizes using the object's work queue. ```c++ bool GetSupportsPrewarming(); ``` -------------------------------- ### Initialize IOUserAudioControl Instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiocontrol/init Use this method to initialize an instance of an audio control. Ensure DriverKit 21.0+ is available. The parameters specify the owning driver, settability, control element, and scope. ```c++ virtual bool init(IOUserAudioDriver *in_driver, bool in_is_settable, IOUserAudioObjectPropertyElement in_control_element, IOUserAudioObjectPropertyScope in_control_scope); ``` -------------------------------- ### GET GetBaseClassID Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostereopancontrol/getbaseclassid Retrieves the audio class identifier of the base class object for an IOUserAudioStereoPanControl instance. ```APIDOC ## GetBaseClassID ### Description Gets the audio class identifier of the base class object. This method overrides the base class IOUserAudioObject. ### Method Virtual Method ### Return Value - **IOUserAudioClassID** - The audio class identifier of the base class object. ### See Also - GetClassID: Gets the audio class identifier of the object. - IOUserAudioClassID: An identifier for the type of audio object. ``` -------------------------------- ### GetDeviceIsAlive Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getdeviceisalive Gets a Boolean value that represents whether the device is alive. Available in DriverKit 21.0+. ```APIDOC ## GetDeviceIsAlive ### Description Gets a Boolean value that represents whether the device is alive. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Request Body None ### Response #### Success Response - **bool**: `true` if the device is alive; `false` otherwise. ### Response Example ```json { "isAlive": true } ``` ### Discussion This method synchronizes by using the work queue created by the object. ``` -------------------------------- ### Implement NewUserClient_Impl for AudioDriverKit Source: https://developer.apple.com/documentation/audiodriverkit/creating-an-audio-device-driver Handles incoming user client connection requests by distinguishing between HAL requests and custom app connections. ```cpp kern_return_t SimpleAudioDriver::NewUserClient_Impl(uint32_t in_type, IOUserClient** out_user_client) { kern_return_t error = kIOReturnSuccess; // Have the superclass create the IOUserAudioDriverUserClient object // if the type is kIOUserAudioDriverUserClientType. if (in_type == kIOUserAudioDriverUserClientType) { error = super::NewUserClient(in_type, out_user_client, SUPERDISPATCH); FailIfError(error, , Failure, "Failed to create user client"); FailIfNULL(*out_user_client, error = kIOReturnNoMemory, Failure, "Failed to create user client"); } else { IOService* user_client_service = nullptr; error = Create(this, "SimpleAudioDriverUserClientProperties", &user_client_service); FailIfError(error, , Failure, "failed to create the SimpleAudioDriver user client"); *out_user_client = OSDynamicCast(IOUserClient, user_client_service); } Failure: return error; } ``` -------------------------------- ### GetDeviceIsRunning Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/getdeviceisrunning Gets a Boolean value that indicates whether the device is running. Available in DriverKit 21.0+. ```APIDOC ## GetDeviceIsRunning ### Description Gets a Boolean value that indicates whether the device is running. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Request Example ```c bool GetDeviceIsRunning(); ``` ### Response #### Success Response - **bool**: `true` if the device is running; `false` otherwise. ### Response Example ```json { "isRunning": true } ``` ### Discussion This method synchronizes by using the work queue created by the object. ``` -------------------------------- ### init (IOUserAudioBooleanControl) Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiobooleancontrol/init Initializes an instance of a Boolean control for an audio driver. ```APIDOC ## init ### Description Initializes an instance of a Boolean control. ### Parameters - **in_driver** (IOUserAudioDriver) - Required - The IOUserAudioDriver that owns this object. - **in_is_settable** (bool) - Required - A Boolean value that indicates if the control can be set. - **in_control_value** (bool) - Required - A Boolean value that represents the control’s current value. - **in_control_element** (IOUserAudioObjectPropertyElement) - Required - An IOUserAudioObjectPropertyElement to identify the control. - **in_control_scope** (IOUserAudioObjectPropertyScope) - Required - A IOUserAudioObjectPropertyScope indicating the control’s scope: input, output, global, or play-through. - **in_control_class_id** (IOUserAudioClassID) - Required - The IOUserAudioClassID of the control. ### Return Value - **bool** - true if initialization succeeded; false otherwise. ``` -------------------------------- ### Create an IOUserAudioStereoPanControl instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiostereopancontrol/create Use this static method to allocate and initialize a new stereo pan control. Do not use this method if you are subclassing IOUserAudioStereoPanControl. ```cpp static OSSharedPtr Create(IOUserAudioDriver *in_driver, bool in_is_settable, float in_control_value, IOUserAudioObjectPropertyElement in_left_channel, IOUserAudioObjectPropertyElement in_right_channel, IOUserAudioObjectPropertyElement in_control_element, IOUserAudioObjectPropertyScope in_control_scope, IOUserAudioClassID in_control_class_id); ``` -------------------------------- ### Initialize an IOUserAudioClockDevice instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudioclockdevice/init Use this method to initialize the audio clock device. It requires an IOUserAudioDriver instance and various OSString identifiers. ```cpp virtual bool init(IOUserAudioDriver *in_driver, bool in_supports_prewarming, OSString *in_device_uid, OSString *in_model_uid, OSString *in_manufacturer_uid, uint32_t in_zero_timestamp_period); ``` -------------------------------- ### Create IOUserAudioCustomProperty instance Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiocustomproperty/create Allocates and initializes a new custom property object. Do not use this method if you are subclassing IOUserAudioCustomProperty. ```cpp static OSSharedPtr Create(IOUserAudioDriver *in_audio_driver, IOUserAudioObjectPropertyAddress in_prop_addr, bool in_is_property_settable, IOUserAudioCustomPropertyDataType in_qualifier_data_type, IOUserAudioCustomPropertyDataType in_data_type); ``` -------------------------------- ### Slider Control Methods Source: https://developer.apple.com/documentation/audiodriverkit/iouseraudiosliderrange Methods for interacting with slider controls, including setting and getting values and ranges. ```APIDOC ## Slider Control Methods ### SetControlValue Sets the value of the slider control. ### GetControlValue Gets the value of the slider control. ### SetRange Sets the range of possible values for the slider. ### GetRange Gets the range of possible values for the slider. ```