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.
#include <iostream>
#include <cstdlib>
#include <cstring>
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 );
return 0;
}
int main()
{
std::cout << "\nNo audio devices found!\n";
exit( 0 );
}
unsigned int bufferBytes, bufferFrames = 512;
try {
adac.
openStream( &oParams, &iParams, RTAUDIO_SINT32, 44100, &bufferFrames, &inout, (
void *)&bufferBytes );
}
exit( 0 );
}
bufferBytes = bufferFrames * 2 * 4;
try {
char input;
std::cout << "\nRunning ... press <enter> to quit.\n";
std::cin.get(input);
}
goto cleanup;
}
cleanup:
return 0;
}
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.