Hades and Koegler patches for ALSA and general efficiency.
authorGary Scavone <gary@music.mcgill.ca>
Sat, 28 Dec 2013 00:09:21 +0000 (16:09 -0800)
committerGary Scavone <gary@music.mcgill.ca>
Sat, 28 Dec 2013 00:09:21 +0000 (16:09 -0800)
RtAudio.cpp
RtAudio.h
doc/release.txt

index baaf24eab340d848842091b94ce0dba1379627e6..1562e858629f6f92e0deea89bcaf6d180aa932d8 100644 (file)
@@ -213,6 +213,7 @@ RtApi :: RtApi()
   stream_.userBuffer[1] = 0;\r
   MUTEX_INITIALIZE( &stream_.mutex );\r
   showWarnings_ = true;\r
+  firstErrorOccurred = false;\r
 }\r
 \r
 RtApi :: ~RtApi()\r
@@ -6089,6 +6090,7 @@ void RtApiAlsa :: startStream()
   }\r
 \r
   if ( ( stream_.mode == INPUT || stream_.mode == DUPLEX ) && !apiInfo->synchronized ) {\r
+    result = snd_pcm_drop(handle[1]); // fix to remove stale data received since device has been open\r
     state = snd_pcm_state( handle[1] );\r
     if ( state != SND_PCM_STATE_PREPARED ) {\r
       result = snd_pcm_prepare( handle[1] );\r
@@ -6103,7 +6105,7 @@ void RtApiAlsa :: startStream()
   stream_.state = STREAM_RUNNING;\r
 \r
  unlock:\r
-  apiInfo->runnable = true;\r
+  apiInfo->runnable = false; // fixes high CPU usage when stopped\r
   pthread_cond_signal( &apiInfo->runnable_cv );\r
   MUTEX_UNLOCK( &stream_.mutex );\r
 \r
@@ -6148,6 +6150,7 @@ void RtApiAlsa :: stopStream()
   }\r
 \r
  unlock:\r
+  apiInfo->runnable = false; // fixes high CPU usage when stopped\r
   MUTEX_UNLOCK( &stream_.mutex );\r
 \r
   if ( result >= 0 ) return;\r
@@ -6891,7 +6894,7 @@ bool RtApiPulse::probeDeviceOpen( unsigned int device, StreamMode mode,
 #include <sys/ioctl.h>\r
 #include <unistd.h>\r
 #include <fcntl.h>\r
-#include "soundcard.h"\r
+#include <sys/soundcard.h>\r
 #include <errno.h>\r
 #include <math.h>\r
 \r
@@ -7837,12 +7840,11 @@ void RtApi :: error( RtAudioError::Type type )
   RtAudioErrorCallback errorCallback = (RtAudioErrorCallback) stream_.callbackInfo.errorCallback;\r
   if ( errorCallback ) {\r
     // abortStream() can generate new error messages. Ignore them. Just keep original one.\r
-    static bool firstErrorOccured = false;\r
 \r
-    if ( firstErrorOccured )\r
+    if ( firstErrorOccurred )\r
       return;\r
 \r
-    firstErrorOccured = true;\r
+    firstErrorOccurred = true;\r
     const std::string errorMessage = errorText_;\r
 \r
     if ( type != RtAudioError::WARNING && stream_.state != STREAM_STOPPED) {\r
@@ -7851,7 +7853,7 @@ void RtApi :: error( RtAudioError::Type type )
     }\r
 \r
     errorCallback( type, errorMessage );\r
-    firstErrorOccured = false;\r
+    firstErrorOccurred = false;\r
     return;\r
   }\r
 \r
index f640a3f375f3e0c615bf52a560bffd2c473bd06d..2be313da4fc8b76b2bc423500d9413821b008d8a 100644 (file)
--- a/RtAudio.h
+++ b/RtAudio.h
@@ -50,8 +50,7 @@
 #include <exception>
 #include <iostream>
 
-// RtAudio version
-static const std::string RTAUDIO_VERSION( "4.1.0pre" );
+// RtAudio version: 4.1.0pre
 
 /*! \typedef typedef unsigned long RtAudioFormat;
     \brief RtAudio data format type.
@@ -375,7 +374,7 @@ class RtAudio
   };
 
   //! A static function to determine the current RtAudio version.
-  static std::string getVersion( void ) { return RTAUDIO_VERSION; } 
+  static std::string getVersion( void ) { return "4.1.0"; } 
 
   //! A static function to determine the available compiled audio APIs.
   /*!
@@ -572,7 +571,7 @@ class RtAudio
   #include <windows.h>
   #include <process.h>
 
-  typedef unsigned long ThreadHandle;
+  typedef ULONG_PTR ThreadHandle;
   typedef CRITICAL_SECTION StreamMutex;
 
 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
@@ -762,6 +761,7 @@ protected:
   std::string errorText_;
   bool showWarnings_;
   RtApiStream stream_;
+  bool firstErrorOccurred;
 
   /*!
     Protected, api-specific method that attempts to open a device
index 7cbd9dfb4f70f83ac4813150f2aaa764e0f8ab83..839d6abc178a3a815c7e05952f674ad8c22c3e69 100644 (file)
@@ -4,6 +4,9 @@ By Gary P. Scavone, 2001-2014.
 
 v4.1.0: (?? 2014)
 - RtError class renamed RtAudioError and embedded in RtAudio.h (RtError.h deleted)
+- pulse audio update to support bufferFrames argument with audio input (thanks to Jonatan Wallmander)
+- fixes for ALSA API to avoid high CPU usage during stops and to clear stale data before input (thanks to Pluto Hades)
+- miscellaneous efficiency updates suggested by Martin Koegler
 
 v4.0.12: (16 April 2013)
 - new functionality to allow error reporting via a client-supplied function (thanks to Pavel Mogilevskiy)