views:

44

answers:

0

I'm using AudioHardwareServiceSetPropertyData to set the master volume. I'm using the following:

AudioObjectPropertyAddress propertyAOPA;
propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
propertyAOPA.mScope = kAudioDevicePropertyScopeOutput;

The problem I'm facing now is that, the sound volume can be set properly in my app, with the appropriate sound balance intact. However, when I change the sound balance in sound preferences after my app has started up, then I set the volume using the AudiohardwareServiceSetPropertyData, the balance in sound preferences will jump back to the state it was before I changed it. Does anyone know why? I'm setting the volume via the following code, and to make it gradually reach the desired volume, I loop the volume setting to increment gradually.

AudioObjectPropertyAddress propertyAOPA;
propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
propertyAOPA.mScope = kAudioDevicePropertyScopeOutput;
propertyAOPA.mSelector = kAudioHardwareServiceDeviceProperty_VirtualMasterVolume; 
err = AudioHardwareServiceSetPropertyData([VolumeManager defaultOutputDeviceID], &propertyAOPA, 0, NULL, propertySize, &involume); 

...where propertySize is a UInt32 set to sizeof(Float32), involume is a Float32, and [VolumeManager defaultOutputDeviceID] gets me the device ID.