Merge pull request #68 from jpcima/master
[rtaudio-cdist.git] / RtAudio.cpp
index fa365f76f2040f40a79b11fd3e6305750ef634d4..0b952f02ec8812c169d3eb17d1ca5c94ae151070 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
@@ -1943,7 +1947,7 @@ struct JackHandle {
 static void jackSilentError( const char * ) {};\r
 \r
 RtApiJack :: RtApiJack()\r
-{\r
+    :shouldAutoconnect_(true) {\r
   // Nothing to do here.\r
 #if !defined(__RTAUDIO_DEBUG__)\r
   // Turn off Jack's internal error reporting.\r
@@ -2354,6 +2358,8 @@ bool RtApiJack :: probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
   // here.\r
   if ( stream_.doConvertBuffer[mode] ) setConvertInfo( mode, 0 );\r
 \r
+  if ( options && options->flags & RTAUDIO_JACK_DONT_CONNECT ) shouldAutoconnect_ = false;\r
+\r
   return SUCCESS;\r
 \r
  error:\r
@@ -2443,7 +2449,7 @@ void RtApiJack :: startStream( void )
   const char **ports;\r
 \r
   // Get the list of available ports.\r
-  if ( stream_.mode == OUTPUT || stream_.mode == DUPLEX ) {\r
+  if ( shouldAutoconnect_ && (stream_.mode == OUTPUT || stream_.mode == DUPLEX) ) {\r
     result = 1;\r
     ports = jack_get_ports( handle->client, handle->deviceName[0].c_str(), NULL, JackPortIsInput);\r
     if ( ports == NULL) {\r
@@ -2467,7 +2473,7 @@ void RtApiJack :: startStream( void )
     free(ports);\r
   }\r
 \r
-  if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) {\r
+  if ( shouldAutoconnect_ && (stream_.mode == INPUT || stream_.mode == DUPLEX) ) {\r
     result = 1;\r
     ports = jack_get_ports( handle->client, handle->deviceName[1].c_str(), NULL, JackPortIsOutput );\r
     if ( ports == NULL) {\r
@@ -3875,7 +3881,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
@@ -5283,6 +5289,8 @@ Exit:
 // Various revisions for RtAudio 4.0 by Gary Scavone, April 2007\r
 // Changed device query structure for RtAudio 4.0.7, January 2010\r
 \r
+#include <mmsystem.h>\r
+#include <mmreg.h>\r
 #include <dsound.h>\r
 #include <assert.h>\r
 #include <algorithm>\r