Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Cannot get output balance of MacBook Pro M1 Speakers #59

Open
jamsinclair opened this issue Jan 16, 2022 · 3 comments
Open

Cannot get output balance of MacBook Pro M1 Speakers #59

jamsinclair opened this issue Jan 16, 2022 · 3 comments

Comments

@jamsinclair
Copy link
Contributor

jamsinclair commented Jan 16, 2022

Problem

I am unable to retrieve the output balance for the builtin speakers on my M1 MacBook Pro.

Other devices, like external headphones, are able to retrieve the balance with no issues.

Specs:

  • MacOS 12.0.1 (Monterey)
  • MacBook Pro (14-inch, 2021), Apple M1 Pro chip
  • Xcode 13.2.1

Code in Use:

import SimplyCoreAudio

let simplyCA = SimplyCoreAudio()
let device = simplyCA.defaultOutputDevice

// This works fine for both builtin and external audio devices
if let outVolume = device?.virtualMainVolume(scope: .output) {
    os_log("Current default device volume of: %F", outVolume)
}

// This works only for external audio devices, builtin speakers do not work
if let outBalance = device?.virtualMainBalance(scope: .output) {
    os_log("Current default device balance of: %F", outBalance)
}

Notes

Feels like this might be an underlying apple issue or I am just doing something stupid 😅

Also so much ❤️ for this library. The Audio APIs are a real developer pain to work with. This will help simplify a bunch of code in my app.

@jamsinclair
Copy link
Contributor Author

jamsinclair commented Jan 16, 2022

I've copied some of the source code and trying it out in my app, looks like maybe it's throwing kCMIOHardwareUnknownPropertyError.

Does this mean newer macbooks don't expose the balance property for their speakers?

This is likely terrible code, let me know if there's a better approach to debug!

var masterBalanceAddress = AudioObjectPropertyAddress(mSelector: kAudioHardwareServiceDeviceProperty_VirtualMainBalance,
                                                      mScope: kAudioDevicePropertyScopeOutput,
                                                      mElement: kAudioObjectPropertyElementMain)

var deviceId: AudioObjectID = <put device id here>        
var balanceValue: Float32 = 0
var size: UInt32 = UInt32(MemoryLayout<Float32>.size)

let result: OSStatus = AudioObjectGetPropertyData(deviceID, &masterBalanceAddress, UInt32(0), nil, &size, &balanceValue)

// Outputs status of 2003332927 which is `kCMIOHardwareUnknownPropertyError`

@rnine
Copy link
Owner

rnine commented Jan 16, 2022

@jamsinclair I don't have access to an M1 Mac right now, but it sounds like the built-in speakers output on your M1 Mac may not support setting this property. One way to confirm this is by opening Audio MIDI Setup (included with macOS) and check if the UI control for Balance is enabled for this device:

Screenshot 2022-01-16 at 12 57 35

@jamsinclair
Copy link
Contributor Author

jamsinclair commented Jan 16, 2022

@rnine Thanks! There's definitely enabled options to configure the balance for the system speakers in both the "Sound Preferences" and "Audio Midi Setup" GUIs.

I would be happy to help debug further from my machine. Any ideas of CoreAudio properties or options I can play around with to get/set the balance?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants