Re: Change Volume on Default Output Device
Re: Change Volume on Default Output Device
- Subject: Re: Change Volume on Default Output Device
- From: Stephen Davis <email@hidden>
- Date: Tue, 26 Sep 2006 12:43:05 -0700
On Sep 26, 2006, at 12:10 PM, Doug Zwick wrote:
On 26-Sep-06, at 12:13 PM, Doug Zwick wrote:
On 26-Sep-06, at 12:00 PM, Jeff Moore wrote:
QA 1016 demonstrates manipulating a master volume control on a
device if one exists. This example is extended to the other
channels of a device by using a channel other than 0, which is
always the master channel.
Be aware that, as QA 1016 says, not every device has a master
volume control. The same is true of individual channel volume
controls. You have to be prepared to deal with them not being
present.
You should check out the HALLab sample code. It puts a slider up
for each volume control it finds on a device.
On Sep 26, 2006, at 10:47 AM, Doug Zwick wrote:
I'm converting some old Sound Manager code to use Core Audio.
I'm using the DefaultOutputUnit example as the basis for the
sound output code, and am using QA 1016 as the basis for
changing the device volume setting (setting the
kAudioDevicePropertyVolumeScalar property). However, this
technique changes the master system volume. In the old Sound
Manager code, changing the volume only changed the level of the
one channel, not the entire system volume. How does one go about
doing this in Core Audio? Can I still use the default output
device (I need to be able to specify the output sample rate, and
the default output device will automatically resample to the
native device rate for me)?
Thanks, I'll give that a try. I had code to change the numerically-
larger channels if-and-only-if channel zero failed. I will rework
this code. I suspect that I have a similar issue with the master
input channel gain (the same code is used for the input gain),
too, that I hadn't found yet.
I changed my code to leave channel zero alone, and only change 1
and 2 (presumably the left and right stereo channels). However,
this still changes the master system volume (as indicated by the
volume slider on the menu bar, and on the "Output" panel of the
"Sound" System Preferences. If I just change channel 1 or channel 2
the system-wide balance control (in System Preferences) is changed
(and the output volume, if the change is large enough). I have
verified that it is not setting the property for channel zero. The
default output device is set to "Line Out" "Build-in Audio" in the
System Preferences (the test system is a G4 MDD).
Perhaps I'm using the wrong device ID? I initialize like this
(error checks excluded for brevity):
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
comp = FindNextComponent(0, &desc);
err = OpenAComponent (comp, &unit);
dataLen = sizeof(devID);
err = AudioUnitGetProperty (unit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global, 0, &devID,
&dataLen);
Then I set the volume level using:
err = AudioDeviceSetProperty (devID, NULL, chx, 0,
kAudioDevicePropertyVolumeScalar,
sizeof(volume), &volume);
(volume is a Float32 in the range 0.0 to 1.0, devID is an
AudioDeviceID, chx is an int with a value of either 1 or 2, and
unit is an AudioUnit). I coded this to loop, starting and channel 1
and increasing the channel number until a non-zero return code is
received, as I do not have the actual channel count at that point.
If channel 1 returns a non-zero code, it tries setting the volume
on channel zero (to handle the case where the property is only
implemented for channel zero). I also cache the device ID (devID)
in a 32-bit integer Java field between initialization and volume
setting. Given that the channel ID is typedefed to a UInt32, this
seems safe.
Any suggestions?
I think you may have gotten off on the wrong foot. In your first
post, you said:
I'm converting some old Sound Manager code to use Core Audio. I'm
using the DefaultOutputUnit example as the basis for the sound
output code, and am using QA 1016 as the basis for changing the
device volume setting (setting the kAudioDevicePropertyVolumeScalar
property). However, this technique changes the master system
volume. In the old Sound Manager code, changing the volume only
changed the level of the one channel, not the entire system volume.
How does one go about doing this in Core Audio? Can I still use the
default output device (I need to be able to specify the output
sample rate, and the default output device will automatically
resample to the native device rate for me)?
The way I read this, you just want to change the volume level on the
audio you are sending to the DefaultOutputUnit. If this is indeed
the case, you just need to call:
float volume = 0.5f;
status = AudioUnitSetParameter( unit, kHALOutputParam_Volume,
kAudioUnitScope_Global, 0, volume, 0 );
This will only change the volume on the data you feed into the output
unit, it will not affect the master volume scalar on the device itself.
Just checking.
stephen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden