double secondsPerHostByte; /* Used to optimize latency calculation for outTime */
PaStreamCallbackFlags callbackFlags;
+
+ HANDLE processingCompleted;
/* FIXME - move all below to PaUtilStreamRepresentation */
volatile int isStarted;
stream->timerID = 0;
+ stream->processingCompleted = CreateEvent( NULL, /* bManualReset = */ TRUE, /* bInitialState = */ FALSE, NULL );
+ if( stream->processingCompleted == NULL )
+ {
+ result = paInsufficientMemory;
+ goto error;
+ }
+
/* Get system minimum latency. */
minLatencyFrames = PaWinDs_GetMinLatencyFrames( sampleRate );
error:
if( stream )
+ {
+ if( stream->processingCompleted != NULL )
+ CloseHandle( stream->processingCompleted );
+
PaUtil_FreeMemory( stream );
+ }
return result;
}
{
if( stream->streamRepresentation.streamFinishedCallback != 0 )
stream->streamRepresentation.streamFinishedCallback( stream->streamRepresentation.userData );
+
+ SetEvent( stream->processingCompleted );
}
}
}
PaError result = paNoError;
PaWinDsStream *stream = (PaWinDsStream*)s;
+ CloseHandle( stream->processingCompleted );
+
// Cleanup the sound buffers
if( stream->pDirectSoundOutputBuffer )
{
PaUtil_ResetBufferProcessor( &stream->bufferProcessor );
+ ResetEvent( stream->processingCompleted );
+
if( stream->bufferProcessor.inputChannelCount > 0 )
{
// Start the buffer playback
else if( msecPerWakeup > 100 ) msecPerWakeup = 100;
resolution = msecPerWakeup/4;
stream->timerID = timeSetEvent( msecPerWakeup, resolution, (LPTIMECALLBACK) Pa_TimerCallback,
- (DWORD_PTR) stream, TIME_PERIODIC );
+ (DWORD_PTR) stream, TIME_PERIODIC | TIME_KILL_SYNCHRONOUS );
}
if( stream->timerID == 0 )
{
int timeoutMsec;
stream->stopProcessing = 1;
- /* Set timeout at 20% beyond maximum time we might wait. */
- timeoutMsec = (int) (1200.0 * stream->framesPerDSBuffer / stream->streamRepresentation.streamInfo.sampleRate);
- while( stream->isActive && (timeoutMsec > 0) )
- {
- Sleep(10);
- timeoutMsec -= 10;
- }
+
+ /* Set timeout at 4 times maximum time we might wait. */
+ timeoutMsec = (int) (4 * MSEC_PER_SECOND * (stream->framesPerDSBuffer / stream->streamRepresentation.streamInfo.sampleRate));
+
+ WaitForSingleObject( stream->processingCompleted, timeoutMsec );
+
if( stream->timerID != 0 )
{
timeKillEvent(stream->timerID); /* Stop callback timer. */