summaryrefslogtreecommitdiff
path: root/doc/doxygen/duplex.txt
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2007-08-07 14:52:05 +0000
committerStephen Sinclair <sinclair@music.mcgill.ca>2013-10-11 01:19:40 +0200
commitb0080e69d64ce69e21c8ce1b22b1bb7f888f1e58 (patch)
treeb51ebcd31a5280b4f4e9e45484f07d9b35723743 /doc/doxygen/duplex.txt
parent0fbcd74a04713a4725d2f346a493121b623d60ab (diff)
Check in of new version 4.0.0 distribution (GS).
Diffstat (limited to 'doc/doxygen/duplex.txt')
-rw-r--r--doc/doxygen/duplex.txt74
1 files changed, 74 insertions, 0 deletions
diff --git a/doc/doxygen/duplex.txt b/doc/doxygen/duplex.txt
new file mode 100644
index 0000000..f060602
--- /dev/null
+++ b/doc/doxygen/duplex.txt
@@ -0,0 +1,74 @@
+/*! \page duplex Duplex Mode
+
+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.
+
+\code
+#include "RtAudio.h"
+#include <iostream>
+
+// Pass-through function.
+int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
+ double streamTime, RtAudioStreamStatus status, void *data )
+{
+ // Since the number of input and output channels is equal, we can do
+ // a simple buffer copy operation here.
+ if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
+
+ unsigned long *bytes = (unsigned long *) data;
+ memcpy( outputBuffer, inputBuffer, *bytes );
+ return 0;
+}
+
+int main()
+{
+ RtAudio adac;
+ if ( adac.getDeviceCount() < 1 ) {
+ std::cout << "\nNo audio devices found!\n";
+ exit( 0 );
+ }
+
+ // Set the same number of channels for both input and output.
+ unsigned int bufferBytes, bufferFrames = 512;
+ RtAudio::StreamParameters iParams, oParams;
+ iParams.deviceId = 0; // first available device
+ iParams.nChannels = 2;
+ oParams.deviceId = 0; // first available device
+ oParams.nChannels = 2;
+
+ try {
+ adac.openStream( &oParams, &iParams, RTAUDIO_SINT32, 44100, &bufferFrames, &inout, (void *)&bufferBytes );
+ }
+ catch ( RtError& e ) {
+ e.printMessage();
+ exit( 0 );
+ }
+
+ bufferBytes = bufferFrames * 2 * 4;
+
+ try {
+ adac.startStream();
+
+ char input;
+ std::cout << "\nRunning ... press <enter> to quit.\n";
+ std::cin.get(input);
+
+ // Stop the stream.
+ adac.stopStream();
+ }
+ catch ( RtError& e ) {
+ e.printMessage();
+ goto cleanup;
+ }
+
+ cleanup:
+ if ( adac.isStreamOpen() ) adac.closeStream();
+
+ return 0;
+}
+\endcode
+
+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.
+
+*/