diff options
| author | Gary Scavone <gary@music.mcgill.ca> | 2019-08-22 18:24:11 -0400 |
|---|---|---|
| committer | Gary Scavone <gary@music.mcgill.ca> | 2019-08-22 18:24:11 -0400 |
| commit | 10977977730415518802eb37c570af4ac18138de (patch) | |
| tree | c721f72fd79b0d5043977f9c9ef6dbcfe2dac350 /tests/playsaw.cpp | |
| parent | e4b398ae9565d7680f5a2e8250a7d2d3fc9d4660 (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/playsaw.cpp')
| -rw-r--r-- | tests/playsaw.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
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: |
