[Stk] [Spam] endless loop RTAudio.cpp

Pavel Nikitenko pavn at centrum.cz
Fri Jan 16 04:37:11 PST 2009


Hi all!

I am using RTAudio with Direct Sound API on Windows XP.

The API works quite good. But very occasionally, I observe that 
sometimes it freezes when I try to abort the playback stream with
rtAudio.abortStream().

When I brake the application run with Visual Studio, it looks like it is 
in the endless loop in this code in:
 Sleep( (DWORD) millis ); line 4474 of RTAudio.cpp version 4.0.4.

Endless loop code:

    DWORD endWrite;
    while ( true ) {
      // Find out where the read and "safe write" pointers are.
      result = dsBuffer->GetCurrentPosition( &currentWritePos, 
&safeWritePos );
      if ( FAILED( result ) ) {
        errorStream_ << "RtApiDs::callbackEvent: error (" << 
getErrorString( result ) << ") getting current write position!";
        errorText_ = errorStream_.str();
        error( RtError::SYSTEM_ERROR );
      }

      leadPos = safeWritePos + handle->dsPointerLeadTime[0];
      if ( leadPos > dsBufferSize ) leadPos -= dsBufferSize;
      if ( leadPos < nextWritePos ) leadPos += dsBufferSize; // unwrap 
offset
      endWrite = nextWritePos + bufferBytes;

      // Check whether the entire write region is behind the play pointer.
      if ( leadPos >= endWrite ) break;

      // If we are here, then we must wait until the play pointer gets
      // beyond the write region.  The approach here is to use the
      // Sleep() function to suspend operation until safePos catches
      // up. Calculate number of milliseconds to wait as:
      //   time = distance * (milliseconds/second) * fudgefactor /
      //          ((bytes/sample) * (samples/second))
      // A "fudgefactor" less than 1 is used because it was found
      // that sleeping too long was MUCH worse than sleeping for
      // several shorter periods.
      double millis = ( endWrite - leadPos ) * 900.0;
      millis /= ( formatBytes( stream_.deviceFormat[0]) * 
stream_.nDeviceChannels[0] * stream_.sampleRate);
      if ( millis < 1.0 ) millis = 1.0;
      if ( millis > 50.0 ) {
        static int nOverruns = 0;
        ++nOverruns;
      }
      Sleep( (DWORD) millis );
    }

It looks like:
      if ( leadPos >= endWrite ) break;

is not true to be able to break the loop.

Could somebody help?

Thanks in advance.

Best Regards,

Pavel N.



More information about the Stk mailing list