3

Please edvice by objective-c code snippets and useful links of how can I control all audio signals of output in OS X?

I think it should be something like proxy layer somewhere in OS X logic layers.

Thank you!

Eugenev
  • 45
  • 6

1 Answers1

4

It's somewhat sad that there is no simple API to do this. Luckily it isn't too hard, just verbose.

First, get the system output device:

UInt32 size;
AudioDeviceID outputDevice;
OSStatus result = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOuputDevice, &size, &outputDevice);

Then set the volume:

Float32 theVolume;
result = AudioDeviceSetProperty(theDevice, NULL, 0, /* master channel */ false, kAudioDevicePropertyVolumeScalar, sizeof(Float32), &theVolume);

Obviously I've omitted any error checking, which is a must.

Things can get a bit tricky because not all devices support channel 0 (the master channel). If this is the case with your device (it probably is) you have two options: query the device for its preferred stereo pair and set the volume on those channels individually, or just set the volume on channels 1 and 2.

sbooth
  • 16,646
  • 2
  • 55
  • 81
  • Hi sbooth, thank you very much! Thats a basic idea of getting mixer, i got it, but what about adjusting volume output of each **application**? Thank you! – Eugenev Feb 25 '11 at 04:14
  • That depends on how you are playing the sounds. Are you using NSSound, AUGraph, or something else? – sbooth Feb 25 '11 at 16:08
  • dear sbooth, I'm not playing sound, I just want to change the volume of sound (which sources are other apps). So I do not want to play sound, I want to know how to modify level volume of them. In best case I'd like to know how to control them, like DSP and VST but during run-time and over system sounds. Thank you very much! Appreciate your help very very much! – Eugenev Feb 26 '11 at 05:01
  • In that case, I don't think you'll be able to do this unless the specific applications that happen to be running support volume control through either AppleScript or some other API. OS X doesn't let you do this. – sbooth Feb 26 '11 at 16:39
  • 1
    Please note that `AudioHardwareGetProperty` is deprecated since 10.6. :-( – Entalpi May 09 '14 at 18:02