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 :
//---------------------------------------------------------------------------------- //
To get the list of devices, you follow these three
steps: //1. You get the size of the list. int
theSize;
OSStatus err; err =
AudioHardwareGetPropertyInfo
( kAudioHardwarePropertyDevices, &theSize,
NULL ); int theNumberDevices = 0; theNumberDevices =
theSize / sizeof(AudioDeviceID); //2. You allocate enough
space to hold the list. AudioDeviceID*
theDeviceList; theDeviceList = (AudioDeviceID*) malloc
( theNumberDevices * sizeof(AudioDeviceID)
); //3. You get the device list. err =
AudioHardwareGetProperty
( kAudioHardwarePropertyDevices, &theSize,
theDeviceList );
//4. Get the devices' name int
i; for(i = 0; i < theNumberDevices;
i++) { int iSizeName = 0;
AudioDeviceGetPropertyInfo( theDeviceList[i],
0,
false, kAudioDevicePropertyDeviceName, &iSizeName,
NULL);
char *cName = (char
*)malloc(iSizeName); err=
AudioDeviceGetProperty(theDeviceList[i], 0,
false, kAudioDevicePropertyDeviceName, &iSizeName,cName); int
t = 0; } // 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 ); // 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 } //----------------------------------------------------------------------------------
And the other question: What dose the 2ed param of
AudioDeviceGetProperty (idChannel) indicate?
How can i get&set this param?
Thanks advanced!
|