Fixed shutdown crash on certain sample rates
authorMarcus Tomlinson <themarcustomlinson@gmail.com>
Fri, 18 Apr 2014 14:02:56 +0000 (16:02 +0200)
committerMarcus Tomlinson <themarcustomlinson@gmail.com>
Fri, 18 Apr 2014 14:02:56 +0000 (16:02 +0200)
RtAudio.cpp

index 3bd001a2eb070725cc8b5e5ba1cbfb37ab418734..44cf4edb497d3743594f56a349693a6e1f83a23f 100644 (file)
@@ -4626,7 +4626,8 @@ void RtApiWasapi::wasapiThread()
 \r
   // convBuffer is used to store converted buffers between WASAPI and the user\r
   char* convBuffer = NULL;\r
-  unsigned int deviceBufferSize = 0;\r
+  unsigned int convBuffSize = 0;\r
+  unsigned int deviceBuffSize = 0;\r
 \r
   errorText_.clear();\r
   RtAudioError::Type errorType = RtAudioError::DRIVER_ERROR;\r
@@ -4801,18 +4802,22 @@ void RtApiWasapi::wasapiThread()
   }\r
 \r
   if ( stream_.mode == INPUT ) {\r
-    deviceBufferSize = ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] );\r
+    convBuffSize = ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] );\r
+    deviceBuffSize = stream_.bufferSize * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] );\r
   }\r
   else if ( stream_.mode == OUTPUT ) {\r
-    deviceBufferSize = ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] );\r
+    convBuffSize = ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] );\r
+    deviceBuffSize = stream_.bufferSize * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] );\r
   }\r
   else if ( stream_.mode == DUPLEX ) {\r
-    deviceBufferSize = std::max( ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ),\r
-                            ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ) );\r
+    convBuffSize = std::max( ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ),\r
+                             ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ) );\r
+    deviceBuffSize = std::max( stream_.bufferSize * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ),\r
+                               stream_.bufferSize * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ) );\r
   }\r
 \r
-  convBuffer = ( char* ) malloc( deviceBufferSize );\r
-  stream_.deviceBuffer = ( char* ) malloc( deviceBufferSize );\r
+  convBuffer = ( char* ) malloc( convBuffSize );\r
+  stream_.deviceBuffer = ( char* ) malloc( deviceBuffSize );\r
   if ( !convBuffer || !stream_.deviceBuffer ) {\r
     errorType = RtAudioError::MEMORY_ERROR;\r
     errorText_ = "RtApiWasapi::wasapiThread: Error allocating device buffer memory.";\r