mercredi 21 mai 2014

OSX - CoreAudio findout si le périphérique audio peut changer de volume - Stack Overflow


At the moment I'm looking for way to find out if audio device can be volume configured.


I tried to use kAudioDevicePropertyVolumeRangeDecibels property to get range and if min and max values are equal than confirm as unchangeable volume. But unfortunately i couldn't get that value at all.


AudioObjectPropertyAddress addr;
addr.mSelector = kAudioDevicePropertyVolumeRangeDecibels;
addr.mScope = kAudioDevicePropertyScopeOutput;
addr.mElement = kAudioDevicePropertyScopeOutput;

UInt32 size;
AudioValueRange range;

OSStatus status = AudioObjectGetPropertyDataSize(self.audioDeviceID, &addr, 0, NULL, &size);
if (status != noErr)
{
NSLog(@"error during size retrieval");
}else {
status = AudioObjectGetPropertyData(self.audioDeviceID, &addr, 0, NULL, &size, &range);
if (status != noErr)
{
NSLog(@"error during value retrieval");
}
}

All the time i get error during size retrieval. (all other data as volume, channels count and so on is retrieved correctly).


Thanks for any solutions.




I've accomplished this by checking whether the device supports the kAudioDevicePropertyVolumeScalar property. Some devices (but not many) support a master channel so first check kAudioObjectPropertyElementMaster. If this fails, check the individual channels you'd like to use:


AudioObjectPropertyAddress propertyAddress = { 
kAudioDevicePropertyVolumeScalar,
kAudioDevicePropertyScopeOutput,
kAudioObjectPropertyElementMaster
};

if(AudioObjectHasProperty(deviceID, &propertyAddress))
// YES

// Assume stereoChannels is a 2-deep array of the device's preferred stereo channels

propertyAddress.mElement = stereoChannels[0];
if(!AudioObjectHasProperty(deviceID, &propertyAddress))
// NO

propertyAddress.mElement = stereoChannels[1];
if(!AudioObjectHasProperty(deviceID, &propertyAddress))
// NO

// YES


At the moment I'm looking for way to find out if audio device can be volume configured.


I tried to use kAudioDevicePropertyVolumeRangeDecibels property to get range and if min and max values are equal than confirm as unchangeable volume. But unfortunately i couldn't get that value at all.


AudioObjectPropertyAddress addr;
addr.mSelector = kAudioDevicePropertyVolumeRangeDecibels;
addr.mScope = kAudioDevicePropertyScopeOutput;
addr.mElement = kAudioDevicePropertyScopeOutput;

UInt32 size;
AudioValueRange range;

OSStatus status = AudioObjectGetPropertyDataSize(self.audioDeviceID, &addr, 0, NULL, &size);
if (status != noErr)
{
NSLog(@"error during size retrieval");
}else {
status = AudioObjectGetPropertyData(self.audioDeviceID, &addr, 0, NULL, &size, &range);
if (status != noErr)
{
NSLog(@"error during value retrieval");
}
}

All the time i get error during size retrieval. (all other data as volume, channels count and so on is retrieved correctly).


Thanks for any solutions.



I've accomplished this by checking whether the device supports the kAudioDevicePropertyVolumeScalar property. Some devices (but not many) support a master channel so first check kAudioObjectPropertyElementMaster. If this fails, check the individual channels you'd like to use:


AudioObjectPropertyAddress propertyAddress = { 
kAudioDevicePropertyVolumeScalar,
kAudioDevicePropertyScopeOutput,
kAudioObjectPropertyElementMaster
};

if(AudioObjectHasProperty(deviceID, &propertyAddress))
// YES

// Assume stereoChannels is a 2-deep array of the device's preferred stereo channels

propertyAddress.mElement = stereoChannels[0];
if(!AudioObjectHasProperty(deviceID, &propertyAddress))
// NO

propertyAddress.mElement = stereoChannels[1];
if(!AudioObjectHasProperty(deviceID, &propertyAddress))
// NO

// YES

0 commentaires:

Enregistrer un commentaire