Created
April 11, 2021 18:00
-
-
Save aaronkollasch/7adc237aa6107fab3e25572473e02d81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| import CoreAudio | |
| import AudioToolbox | |
| var str = "Compare bool and uint32 for kAudioDevicePropertyMute" | |
| var propAddr = AudioObjectPropertyAddress( | |
| mSelector: AudioObjectPropertySelector(kAudioHardwarePropertyDefaultOutputDevice), | |
| mScope: AudioObjectPropertyScope(kAudioObjectPropertyScopeGlobal), | |
| mElement: AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)) | |
| var defaultAudioHardwareID : AudioDeviceID = 0 | |
| var propSize = UInt32(MemoryLayout<uint32>.size) | |
| var status = AudioObjectGetPropertyData( | |
| AudioObjectID(kAudioObjectSystemObject), | |
| &propAddr, | |
| 0 , | |
| nil, | |
| &propSize, | |
| &defaultAudioHardwareID | |
| ) | |
| print("hwID:", defaultAudioHardwareID) | |
| var propertyAddress = AudioObjectPropertyAddress( | |
| mSelector: kAudioDevicePropertyMute, | |
| mScope: kAudioObjectPropertyScopeOutput, | |
| mElement: kAudioObjectPropertyElementMaster | |
| ) | |
| print("\ninit false:") | |
| var isMuted_uint: uint32 = 0; | |
| var isMutedUIntSize: UInt32 = UInt32(MemoryLayout<uint32>.size) | |
| var isMuted_bool: Bool = false; | |
| var isMutedBoolSize: UInt32 = UInt32(MemoryLayout<Bool>.size) | |
| AudioObjectGetPropertyData( | |
| defaultAudioHardwareID, | |
| &propertyAddress, | |
| 0, | |
| nil, | |
| &isMutedUIntSize, | |
| &isMuted_uint | |
| ) | |
| AudioObjectGetPropertyData( | |
| defaultAudioHardwareID, | |
| &propertyAddress, | |
| 0, | |
| nil, | |
| &isMutedBoolSize, | |
| &isMuted_bool | |
| ) | |
| print("\ninit true:") | |
| print("mute uint:", isMuted_uint) // uint changes to reflect true mut status | |
| print("mute bool:", isMuted_bool) // bool remains false | |
| isMuted_uint = 1; | |
| isMuted_bool = true; | |
| AudioObjectGetPropertyData( | |
| defaultAudioHardwareID, | |
| &propertyAddress, | |
| 0, | |
| nil, | |
| &isMutedUIntSize, | |
| &isMuted_uint | |
| ) | |
| AudioObjectGetPropertyData( | |
| defaultAudioHardwareID, | |
| &propertyAddress, | |
| 0, | |
| nil, | |
| &isMutedBoolSize, | |
| &isMuted_bool | |
| ) | |
| print("mute uint:", isMuted_uint) // uint changes to reflect true mut status | |
| print("mute bool:", isMuted_bool) // bool remains true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment