I am using SimplyCoreAudio to switch the clock source. The code is as follows:
debugPrint("nullAudioDevice.clockSourceID \(nullAudioDevice.clockSourceID)")
if let cid = hardwareDevice.clockSourceID {
if nullAudioDevice.setClockSourceID(cid) {
debugPrint("hardwareDevice.clockSourceID \(hardwareDevice.clockSourceID)")
debugPrint("nullAudioDevice.clockSourceID \(nullAudioDevice.clockSourceID)")
}else{
debugPrint("false")
}
}
The printed result is as follows:
nullAudioDevice.clockSourceID Optional(4294967295)
hardwareDevice.clockSourceID Optional(690487296)
nullAudioDevice.clockSourceID Optional(4294967295)
Why does the ID returned after successfully setting the clock source with setClockSourceID still show the original one? Does this mean the setting was not successful? Is there a proper method to synchronize the clock source setting?
1 Answer 1
This is my understanding:
Setting clockSource is not available for just any audio devices, as CoreAudio.AudioHardwareDevice does not have a property clockSource; only the subclass aggregate devices have it, see: CoreAudio.AudioHardwareAggregateDevice.
You can also check this in macOS Audio MIDI Setup app: Clock source is greyed out for all devices except aggregate devices.
The CoreAudio "clock source" is not to be mixed with the actual audio clock source setting of (professional) audio hardware that provides setting it to "internal", "input", "wordclock" etc. in its driver.
So why does your code return success (true)?
In your code, nullAudioDevice.setClockSourceID(cid) returns true, which you did not expect.
The general definition of a null device is:
"the null device is a device file that discards all data written to it but reports that the write operation succeeded.".
The same applies to SimplyCoreAudio's NullAudio.device.
Comments
Explore related questions
See similar questions with these tags.
AudioDevice.clockSourceIDsreturning a "list of all the clock source identifiers available for this audio device" .