summaryrefslogtreecommitdiff
path: root/src/output/plugins
diff options
context:
space:
mode:
authorYue Wang <Wang-Yue@users.noreply.github.com>2018-07-10 15:51:32 -0700
committerGitHub <noreply@github.com>2018-07-10 15:51:32 -0700
commit680fdb0338c5f30c1113bf1227579a51261098b7 (patch)
treea8175e38c74ac8a58f4182343b3b6c65aab0ec2d /src/output/plugins
parent727078f65d7c2ccb3cd2a9c7c331b4739fcfd76d (diff)
enable macOS to use Hardware Mixer
- Update the mixer to set on device property instead of audio unit property. When user choose "hardware" as mixer type, they will be able to change the hardware device volume instead of the software (AudioUnit) volume. - We don't use square root scale in volume calculation as previous code did. This will make the volume level in line with system volume meter --- That is, MPD will have the same percentage volume reading compared to System Setting (Either in "System Preference" or in "Audio Midi Setup" app)
Diffstat (limited to 'src/output/plugins')
-rw-r--r--src/output/plugins/OSXOutputPlugin.cxx46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/output/plugins/OSXOutputPlugin.cxx b/src/output/plugins/OSXOutputPlugin.cxx
index dddbd83a0..5a7bf415f 100644
--- a/src/output/plugins/OSXOutputPlugin.cxx
+++ b/src/output/plugins/OSXOutputPlugin.cxx
@@ -174,35 +174,47 @@ OSXOutput::Create(EventLoop &, const ConfigBlock &block)
int
OSXOutput::GetVolume()
{
- AudioUnitParameterValue dvolume;
- char errormsg[1024];
+ Float32 vol;
+ AudioObjectPropertyAddress aopa = {
+ .mSelector = kAudioDevicePropertyVolumeScalar,
+ .mScope = kAudioObjectPropertyScopeOutput,
+ .mElement = kAudioObjectPropertyElementMaster,
+ };
+ UInt32 size = sizeof(vol);
+ OSStatus status = AudioObjectGetPropertyData(dev_id,
+ &aopa,
+ 0,
+ NULL,
+ &size,
+ &vol);
- OSStatus status = AudioUnitGetParameter(au, kHALOutputParam_Volume,
- kAudioUnitScope_Global, 0, &dvolume);
if (status != noErr) {
+ char errormsg[1024];
osx_os_status_to_cstring(status, errormsg, sizeof(errormsg));
throw FormatRuntimeError("unable to get volume: %s", errormsg);
}
- /* see the explanation in SetVolume, below */
- return static_cast<int>(dvolume * dvolume * 100.0);
+ return static_cast<int>(vol * 100.0);
}
void
OSXOutput::SetVolume(unsigned new_volume) {
- char errormsg[1024];
-
- /* The scaling below makes shifts in volume greater at the lower end
- * of the scale. This mimics the "feel" of physical volume levers. This is
- * generally what users of audio software expect.
- */
-
- AudioUnitParameterValue scaled_volume =
- sqrt(static_cast<AudioUnitParameterValue>(new_volume) / 100.0);
+ Float32 vol = new_volume / 100.0;
+ AudioObjectPropertyAddress aopa = {
+ .mSelector = kAudioDevicePropertyVolumeScalar,
+ .mScope = kAudioObjectPropertyScopeOutput,
+ .mElement = kAudioObjectPropertyElementMaster
+ };
+ UInt32 size = sizeof(vol);
+ OSStatus status = AudioObjectSetPropertyData(dev_id,
+ &aopa,
+ 0,
+ NULL,
+ size,
+ &vol);
- OSStatus status = AudioUnitSetParameter(au, kHALOutputParam_Volume,
- kAudioUnitScope_Global, 0, scaled_volume, 0);
if (status != noErr) {
+ char errormsg[1024];
osx_os_status_to_cstring(status, errormsg, sizeof(errormsg));
throw FormatRuntimeError( "unable to set new volume %u: %s",
new_volume, errormsg);