summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2019-08-22 18:24:11 -0400
committerGary Scavone <gary@music.mcgill.ca>2019-08-22 18:24:11 -0400
commit10977977730415518802eb37c570af4ac18138de (patch)
treec721f72fd79b0d5043977f9c9ef6dbcfe2dac350 /tests
parente4b398ae9565d7680f5a2e8250a7d2d3fc9d4660 (diff)
Modified CoreAudio cleanup in case of error during initialization, fixed duplex streamtime bug for single device in CoreAudio, updated playsaw.cpp with interrupt handler instead of cin.get() function.
Diffstat (limited to 'tests')
-rw-r--r--tests/duplex.cpp31
-rw-r--r--tests/playsaw.cpp26
2 files changed, 31 insertions, 26 deletions
diff --git a/tests/duplex.cpp b/tests/duplex.cpp
index c5abc3b..33ab282 100644
--- a/tests/duplex.cpp
+++ b/tests/duplex.cpp
@@ -1,7 +1,7 @@
/******************************************/
/*
duplex.cpp
- by Gary P. Scavone, 2006-2007.
+ by Gary P. Scavone, 2006-2019.
This program opens a duplex stream and passes
input directly through to the output.
@@ -109,36 +109,29 @@ int main( int argc, char *argv[] )
iParams.deviceId = adac.getDefaultInputDevice();
if ( oDevice == 0 )
oParams.deviceId = adac.getDefaultOutputDevice();
-
+
RtAudio::StreamOptions options;
//options.flags |= RTAUDIO_NONINTERLEAVED;
bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
- try {
- adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
- }
- catch ( RtAudioError& e ) {
- std::cout << '\n' << e.getMessage() << '\n' << std::endl;
- exit( 1 );
+ if ( adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options ) ) {
+ goto cleanup;
}
+ if ( adac.isStreamOpen() == false ) goto cleanup;
+
// Test RtAudio functionality for reporting latency.
std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;
- try {
- adac.startStream();
+ if ( adac.startStream() ) goto cleanup;
- char input;
- std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
- std::cin.get(input);
+ char input;
+ std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
+ std::cin.get(input);
- // Stop the stream.
+ // Stop the stream.
+ if ( adac.isStreamRunning() )
adac.stopStream();
- }
- catch ( RtAudioError& e ) {
- std::cout << '\n' << e.getMessage() << '\n' << std::endl;
- goto cleanup;
- }
cleanup:
if ( adac.isStreamOpen() ) adac.closeStream();
diff --git a/tests/playsaw.cpp b/tests/playsaw.cpp
index f678d1e..a9c7891 100644
--- a/tests/playsaw.cpp
+++ b/tests/playsaw.cpp
@@ -1,7 +1,7 @@
/******************************************/
/*
playsaw.cpp
- by Gary P. Scavone, 2006
+ by Gary P. Scavone, 2006-2019.
This program will output sawtooth waveforms
of different frequencies on each channel.
@@ -11,6 +11,7 @@
#include "RtAudio.h"
#include <iostream>
#include <cstdlib>
+#include <signal.h>
/*
typedef char MY_TYPE;
@@ -49,6 +50,10 @@ typedef double MY_TYPE;
#define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
#endif
+// Interrupt handler function
+bool done;
+static void finish( int /*ignore*/ ){ done = true; }
+
#define BASE_RATE 0.005
#define TIME 1.0
@@ -173,8 +178,9 @@ int main( int argc, char *argv[] )
double *data = (double *) calloc( channels, sizeof( double ) );
- // Tell RtAudio to output all messages, even warnings.
//dac.setErrorCallback( &errorCallback ); // could use if not set via constructor
+
+ // Tell RtAudio to output all messages, even warnings.
dac.showWarnings( true );
// Set our stream parameters for output only.
@@ -200,6 +206,8 @@ int main( int argc, char *argv[] )
goto cleanup;
if ( dac.isStreamOpen() == false ) goto cleanup;
+ //std::cout << "Stream latency = " << dac.getStreamLatency() << "\n" << std::endl;
+
// Stream is open ... now start it.
if ( dac.startStream() ) goto cleanup;
@@ -207,13 +215,17 @@ int main( int argc, char *argv[] )
while ( dac.isStreamRunning() == true ) SLEEP( 100 );
}
else {
- char input;
- //std::cout << "Stream latency = " << dac.getStreamLatency() << "\n" << std::endl;
- std::cout << "\nPlaying ... press <enter> to quit (buffer size = " << bufferFrames << ").\n";
- std::cin.get( input );
+ std::cout << "\nPlaying ... quit with Ctrl-C (buffer size = " << bufferFrames << ").\n";
+
+ // Install an interrupt handler function.
+ done = false;
+ (void) signal(SIGINT, finish);
+
+ while ( !done && dac.isStreamRunning() ) SLEEP( 100 );
// Block released ... stop the stream
- dac.stopStream(); // or could call dac.abortStream();
+ if ( dac.isStreamRunning() )
+ dac.stopStream(); // or could call dac.abortStream();
}
cleanup: