Re: About AudioDeviceSetProperty
Re: About AudioDeviceSetProperty
- Subject: Re: About AudioDeviceSetProperty
- From: Derk-Jan Hartman <email@hidden>
- Date: Sat, 3 Dec 2005 18:56:54 +0100
On 3-dec-2005, at 4:04, aizhimin wrote:
Hi,
I want to get&set the input&output volume of a USB audio
device, This USB audio device was recognised by MAC OSX(MAC Mini),
and I can adjust it's Input&output volume in "System preferences".
But when I try to control it's valume in my programme, I meet err.
I don't know why and what should i do.I wrote code like this :
well, what error did you encounter ? where?
// To set the volume of a channel, you follow these steps:
// 1. You find out if output channel 2 has a volume control.
bool isWritable;
err = AudioDeviceGetPropertyInfo (
theDeviceList[1], 2, false, // theDeviceList[1]'s name =
"Generic USB Audio Device"
kAudioDevicePropertyVolumeScalar,
NULL, &isWritable );
Look in HALlab and see if the device allows to set volume per channel
first.
possibly it only allows it to do so on the master channel.
one thing to check.
// 2. If it does have a volume control, you set the value.
if ( (err == kAudioHardwareNoError)&& isWritable)
{
float theValue = 0.8;
err = AudioDeviceSetProperty (
theDeviceList[1], NULL, 2, false,
kAudioDevicePropertyVolumeScalar,
sizeof(float), &theValue ); // Sometimes the volume can be
changed, but sometimes nothing happend.
// I'm sure this code has been
executed every time
}
Ehm, so add NSLog of printfs or whatever. check what happens when.
print errors when stuff fails.
And the other question: What dose the 2ed param of
AudioDeviceGetProperty (idChannel) indicate?
How can i get&set this param?
The time at which the change should be executed. NULL means
immediatly. This is in the documentation my friend.
/*!
@function AudioDeviceSetProperty
@abstract Tells the AudioDevice object to change the value
of the given property using the
provided data.
@discussion Note that the value of the property should not
be considered changed until the
HAL has called the listeners as many properties
values are changed
asynchronously. Also note that the same
functionality is provided by the
function AudioObjectGetPropertyData().
@param inDevice
The AudioDevice to change.
@param inWhen
A pointer to an AudioTimeStamp that says
when to change the property's value
relative to the device's time base. NULL
means execute the change
immediately.
@param inChannel
The channel of the property to change where
0 is the master channel.
@param isInput
Which section of the AudioDevice to change.
@param inPropertyID
The AudioDevicePropertyID of the property to
change.
@param inPropertyDataSize
A UInt32 indicating the size of the buffer
pointed to by inData.
@param inPropertyData
The buffer containing the data to be used to
change the property's value.
@result An OSStatus indicating success or failure.
*/
Here is some code that deals with AudioDevices as well:
https://trac.videolan.org/vlc/file/trunk/modules/audio_output/auhal.c
See the Probe() function. You are welcome to look at that code.
DJ
_______________________________________________
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