1 /*! \page duplex Duplex Mode
3 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.
11 // Pass-through function.
12 int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
13 double streamTime, RtAudioStreamStatus status, void *data )
15 // Since the number of input and output channels is equal, we can do
16 // a simple buffer copy operation here.
17 if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
19 unsigned long *bytes = (unsigned long *) data;
20 memcpy( outputBuffer, inputBuffer, *bytes );
27 if ( adac.getDeviceCount() < 1 ) {
28 std::cout << "\nNo audio devices found!\n";
32 // Set the same number of channels for both input and output.
33 unsigned int bufferBytes, bufferFrames = 512;
34 RtAudio::StreamParameters iParams, oParams;
35 iParams.deviceId = 0; // first available device
36 iParams.nChannels = 2;
37 oParams.deviceId = 0; // first available device
38 oParams.nChannels = 2;
41 adac.openStream( &oParams, &iParams, RTAUDIO_SINT32, 44100, &bufferFrames, &inout, (void *)&bufferBytes );
43 catch ( RtError& e ) {
48 bufferBytes = bufferFrames * 2 * 4;
54 std::cout << "\nRunning ... press <enter> to quit.\n";
60 catch ( RtError& e ) {
66 if ( adac.isStreamOpen() ) adac.closeStream();
72 In this example, audio recorded by the stream input will be played out during the next round of audio processing.
74 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.