Skip to main content

Posts

Showing posts with the label audio

Set/get volume in OS X

How to get/set master volume in OS X. Many sample codes online use the deprecated API. This uses the currently 'legal' API. #include <CoreAudio/CoreAudio.h> #include <AudioToolbox/AudioToolbox.h> #include <AudioToolbox/AudioServices.h> #include <AppKit/AppKit.h> #include <CoreGraphics/CGEvent.h> static AudioDeviceID getDefaultOutputDeviceID() { AudioDeviceID outputDeviceID = kAudioObjectUnknown; // get output device device OSStatus status = noErr; AudioObjectPropertyAddress propertyAOPA; propertyAOPA.mScope = kAudioObjectPropertyScopeGlobal; propertyAOPA.mElement = kAudioObjectPropertyElementMaster; propertyAOPA.mSelector = kAudioHardwarePropertyDefaultOutputDevice; if (!AudioObjectHasProperty( kAudioObjectSystemObject, &propertyAOPA)) { printf("Cannot find default output device!"); return outputDeviceID; } status = AudioObjectGetPropert...