@@ -11,11 +11,10 @@ import CoreAudio.AudioServerPlugIn
1111import Atomics
1212
1313class EQMDevice : EQMObject {
14- static let id = AudioObjectID ( kDeviceUID) !
1514 static var name = kEQMDeviceDefaultName
1615 static var sampleRate = kDefaultSampleRate
1716 static var running = false
18- static var shown = false
17+ static var shown = true
1918 static var latency : UInt32 = 0
2019 static var ioCounter = ManagedAtomic < UInt64 > ( 0 )
2120 static var anchorHostTime : UInt64 = 0
@@ -24,7 +23,7 @@ class EQMDevice: EQMObject {
2423 static let ioMutex = Mutex ( )
2524
2625 static let ringBufferSize : UInt32 = 16384
27- static var ringBuffer = UnsafeMutablePointer< Float32> . allocate( capacity: Int ( ringBufferSize * kChannelCount) )
26+ static var ringBuffer = UnsafeMutablePointer< Float32> . allocate( capacity: Int ( ringBufferSize * 4 * kChannelCount) )
2827
2928 static func getDescription ( for samplingRate: Float64 ) -> AudioStreamBasicDescription {
3029 return AudioStreamBasicDescription (
@@ -63,14 +62,14 @@ class EQMDevice: EQMObject {
6362 kAudioDevicePropertyIcon,
6463 kAudioDevicePropertyStreams,
6564 kAudioObjectPropertyCustomPropertyInfoList,
65+ kAudioDevicePropertyDeviceCanBeDefaultSystemDevice,
6666 EQMDeviceCustom . properties. shown,
6767 EQMDeviceCustom . properties. version,
6868 EQMDeviceCustom . properties. latency,
6969 EQMDeviceCustom . properties. name:
7070 return true
7171
7272 case kAudioDevicePropertyDeviceCanBeDefaultDevice,
73- kAudioDevicePropertyDeviceCanBeDefaultSystemDevice,
7473 kAudioDevicePropertyLatency,
7574 kAudioDevicePropertySafetyOffset,
7675 kAudioDevicePropertyPreferredChannelsForStereo,
@@ -143,7 +142,8 @@ class EQMDevice: EQMObject {
143142 case kAudioDevicePropertyZeroTimeStampPeriod: return sizeof ( UInt32 . self)
144143 case kAudioDevicePropertyIcon: return sizeof ( CFURL . self)
145144
146- case kAudioObjectPropertyCustomPropertyInfoList: return sizeof ( AudioServerPlugInCustomPropertyInfo . self) * EQMDeviceCustom. properties. count
145+ case kAudioObjectPropertyCustomPropertyInfoList:
146+ return sizeof ( AudioServerPlugInCustomPropertyInfo . self) * EQMDeviceCustom. properties. count
147147 case EQMDeviceCustom . properties. latency: return sizeof ( CFNumber . self)
148148 case EQMDeviceCustom . properties. shown: return sizeof ( CFBoolean . self)
149149 case EQMDeviceCustom . properties. version: return sizeof ( CFString . self)
@@ -261,7 +261,7 @@ class EQMDevice: EQMObject {
261261 // default device. This is the device that is used to play interface sounds and
262262 // other incidental or UI-related sounds on. Most devices should allow this
263263 // although devices with lots of latency may not want to.
264- return . integer( shown ? 1 : 0 )
264+ return . integer( 1 )
265265 case kAudioDevicePropertyLatency:
266266 // This property returns the presentation latency of the device. For this,
267267 // device, the value is 0 due to the fact that it always vends silence.
@@ -439,6 +439,22 @@ class EQMDevice: EQMObject {
439439 let shownRef = data. load ( as: CFBoolean . self)
440440
441441 shown = CFBooleanGetValue ( shownRef)
442+
443+ changedProperties. append (
444+ AudioObjectPropertyAddress (
445+ mSelector: kAudioDevicePropertyDeviceCanBeDefaultDevice,
446+ mScope: kAudioObjectPropertyScopeOutput,
447+ mElement: kAudioObjectPropertyElementMaster
448+ )
449+ )
450+
451+ changedProperties. append (
452+ AudioObjectPropertyAddress (
453+ mSelector: kAudioDevicePropertyDeviceCanBeDefaultSystemDevice,
454+ mScope: kAudioObjectPropertyScopeGlobal,
455+ mElement: kAudioObjectPropertyElementMaster
456+ )
457+ )
442458 return noErr
443459
444460 case EQMDeviceCustom . properties. latency:
@@ -452,6 +468,14 @@ class EQMDevice: EQMObject {
452468 if latency != newLatency {
453469 latency = UInt32 ( newLatency)
454470 }
471+
472+ changedProperties. append (
473+ AudioObjectPropertyAddress (
474+ mSelector: kAudioDevicePropertyLatency,
475+ mScope: kAudioObjectPropertyScopeOutput,
476+ mElement: kAudioObjectPropertyElementMaster
477+ )
478+ )
455479 return noErr
456480 case EQMDeviceCustom . properties. name:
457481 // Only allow eqMac app to set this property
@@ -493,7 +517,7 @@ class EQMDevice: EQMObject {
493517 timestampCount = 0
494518 anchorSampleTime = 0
495519 anchorHostTime = mach_absolute_time ( )
496- ringBuffer = UnsafeMutablePointer< Float32> . allocate( capacity: Int ( ringBufferSize * kChannelCount) )
520+ ringBuffer = UnsafeMutablePointer< Float32> . allocate( capacity: Int ( ringBufferSize * 4 * kChannelCount) )
497521 } else {
498522 // IO already running so increment the counter
499523 ioCounter. wrappingIncrement ( ordering: . relaxed)
@@ -548,7 +572,7 @@ class EQMDevice: EQMObject {
548572 return noErr
549573 }
550574
551- static func doIO ( clientID : UInt32 , operationID: UInt32 , sample: UnsafeMutablePointer < Float32 > , cycleInfo: AudioServerPlugInIOCycleInfo , frameSize: UInt32 ) -> OSStatus {
575+ static func doIO ( client : EQMClient ? , operationID: UInt32 , sample: UnsafeMutablePointer < Float32 > , cycleInfo: AudioServerPlugInIOCycleInfo , frameSize: UInt32 ) -> OSStatus {
552576
553577 ioMutex. lock ( )
554578
@@ -597,7 +621,7 @@ class EQMDevice: EQMObject {
597621 }
598622
599623 // Clean up buffer
600- let cleanFromFrame = sampleTime + Int( frame) - 16384
624+ let cleanFromFrame = sampleTime + Int( frame) - Int ( ringBufferSize )
601625 let remainder = cleanFromFrame % Int( ringBufferSize)
602626 let cleanFrame = remainder * Int( kChannelCount) + Int( channel)
603627 ringBuffer [ cleanFrame] = 0
0 commit comments