OSStatus CAPlayThrough::SetInputDeviceAsCurrent(AudioDeviceID in) { UInt32 size = sizeof(AudioDeviceID); OSStatus err = noErr; if(in == kAudioDeviceUnknown) //get the default input device if device is unknown { err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &size, &in); checkErr(err); } mInputDevice.Init(in, true); //Set the Current Device to the AUHAL. //this should be done only after IO has been enabled on the AUHAL. err = AudioUnitSetProperty(mInputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &mInputDevice.mID, sizeof(mInputDevice.mID)); checkErr(err); return err; }
OSStatus CAPlayThrough::SetOutputDeviceAsCurrent(AudioDeviceID out) { UInt32 size = sizeof(AudioDeviceID);; OSStatus err = noErr; // UInt32 propsize = sizeof(Float32); //AudioObjectPropertyScope theScope = mIsInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; if(out == kAudioDeviceUnknown) //Retrieve the default output device { err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &out); checkErr(err); } mOutputDevice.Init(out, false); //Set the Current Device to the Default Output Unit. err = AudioUnitSetProperty(mOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &mOutputDevice.mID, sizeof(mOutputDevice.mID)); return err; }
OSStatus CAPlayThrough::SetOutputDeviceAsCurrent(AudioDeviceID out) { UInt32 size = sizeof(AudioDeviceID);; OSStatus err = noErr; if(out == kAudioDeviceUnknown) //Retrieve the default output device { err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &out); } mOutputDevice.Init(out, false); checkErr(err); //Set the Current Device to the Default Output Unit. err = AudioUnitSetProperty(mOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &mOutputDevice.mID, sizeof(mOutputDevice.mID)); return err; }