Fix to initialize lastTickTimestamp when setting stream time.
[rtaudio-cdist.git] / RtAudio.cpp
index 91bd22165290c13c919f8b26d5de65fb9273877d..5d49366358f450fcfdf400206b31df22437e7673 100644 (file)
@@ -45,6 +45,7 @@
 #include <cstdlib>\r
 #include <cstring>\r
 #include <climits>\r
+#include <cmath>\r
 #include <algorithm>\r
 \r
 // Static variable definitions.\r
@@ -427,6 +428,9 @@ void RtApi :: setStreamTime( double time )
 \r
   if ( time >= 0.0 )\r
     stream_.streamTime = time;\r
+#if defined( HAVE_GETTIMEOFDAY )\r
+  gettimeofday( &stream_.lastTickTimestamp, NULL );\r
+#endif\r
 }\r
 \r
 unsigned int RtApi :: getStreamSampleRate( void )\r
@@ -3875,7 +3879,7 @@ void convertBufferWasapi( char* outBuffer,
   float sampleStep = 1.0f / sampleRatio;\r
   float inSampleFraction = 0.0f;\r
 \r
-  outSampleCount = ( unsigned int ) roundf( inSampleCount * sampleRatio );\r
+  outSampleCount = ( unsigned int ) std::roundf( inSampleCount * sampleRatio );\r
 \r
   // if inSampleRate is a multiple of outSampleRate (or vice versa) there's no need to interpolate\r
   if ( floor( sampleRatio ) == sampleRatio || floor( sampleRatioInv ) == sampleRatioInv )\r
@@ -5363,8 +5367,8 @@ RtApiDs :: RtApiDs()
 \r
 RtApiDs :: ~RtApiDs()\r
 {\r
-  if ( coInitialized_ ) CoUninitialize(); // balanced call.\r
   if ( stream_.state != STREAM_CLOSED ) closeStream();\r
+  if ( coInitialized_ ) CoUninitialize(); // balanced call.\r
 }\r
 \r
 // The DirectSound default output is always the first device.\r