Exemplo n.º 1
0
// ____________________________________________________________________________________
// get sample rate of the default input device
OSStatus	MyGetDefaultInputDeviceSampleRate(Float64 *outSampleRate)
{
	OSStatus err;
	AudioDeviceID deviceID = 0;

	// get the default input device
	AudioObjectPropertyAddress addr;
	UInt32 size;
	addr.mSelector = kAudioHardwarePropertyDefaultInputDevice;
	addr.mScope = kAudioObjectPropertyScopeGlobal;
	addr.mElement = 0;
	size = sizeof(AudioDeviceID);
#if USE_AUDIO_SERVICES
	err = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, &deviceID);
#else
	err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, &deviceID);
#endif
	if (err) return err;

	// get its sample rate
	addr.mSelector = kAudioDevicePropertyNominalSampleRate;
	addr.mScope = kAudioObjectPropertyScopeGlobal;
	addr.mElement = 0;
	size = sizeof(Float64);
#if USE_AUDIO_SERVICES
	err = AudioHardwareServiceGetPropertyData(deviceID, &addr, 0, NULL, &size, outSampleRate);
#else
	err = AudioObjectGetPropertyData(deviceID, &addr, 0, NULL, &size, outSampleRate);
#endif

	return err;
}
Exemplo n.º 2
0
AudioDeviceID defaultOutputDeviceID() {
  AudioDeviceID outputDeviceID = kAudioObjectUnknown;

  // get output device device
  UInt32 propertySize = 0;
  OSStatus status = noErr;
  AudioObjectPropertyAddress propertyAOPA;
  propertyAOPA.mScope = kAudioObjectPropertyScopeGlobal;
  propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
  propertyAOPA.mSelector = kAudioHardwarePropertyDefaultOutputDevice;

  if (!AudioHardwareServiceHasProperty(kAudioObjectSystemObject, &propertyAOPA)) {
    fprintf(stderr, "ERROR: Cannot find default output device!\n");
    return outputDeviceID;
  }

  propertySize = sizeof(AudioDeviceID);

  status = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAOPA, 0, NULL, &propertySize, &outputDeviceID);
  if (status) {
    fprintf(stderr, "ERROR: Cannot find default output device!\n");
  }
  
  return outputDeviceID;
}
Exemplo n.º 3
0
// static
OSStatus    BGMDeviceControlSync::AHSGetPropertyData(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32* ioDataSize, void* outData)
{
    // The docs for AudioHardwareServiceGetPropertyData specifically allow passing NULL for inQualifierData as we do here,
    // but it's declared in an assume_nonnull section so we have to disable the warning here. I'm not sure why inQualifierData
    // isn't __nullable. I'm assuming it's either a backwards compatibility thing or just a bug.
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wnonnull"
    // The non-depreciated version of this (and the setter below) doesn't seem to support devices other than the default
    return AudioHardwareServiceGetPropertyData(inObjectID, inAddress, 0, NULL, ioDataSize, outData);
    #pragma clang diagnostic pop
}
Exemplo n.º 4
0
OSStatus MyGetDefaultInputDeviceSampleRate(Float64 *outSampleRate)
{
	OSStatus error;

	AudioObjectPropertyAddress propertyAddress;
	UInt32 propertySize;
	propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
	propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
	propertyAddress.mElement = 0;
	propertySize = sizeof(AudioDeviceID);
	error = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, outSampleRate);
	return error;
}
Exemplo n.º 5
0
    bool isMuted()
    {
        UInt32 muted = 0;

        if (outputDeviceID != kAudioObjectUnknown)
        {
            UInt32 size = sizeof (muted);
            AudioHardwareServiceGetPropertyData (outputDeviceID, &addr,
                                                 0, nullptr, &size, &muted);
        }

        return muted != 0;
    }
Exemplo n.º 6
0
    float getGain()
    {
        Float32 gain = 0;

        if (outputDeviceID != kAudioObjectUnknown)
        {
            UInt32 size = sizeof (gain);
            AudioHardwareServiceGetPropertyData (outputDeviceID, &addr,
                                                 0, nullptr, &size, &gain);
        }

        return (float) gain;
    }
// get sample rate of the default input device
OSStatus MyGetDefaultInputDeviceSampleRate(Float64 *outSampleRate)
{
	OSStatus error;
	AudioDeviceID deviceID = 0;
	
	// get the default input device
	AudioObjectPropertyAddress propertyAddress;
	UInt32 propertySize;
	propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
	propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
	propertyAddress.mElement = 0;
	propertySize = sizeof(AudioDeviceID);
	error = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, &deviceID);
	if (error) return error;
	
	// get its sample rate
	propertyAddress.mSelector = kAudioDevicePropertyNominalSampleRate;
	propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
	propertyAddress.mElement = 0;
	propertySize = sizeof(Float64);
	error = AudioHardwareServiceGetPropertyData(deviceID, &propertyAddress, 0, NULL, &propertySize, outSampleRate);
	
	return error;
}
Exemplo n.º 8
0
    SystemVol (AudioObjectPropertySelector selector)
        : outputDeviceID (kAudioObjectUnknown)
    {
        addr.mScope    = kAudioObjectPropertyScopeGlobal;
        addr.mElement  = kAudioObjectPropertyElementMaster;
        addr.mSelector = kAudioHardwarePropertyDefaultOutputDevice;

        if (AudioHardwareServiceHasProperty (kAudioObjectSystemObject, &addr))
        {
            UInt32 deviceIDSize = sizeof (outputDeviceID);
            OSStatus status = AudioHardwareServiceGetPropertyData (kAudioObjectSystemObject, &addr, 0,
                                                                   nullptr, &deviceIDSize, &outputDeviceID);

            if (status == noErr)
            {
                addr.mElement  = kAudioObjectPropertyElementMaster;
                addr.mSelector = selector;
                addr.mScope    = kAudioDevicePropertyScopeOutput;

                if (! AudioHardwareServiceHasProperty (outputDeviceID, &addr))
                    outputDeviceID = kAudioObjectUnknown;
            }
        }
    }