return timeOut;
}
#endif
+
+
+/*******************************************************************/
+/* Attempt to set device sample rate. */
+static PaError PaHost_SetSampleRate( AudioDeviceID devID, Boolean isInput, double sampleRate )
+{
+ AudioStreamBasicDescription formatDesc;
+ OSStatus err;
+ memset( &formatDesc, 0, sizeof(AudioStreamBasicDescription) );
+ formatDesc.mSampleRate = sampleRate;
+ err = AudioDeviceSetProperty( devID, 0, 0,
+ isInput, kAudioDevicePropertyStreamFormat, sizeof(formatDesc), &formatDesc);
+
+ if (err != kAudioHardwareNoError) return paInvalidSampleRate;
+ else return paNoError;
+}
+
/*******************************************************************/
PaError PaHost_OpenInputStream( internalPortAudioStream *past )
{
}
hostDeviceInfo = &sDeviceInfos[past->past_InputDeviceID];
+ /* Try to set sample rate. */
+ result = PaHost_SetSampleRate( hostDeviceInfo->audioDeviceID, IS_INPUT, past->past_SampleRate );
+ if( result != paNoError ) return result;
+
if( past->past_NumInputChannels != hostDeviceInfo->paInfo.maxInputChannels )
{
#if 1
OSStatus err;
memset( &formatDesc, 0, sizeof(AudioStreamBasicDescription) );
formatDesc.mChannelsPerFrame = past->past_NumInputChannels;
- err = AudioDeviceSetProperty(pahsc->pahsc_AudioDeviceID, 0, 0,
+
+ err = AudioDeviceSetProperty( hostDeviceInfo->audioDeviceID, 0, 0,
IS_INPUT, kAudioDevicePropertyStreamFormat, sizeof(formatDesc), &formatDesc);
-
- if (err != kAudioHardwareNoError)
+ if (err != kAudioHardwareNoError)
{
result = paInvalidChannelCount;
goto error;
return paInvalidDeviceId;
}
hostDeviceInfo = &sDeviceInfos[past->past_OutputDeviceID];
-
+
+ /* Try to set sample rate. */
+ result = PaHost_SetSampleRate( hostDeviceInfo->audioDeviceID, IS_OUTPUT, past->past_SampleRate );
+ if( result != paNoError ) return result;
+
if( past->past_NumOutputChannels != hostDeviceInfo->paInfo.maxOutputChannels )
{
#if 1
OSStatus err;
memset( &formatDesc, 0, sizeof(AudioStreamBasicDescription) );
formatDesc.mChannelsPerFrame = past->past_NumOutputChannels;
- err = AudioDeviceSetProperty(pahsc->pahsc_AudioDeviceID, 0, 0,
+ err = AudioDeviceSetProperty( hostDeviceInfo->audioDeviceID, 0, 0,
IS_OUTPUT, kAudioDevicePropertyStreamFormat, sizeof(formatDesc), &formatDesc);
- if (err != kAudioHardwareNoError)
+ if (err != kAudioHardwareNoError)
{
result = paInvalidChannelCount;
goto error;
/* ------------------ OUTPUT */
if( (past->past_OutputDeviceID != paNoDevice) && (past->past_NumOutputChannels > 0) )
{
+ pahsc->pahsc_AudioDeviceID = sDeviceInfos[past->past_OutputDeviceID].audioDeviceID;
result = PaHost_OpenOutputStream( past );
if( result < 0 ) goto error;
- pahsc->pahsc_AudioDeviceID = sDeviceInfos[past->past_OutputDeviceID].audioDeviceID;
}
/* ------------------ INPUT */
if( (past->past_InputDeviceID != paNoDevice) && (past->past_NumInputChannels > 0) )
{
+ pahsc->pahsc_AudioDeviceID = sDeviceInfos[past->past_InputDeviceID].audioDeviceID;
result = PaHost_OpenInputStream( past );
if( result < 0 ) goto error;
- pahsc->pahsc_AudioDeviceID = sDeviceInfos[past->past_InputDeviceID].audioDeviceID;
- }
-
- /* Attempt to set device sample rate. */
- {
- AudioStreamBasicDescription formatDesc;
- OSStatus err;
- memset( &formatDesc, 0, sizeof(AudioStreamBasicDescription) );
- formatDesc.mSampleRate = past->past_SampleRate;
- err = AudioDeviceSetProperty(pahsc->pahsc_AudioDeviceID, 0, 0,
- IS_OUTPUT, kAudioDevicePropertyStreamFormat, sizeof(formatDesc), &formatDesc);
-
- if (err != kAudioHardwareNoError)
- {
- result = paInvalidSampleRate;
- goto error;
- }
}
return result;