errorText_ = "RtApiCore::closeStream(): error removing property listener!";
error( RtAudioError::WARNING );
}
- }
- if ( stream_.state == STREAM_RUNNING ) {
+
#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
- AudioDeviceStop( handle->id[0], handle->procId[0] );
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[0], handle->procId[0] );
AudioDeviceDestroyIOProcID( handle->id[0], handle->procId[0] );
#else // deprecated behaviour
- AudioDeviceStop( handle->id[0], callbackHandler );
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[0], callbackHandler );
AudioDeviceRemoveIOProc( handle->id[0], callbackHandler );
#endif
}
errorText_ = "RtApiCore::closeStream(): error removing property listener!";
error( RtAudioError::WARNING );
}
- }
- if ( stream_.state == STREAM_RUNNING ) {
+
#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
- AudioDeviceStop( handle->id[1], handle->procId[1] );
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[1], handle->procId[1] );
AudioDeviceDestroyIOProcID( handle->id[1], handle->procId[1] );
#else // deprecated behaviour
- AudioDeviceStop( handle->id[1], callbackHandler );
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[1], callbackHandler );
AudioDeviceRemoveIOProc( handle->id[1], callbackHandler );
#endif
}
#endif
}
- void Convert( char* outBuffer, const char* inBuffer, unsigned int inSampleCount, unsigned int& outSampleCount )
+ void Convert( char* outBuffer, const char* inBuffer, unsigned int inSampleCount, unsigned int& outSampleCount, int maxOutSampleCount = -1 )
{
unsigned int inputBufferSize = _bytesPerSample * _channelCount * inSampleCount;
if ( _sampleRatio == 1 )
return;
}
- unsigned int outputBufferSize = ( unsigned int ) ceilf( inputBufferSize * _sampleRatio ) + ( _bytesPerSample * _channelCount );
+ unsigned int outputBufferSize = 0;
+ if ( maxOutSampleCount != -1 )
+ {
+ outputBufferSize = _bytesPerSample * _channelCount * maxOutSampleCount;
+ }
+ else
+ {
+ outputBufferSize = ( unsigned int ) ceilf( inputBufferSize * _sampleRatio ) + ( _bytesPerSample * _channelCount );
+ }
IMFMediaBuffer* rInBuffer;
IMFSample* rInSample;
if ( captureAudioClient )
{
int samplesToPull = ( unsigned int ) floorf( stream_.bufferSize * captureSrRatio );
- if ( captureSrRatio != 1 )
- {
- // account for remainders
- samplesToPull--;
- }
convBufferSize = 0;
while ( convBufferSize < stream_.bufferSize )
captureResampler->Convert( stream_.deviceBuffer + deviceBufferOffset,
convBuffer,
samplesToPull,
- convSamples );
+ convSamples,
+ convBufferSize == 0 ? -1 : stream_.bufferSize - convBufferSize );
convBufferSize += convSamples;
samplesToPull = 1; // now pull one sample at a time until we have stream_.bufferSize samples
stream_.state = STREAM_STOPPED;
MUTEX_LOCK( &stream_.mutex );
- if ( pah && pah->s_play ) {
- int pa_error;
- if ( pa_simple_drain( pah->s_play, &pa_error ) < 0 ) {
- errorStream_ << "RtApiPulse::stopStream: error draining output device, " <<
- pa_strerror( pa_error ) << ".";
- errorText_ = errorStream_.str();
- MUTEX_UNLOCK( &stream_.mutex );
- error( RtAudioError::SYSTEM_ERROR );
- return;
+ if ( pah ) {
+ pah->runnable = false;
+ if ( pah->s_play ) {
+ int pa_error;
+ if ( pa_simple_drain( pah->s_play, &pa_error ) < 0 ) {
+ errorStream_ << "RtApiPulse::stopStream: error draining output device, " <<
+ pa_strerror( pa_error ) << ".";
+ errorText_ = errorStream_.str();
+ MUTEX_UNLOCK( &stream_.mutex );
+ error( RtAudioError::SYSTEM_ERROR );
+ return;
+ }
}
}
stream_.state = STREAM_STOPPED;
MUTEX_LOCK( &stream_.mutex );
- if ( pah && pah->s_play ) {
- int pa_error;
- if ( pa_simple_flush( pah->s_play, &pa_error ) < 0 ) {
- errorStream_ << "RtApiPulse::abortStream: error flushing output device, " <<
- pa_strerror( pa_error ) << ".";
- errorText_ = errorStream_.str();
- MUTEX_UNLOCK( &stream_.mutex );
- error( RtAudioError::SYSTEM_ERROR );
- return;
+ if ( pah ) {
+ pah->runnable = false;
+ if ( pah->s_play ) {
+ int pa_error;
+ if ( pa_simple_flush( pah->s_play, &pa_error ) < 0 ) {
+ errorStream_ << "RtApiPulse::abortStream: error flushing output device, " <<
+ pa_strerror( pa_error ) << ".";
+ errorText_ = errorStream_.str();
+ MUTEX_UNLOCK( &stream_.mutex );
+ error( RtAudioError::SYSTEM_ERROR );
+ return;
+ }
}
}