Finally, it is easy to use RtAudio for simultaneous audio input/output, or duplex operation. In this example, we simply pass the input data back to the output.
int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
unsigned long *bytes = (unsigned long *) data;
memcpy( outputBuffer, inputBuffer, *bytes );
std::cout << "\nNo audio devices found!\n";
exit( 0 );
unsigned int bufferBytes, bufferFrames = 512;
( &oParams, &iParams, RTAUDIO_SINT32, 44100, &bufferFrames, &inout, (void
exit( 0 );
bufferBytes = bufferFrames * 2 * 4;
std::cout << "\nRunning ... press <enter> to quit.\n";
In this example, audio recorded by the stream input will be played out during the next round of audio processing.
Note that a duplex stream can make use of two different devices (except when using the Linux Jack and Windows ASIO APIs). However, this may cause timing problems due to possible device clock variations, unless a common external "sync" is provided.