summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2019-04-05 15:47:28 -0400
committerGary Scavone <gary@music.mcgill.ca>2019-04-19 15:11:35 -0400
commit3619a028768e5f689aeaa49838f5216914d9163c (patch)
treeecd075867c48d8e1f3dc33d3bb773c55eed30d10
parentf385740a2797800d005534443467592fded18a5a (diff)
Updates to playsaw.cpp and testall.cpp for new behaviour
-rw-r--r--RtAudio.cpp18
-rw-r--r--tests/playsaw.cpp39
-rw-r--r--tests/testall.cpp10
3 files changed, 33 insertions, 34 deletions
diff --git a/RtAudio.cpp b/RtAudio.cpp
index f930114..fd8380b 100644
--- a/RtAudio.cpp
+++ b/RtAudio.cpp
@@ -1439,9 +1439,9 @@ bool RtApiCore :: probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
// Setup a listener to detect a possible device disconnect.
property.mSelector = kAudioDevicePropertyDeviceIsAlive;
- property.mScope = kAudioObjectPropertyScopeGlobal;
result = AudioObjectAddPropertyListener( id , &property, disconnectListener, (void *) &stream_.callbackInfo );
if ( result != noErr ) {
+ AudioObjectRemovePropertyListener( id, &property, xrunListener, (void *) handle );
errorStream_ << "RtApiCore::probeDeviceOpen: system error setting disconnect listener for device (" << device << ").";
errorText_ = errorStream_.str();
goto error;
@@ -1489,9 +1489,13 @@ void RtApiCore :: closeStream( void )
kAudioObjectPropertyElementMaster };
property.mSelector = kAudioDeviceProcessorOverload;
- property.mScope = kAudioObjectPropertyScopeGlobal;
if (AudioObjectRemovePropertyListener( handle->id[0], &property, xrunListener, (void *) handle ) != noErr) {
- errorText_ = "RtApiCore::closeStream(): error removing property listener!";
+ errorText_ = "RtApiCore::closeStream(): error removing xrun property listener!";
+ error( RtAudioError::WARNING );
+ }
+ property.mSelector = kAudioDevicePropertyDeviceIsAlive;
+ if (AudioObjectRemovePropertyListener( handle->id[0], &property, disconnectListener, (void *) &stream_.callbackInfo ) != noErr) {
+ errorText_ = "RtApiCore::closeStream(): error removing disconnect property listener!";
error( RtAudioError::WARNING );
}
}
@@ -1512,9 +1516,13 @@ void RtApiCore :: closeStream( void )
kAudioObjectPropertyElementMaster };
property.mSelector = kAudioDeviceProcessorOverload;
- property.mScope = kAudioObjectPropertyScopeGlobal;
if (AudioObjectRemovePropertyListener( handle->id[1], &property, xrunListener, (void *) handle ) != noErr) {
- errorText_ = "RtApiCore::closeStream(): error removing property listener!";
+ errorText_ = "RtApiCore::closeStream(): error removing xrun property listener!";
+ error( RtAudioError::WARNING );
+ }
+ property.mSelector = kAudioDevicePropertyDeviceIsAlive;
+ if (AudioObjectRemovePropertyListener( handle->id[1], &property, disconnectListener, (void *) &stream_.callbackInfo ) != noErr) {
+ errorText_ = "RtApiCore::closeStream(): error removing disconnect property listener!";
error( RtAudioError::WARNING );
}
}
diff --git a/tests/playsaw.cpp b/tests/playsaw.cpp
index 41c4e26..beaf714 100644
--- a/tests/playsaw.cpp
+++ b/tests/playsaw.cpp
@@ -68,11 +68,7 @@ void errorCallback( RtAudioError::Type /*type*/, const std::string &errorText )
{
// This example error handling function does exactly the same thing
// as the embedded RtAudio::error() function.
- std::cout << "in errorCallback" << std::endl;
- //if ( type == RtAudioError::WARNING )
- std::cerr << '\n' << errorText << "\n\n";
- //else if ( type != RtAudioError::WARNING )
- //throw( RtAudioError( errorText, type ) );
+ std::cerr << "\nerrorCallback: " << errorText << "\n\n";
}
unsigned int channels;
@@ -80,15 +76,15 @@ RtAudio::StreamOptions options;
unsigned int frameCounter = 0;
bool checkCount = false;
unsigned int nFrames = 0;
-const unsigned int callbackReturnValue = 2;
+const unsigned int callbackReturnValue = 1; // 1 = stop and drain, 2 = abort
double streamTimePrintIncrement = 1.0; // seconds
double streamTimePrintTime = 1.0; // seconds
-//#define USE_INTERLEAVED
+#define USE_INTERLEAVED
#if defined( USE_INTERLEAVED )
// Interleaved buffers
-int saw( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
+int saw( void *outputBuffer, void * /*inputBuffer*/, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *data )
{
unsigned int i, j;
@@ -194,15 +190,12 @@ int main( int argc, char *argv[] )
#if !defined( USE_INTERLEAVED )
options.flags |= RTAUDIO_NONINTERLEAVED;
#endif
- // try {
- dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options, &errorCallback );
- if ( dac.isStreamOpen() == false ) goto cleanup;
- dac.startStream();
- // }
- // catch ( RtAudioError& e ) {
- // e.printMessage();
- //goto cleanup;
- // }
+
+ dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options, &errorCallback );
+ if ( dac.isStreamOpen() == false ) goto cleanup;
+
+ // Stream is open ... now start it.
+ dac.startStream();
if ( checkCount ) {
while ( dac.isStreamRunning() == true ) SLEEP( 100 );
@@ -213,17 +206,9 @@ int main( int argc, char *argv[] )
std::cout << "\nPlaying ... press <enter> to quit (buffer size = " << bufferFrames << ").\n";
std::cin.get( input );
- //try {
- // Stop the stream
- dac.stopStream();
- //dac.abortStream();
- }
- /*
- catch ( RtAudioError& e ) {
- e.printMessage();
- }
+ // Block released ... stop the stream
+ dac.stopStream(); // or could call dac.abortStream();
}
- */
cleanup:
if ( dac.isStreamOpen() ) dac.closeStream();
diff --git a/tests/testall.cpp b/tests/testall.cpp
index b94ce69..cd6db44 100644
--- a/tests/testall.cpp
+++ b/tests/testall.cpp
@@ -133,10 +133,11 @@ int main( int argc, char *argv[] )
RtAudio::StreamOptions options;
options.flags = RTAUDIO_HOG_DEVICE;
- try {
+ //try {
dac.openStream( &oParams, NULL, RTAUDIO_FLOAT64, fs, &bufferFrames, &sawi, (void *)data, &options );
std::cout << "\nStream latency = " << dac.getStreamLatency() << std::endl;
+ if ( !dac.isStreamOpen() ) goto cleanup;
// Start the stream
dac.startStream();
std::cout << "\nPlaying ... press <enter> to stop.\n";
@@ -162,11 +163,13 @@ int main( int argc, char *argv[] )
std::cout << "Playing again ... press <enter> to close the stream.\n";
std::cin.get( input );
+ /*
}
catch ( RtAudioError& e ) {
e.printMessage();
goto cleanup;
}
+ */
if ( dac.isStreamOpen() ) dac.closeStream();
@@ -175,6 +178,8 @@ int main( int argc, char *argv[] )
try {
dac.openStream( &oParams, NULL, RTAUDIO_FLOAT64, fs, &bufferFrames, &sawni, (void *)data, &options );
+ if ( !dac.isStreamOpen() ) goto cleanup;
+
std::cout << "Press <enter> to start non-interleaved playback.\n";
std::cin.get( input );
@@ -200,7 +205,8 @@ int main( int argc, char *argv[] )
options.flags = RTAUDIO_NONINTERLEAVED;
try {
dac.openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
-
+ if ( !dac.isStreamOpen() ) goto cleanup;
+
bufferBytes = bufferFrames * channels * 4;
std::cout << "Press <enter> to start duplex operation.\n";