From 861b084aaae054d70e0f770a695359265c35e20c Mon Sep 17 00:00:00 2001 From: Michael Dickens Date: Thu, 17 Nov 2011 13:55:59 -0500 Subject: allow any input hardware audio rate; fix use of deprecated function 'AudioHardwareGetProperty' --- gr-audio/lib/osx/audio_osx_source.cc | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/gr-audio/lib/osx/audio_osx_source.cc b/gr-audio/lib/osx/audio_osx_source.cc index 61f8eb4a6..a6dd81908 100644 --- a/gr-audio/lib/osx/audio_osx_source.cc +++ b/gr-audio/lib/osx/audio_osx_source.cc @@ -300,7 +300,7 @@ audio_osx_source::audio_osx_source (int sample_rate, // get the max number of input (& thus output) channels supported by // this device - d_n_max_channels = asbd_client.mChannelsPerFrame; + d_n_max_channels = asbd_device.mChannelsPerFrame; // create the output io signature; // no input siganture to set (source is hardware) @@ -319,6 +319,31 @@ audio_osx_source::audio_osx_source (int sample_rate, d_deviceSampleRate = asbd_device.mSampleRate; d_n_deviceChannels = asbd_device.mChannelsPerFrame; + asbd_client.mChannelsPerFrame = d_n_deviceChannels; + asbd_client.mSampleRate = asbd_device.mSampleRate; + asbd_client.mFormatID = kAudioFormatLinearPCM; + asbd_client.mFormatFlags = (kAudioFormatFlagIsFloat | + kAudioFormatFlagIsPacked | + kAudioFormatFlagIsNonInterleaved); + if ((asbd_client.mFormatID == kAudioFormatLinearPCM) && + (d_n_deviceChannels == 1)) { + asbd_client.mFormatFlags &= ~kLinearPCMFormatFlagIsNonInterleaved; + } + asbd_client.mBitsPerChannel = 32; + asbd_client.mBytesPerFrame = asbd_client.mBitsPerChannel / 8; + asbd_client.mFramesPerPacket = 1; + asbd_client.mBytesPerPacket = asbd_client.mBytesPerFrame; + + propertySize = sizeof(AudioStreamBasicDescription); + err = AudioUnitSetProperty (d_InputAU, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Output, + 1, + &asbd_client, + propertySize); + CheckErrorAndThrow (err, "AudioUnitSetProperty Device Ouput Stream Format", + "audio_osx_source::audio_osx_source"); + // create an ASBD for the user's wants asbd_user.mSampleRate = d_outputSampleRate; @@ -914,17 +939,41 @@ audio_osx_source::SetDefaultInputDeviceAsCurrent () { // set the default input device - AudioDeviceID deviceID; + AudioDeviceID deviceID = 0; UInt32 dataSize = sizeof (AudioDeviceID); - AudioHardwareGetProperty (kAudioHardwarePropertyDefaultInputDevice, - &dataSize, - &deviceID); - OSStatus err = AudioUnitSetProperty (d_InputAU, - kAudioOutputUnitProperty_CurrentDevice, - kAudioUnitScope_Global, - 0, - &deviceID, - sizeof (AudioDeviceID)); + OSStatus err = noErr; + +#ifndef GR_USE_OLD_AUDIO_UNIT + AudioObjectPropertyAddress theAddress = + { kAudioHardwarePropertyDefaultInputDevice, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster }; + + err = AudioObjectGetPropertyData + (kAudioObjectSystemObject, + &theAddress, + 0, + NULL, + &dataSize, + &deviceID); +#else + err = AudioHardwareGetProperty + (kAudioHardwarePropertyDefaultInputDevice, + &dataSize, + &deviceID); +#endif + + CheckErrorAndThrow (err, "Get Audio Unit Property for Current Device", + "audio_osx_source::SetDefaultInputDeviceAsCurrent"); + + err = AudioUnitSetProperty + (d_InputAU, + kAudioOutputUnitProperty_CurrentDevice, + kAudioUnitScope_Global, + 0, + &deviceID, + sizeof (AudioDeviceID)); + CheckErrorAndThrow (err, "AudioUnitSetProperty Current Device", "audio_osx_source::SetDefaultInputDeviceAsCurrent"); } -- cgit From 12311ad384cd494bbab1a4ffb0b8699f28569e1b Mon Sep 17 00:00:00 2001 From: Michael L Dickens Date: Thu, 16 Feb 2012 11:57:22 -0500 Subject: small tweaks to get stream sizes "more correct" --- gr-audio/lib/osx/audio_osx_source.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gr-audio/lib/osx/audio_osx_source.cc b/gr-audio/lib/osx/audio_osx_source.cc index a6dd81908..6c5609d20 100644 --- a/gr-audio/lib/osx/audio_osx_source.cc +++ b/gr-audio/lib/osx/audio_osx_source.cc @@ -319,7 +319,6 @@ audio_osx_source::audio_osx_source (int sample_rate, d_deviceSampleRate = asbd_device.mSampleRate; d_n_deviceChannels = asbd_device.mChannelsPerFrame; - asbd_client.mChannelsPerFrame = d_n_deviceChannels; asbd_client.mSampleRate = asbd_device.mSampleRate; asbd_client.mFormatID = kAudioFormatLinearPCM; asbd_client.mFormatFlags = (kAudioFormatFlagIsFloat | @@ -329,9 +328,10 @@ audio_osx_source::audio_osx_source (int sample_rate, (d_n_deviceChannels == 1)) { asbd_client.mFormatFlags &= ~kLinearPCMFormatFlagIsNonInterleaved; } - asbd_client.mBitsPerChannel = 32; - asbd_client.mBytesPerFrame = asbd_client.mBitsPerChannel / 8; + asbd_client.mBytesPerFrame = sizeof (float); asbd_client.mFramesPerPacket = 1; + asbd_client.mBitsPerChannel = asbd_client.mBytesPerFrame * 8; + asbd_client.mChannelsPerFrame = d_n_deviceChannels; asbd_client.mBytesPerPacket = asbd_client.mBytesPerFrame; propertySize = sizeof(AudioStreamBasicDescription); @@ -352,11 +352,11 @@ audio_osx_source::audio_osx_source (int sample_rate, GR_PCM_ENDIANNESS | kLinearPCMFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved); - asbd_user.mBytesPerPacket = 4; + asbd_user.mBytesPerPacket = sizeof (float); asbd_user.mFramesPerPacket = 1; - asbd_user.mBytesPerFrame = 4; - asbd_user.mChannelsPerFrame = d_n_max_channels; - asbd_user.mBitsPerChannel = 32; + asbd_user.mBytesPerFrame = asbd_user.mBytesPerPacket; + asbd_user.mChannelsPerFrame = d_n_deviceChannels; + asbd_user.mBitsPerChannel = asbd_user.mBytesPerPacket * 8; if (d_deviceSampleRate == d_outputSampleRate) { // no need to do conversion if asbd_client matches user wants -- cgit