Re: How to get/set microphone volume
Re: How to get/set microphone volume
- Subject: Re: How to get/set microphone volume
- From: Jeff Moore <email@hidden>
- Date: Wed, 21 Oct 2009 12:42:53 -0700
First off, you are using deprecated APIs. You should be using the
functions prefixed with AudioObject for this job. That would make the
code for getting the default device look something like this:
AudioObjectID GetDefaultInputDevice()
{
AudioObjectID theDefaultDeviceID = kAudioObjectUnknown;
AudioObjectPropertyAddress theDefaultDeviceAddress =
{ kAudioHardwarePropertyDefaultInputDevice,
kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
UInt32 theDefaultDeviceSize = sizeof(AudioObjectID);
OSStatus theError = AudioObjectGetPropertyData
(kAudioObjectSystemObject, &theDefaultDeviceAddress, 0, NULL,
&theDefaultDeviceSize, &theDefaultDeviceID);
return theDefaultDeviceID;
}
Then the code for getting the volume on the device would look
something like this:
Float32 GetVolume(AudioObjectID inDeviceID, Boolean inIsInput,
UInt32 inChannel)
{
Float32 theVolume = 0;
AudioObjectPropertyAddress theVolumeAddress =
{ kAudioDevicePropertyVolumeScalar, inIsInput ?
kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
inChannel };
UInt32 theVolumeSize = sizeof(Float32);
if(AudioObjectHasProperty(theDefaultDeviceID, &theVolumeAddress))
{
OSStatus theError = AudioObjectGetPropertyData(theDefaultDeviceID,
&theVolumeAddress, 0, NULL, &theVolumeSize, &theVolume);
}
return theVolume;
}
Note that this function will do the right thing for both input and
output, provided that the device in question has volume controls in
the given locations.
On Oct 19, 2009, at 7:06 PM, Symadept wrote:
I managed to get/set the earphone(output device) volume. Does
anybody know how to get the same for microphone(input device). I am
doing the following but still no result.
err = AudioHardwareGetProperty
(kAudioHardwarePropertyDefaultSystemInputDevice, &size, &device);
err = AudioDeviceGetProperty(107, 0, 0,
kAudioDevicePropertyVolumeScalar, &size, &b_vol);
err = AudioDeviceGetProperty(device, channels[0], 0,
kAudioDevicePropertyVolumeScalar, &size, &volume[0]);
err = AudioDeviceGetProperty(device, channels[1], 0,
kAudioDevicePropertyVolumeScalar, &size, &volume[1]);
b_vol = (volume[0]+volume[1])/2.00;
But no luck. It is always giving me the same value as output device.
This is becoz DeviceIds for Output and Input are the same.
--
Jeff Moore
Core Audio
Apple
_______________________________________________
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