From d44af635112d391cba2b9a488ea4963c0922c531 Mon Sep 17 00:00:00 2001 From: Daniel Prows Date: Mon, 21 Aug 2023 10:56:03 -0600 Subject: [PATCH] Fixing an issue where some devices (usb) don't support channel 0, so i switched to virtual main volume --- src/volume/coreAudio.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/volume/coreAudio.go b/src/volume/coreAudio.go index a327259..e98cc7c 100644 --- a/src/volume/coreAudio.go +++ b/src/volume/coreAudio.go @@ -2,8 +2,9 @@ package volume /* #cgo CFLAGS: -x objective-c - #cgo LDFLAGS: -framework CoreAudio + #cgo LDFLAGS: -framework CoreAudio -framework AudioToolbox #include + #include */ import "C" import ( @@ -43,10 +44,17 @@ func GetDefaultOutputDevice() (AudioObjectID, OSStatus) { func GetVolume(objectID AudioObjectID) (float32, OSStatus) { properties := C.AudioObjectPropertyAddress{ - C.kAudioDevicePropertyVolumeScalar, + C.kAudioHardwareServiceDeviceProperty_VirtualMainVolume, C.kAudioDevicePropertyScopeOutput, - 0, //main channel + C.kAudioObjectPropertyElementMain, } + /* + properties := C.AudioObjectPropertyAddress{ + C.kAudioDevicePropertyVolumeScalar, + C.kAudioDevicePropertyScopeOutput, + 0, //main channel + } + */ var data C.Float32 dataSize := C.UInt32(unsafe.Sizeof(data)) @@ -66,10 +74,17 @@ func GetVolume(objectID AudioObjectID) (float32, OSStatus) { func SetVolume(objectID AudioObjectID, volume float32) OSStatus { properties := C.AudioObjectPropertyAddress{ - C.kAudioDevicePropertyVolumeScalar, + C.kAudioHardwareServiceDeviceProperty_VirtualMainVolume, C.kAudioDevicePropertyScopeOutput, - 0, //main channel + C.kAudioObjectPropertyElementMain, } + /* + properties := C.AudioObjectPropertyAddress{ + C.kAudioDevicePropertyVolumeScalar, + C.kAudioDevicePropertyScopeOutput, + 0, //main channel + } + */ data := C.Float32(volume)