summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2019-08-27 20:28:49 -0400
committerGary Scavone <gary@music.mcgill.ca>2019-08-27 20:28:49 -0400
commitcfef06a89de8615490034979f49696b74a1f1691 (patch)
treebbf47a1bcf8f489b79ee7c5c23b28b70b4bfe223
parentf2244e394dc2873abc4de1864d215ccab2b15e08 (diff)
CoreAudio fix for deprecated behaviour in stopping and starting stream, which allows multiple instances of RtAudio accessing the same device.
-rw-r--r--RtAudio.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/RtAudio.cpp b/RtAudio.cpp
index 9b2a972..3793d63 100644
--- a/RtAudio.cpp
+++ b/RtAudio.cpp
@@ -1486,16 +1486,18 @@ void RtApiCore :: closeStream( void )
}
}
- if ( stream_.state == STREAM_RUNNING )
- AudioDeviceStop( handle->id[0], callbackHandler );
-
#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
- if ( handle->procId[0] )
+ if ( handle->procId[0] ) {
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[0], handle-procId[0] );
AudioDeviceDestroyIOProcID( handle->id[0], handle->procId[0] );
-#else
- // deprecated in favor of AudioDeviceDestroyIOProcID()
+ }
+#else // deprecated behaviour
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[0], callbackHandler );
AudioDeviceRemoveIOProc( handle->id[0], callbackHandler );
#endif
+ }
}
}
@@ -1520,17 +1522,19 @@ void RtApiCore :: closeStream( void )
error( RTAUDIO_WARNING );
}
}
- }
- if ( stream_.state == STREAM_RUNNING )
- AudioDeviceStop( handle->id[1], callbackHandler );
#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
- if ( handle->procId[1] )
- AudioDeviceDestroyIOProcID( handle->id[1], handle->procId[1] );
-#else
- // deprecated in favor of AudioDeviceDestroyIOProcID()
- AudioDeviceRemoveIOProc( handle->id[1], callbackHandler );
+ if ( handle->procId[1] ) {
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[1], handle->procId[1] );
+ AudioDeviceDestroyIOProcID( handle->id[1], handle->procId[1] );
+ }
+#else // deprecated behaviour
+ if ( stream_.state == STREAM_RUNNING )
+ AudioDeviceStop( handle->id[1], callbackHandler );
+ AudioDeviceRemoveIOProc( handle->id[1], callbackHandler );
#endif
+ }
}
for ( int i=0; i<2; i++ ) {
@@ -1582,7 +1586,11 @@ RtAudioErrorType RtApiCore :: startStream( void )
CoreHandle *handle = (CoreHandle *) stream_.apiHandle;
if ( stream_.mode == OUTPUT || stream_.mode == DUPLEX ) {
- result = AudioDeviceStart( handle->id[0], callbackHandler );
+#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
+ result = AudioDeviceStart( handle->id[0], handle->procId[0] );
+#else // deprecated behaviour
+ result = AudioDeviceStart( handle->id[0], callbackHandler );
+#endif
if ( result != noErr ) {
errorStream_ << "RtApiCore::startStream: system error (" << getErrorCode( result ) << ") starting callback procedure on device (" << stream_.device[0] << ").";
errorText_ = errorStream_.str();
@@ -1598,7 +1606,11 @@ RtAudioErrorType RtApiCore :: startStream( void )
bufferBytes = stream_.nUserChannels[1] * stream_.bufferSize * formatBytes( stream_.userFormat );
memset( stream_.userBuffer[1], 0, bufferBytes * sizeof(char) );
+#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
+ result = AudioDeviceStart( handle->id[1], handle->procId[1] );
+#else // deprecated behaviour
result = AudioDeviceStart( handle->id[1], callbackHandler );
+#endif
if ( result != noErr ) {
errorStream_ << "RtApiCore::startStream: system error starting input callback procedure on device (" << stream_.device[1] << ").";
errorText_ = errorStream_.str();
@@ -1634,7 +1646,11 @@ RtAudioErrorType RtApiCore :: stopStream( void )
pthread_cond_wait( &handle->condition, &stream_.mutex ); // block until signaled
}
+#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
+ result = AudioDeviceStop( handle->id[0], handle->procId[0] );
+#else
result = AudioDeviceStop( handle->id[0], callbackHandler );
+#endif
if ( result != noErr ) {
errorStream_ << "RtApiCore::stopStream: system error (" << getErrorCode( result ) << ") stopping callback procedure on device (" << stream_.device[0] << ").";
errorText_ = errorStream_.str();
@@ -1643,8 +1659,11 @@ RtAudioErrorType RtApiCore :: stopStream( void )
}
if ( stream_.mode == INPUT || ( stream_.mode == DUPLEX && stream_.device[0] != stream_.device[1] ) ) {
-
+#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
+ result = AudioDeviceStop( handle->id[1], handle->procId[1] );
+#else
result = AudioDeviceStop( handle->id[1], callbackHandler );
+#endif
if ( result != noErr ) {
errorStream_ << "RtApiCore::stopStream: system error (" << getErrorCode( result ) << ") stopping input callback procedure on device (" << stream_.device[1] << ").";
errorText_ = errorStream_.str();