1 /******************************************/
4 by Gary P. Scavone, 2006-2007.
6 This program opens a duplex stream and passes
7 input directly through to the output.
9 /******************************************/
15 typedef signed long MY_TYPE;
16 #define FORMAT RTAUDIO_SINT24
19 #define FORMAT RTAUDIO_SINT8
21 typedef signed short MY_TYPE;
22 #define FORMAT RTAUDIO_SINT16
24 typedef signed long MY_TYPE;
25 #define FORMAT RTAUDIO_SINT32
27 typedef float MY_TYPE;
28 #define FORMAT RTAUDIO_FLOAT32
31 typedef double MY_TYPE;
32 #define FORMAT RTAUDIO_FLOAT64
35 // Error function in case of incorrect command-line
36 // argument specifications
37 std::cout << "\nuseage: duplex N fs <iDevice> <oDevice> <iChannelOffset> <oChannelOffset>\n";
38 std::cout << " where N = number of channels,\n";
39 std::cout << " fs = the sample rate,\n";
40 std::cout << " iDevice = optional input device to use (default = 0),\n";
41 std::cout << " oDevice = optional output device to use (default = 0),\n";
42 std::cout << " iChannelOffset = an optional input channel offset (default = 0),\n";
43 std::cout << " and oChannelOffset = optional output channel offset (default = 0).\n\n";
47 int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
48 double streamTime, RtAudioStreamStatus status, void *data )
50 // Since the number of input and output channels is equal, we can do
51 // a simple buffer copy operation here.
52 if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
54 unsigned long *bytes = (unsigned long *) data;
55 memcpy( outputBuffer, inputBuffer, *bytes );
59 int main( int argc, char *argv[] )
61 unsigned int channels, fs, bufferBytes, oDevice = 0, iDevice = 0, iOffset = 0, oOffset = 0;
63 // Minimal command-line checking
64 if (argc < 3 || argc > 7 ) usage();
67 if ( adac.getDeviceCount() < 1 ) {
68 std::cout << "\nNo audio devices found!\n";
72 channels = (unsigned int) atoi(argv[1]);
73 fs = (unsigned int) atoi(argv[2]);
75 iDevice = (unsigned int) atoi(argv[3]);
77 oDevice = (unsigned int) atoi(argv[4]);
79 iOffset = (unsigned int) atoi(argv[5]);
81 oOffset = (unsigned int) atoi(argv[6]);
83 // Let RtAudio print messages to stderr.
84 adac.showWarnings( true );
86 // Set the same number of channels for both input and output.
87 unsigned int bufferFrames = 512;
88 RtAudio::StreamParameters iParams, oParams;
89 iParams.deviceId = iDevice;
90 iParams.nChannels = channels;
91 iParams.firstChannel = iOffset;
92 oParams.deviceId = oDevice;
93 oParams.nChannels = channels;
94 oParams.firstChannel = oOffset;
96 RtAudio::StreamOptions options;
97 //options.flags |= RTAUDIO_NONINTERLEAVED;
100 adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
102 catch ( RtError& e ) {
103 std::cout << '\n' << e.getMessage() << '\n' << std::endl;
107 bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
109 // Test RtAudio functionality for reporting latency.
110 std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;
116 std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
122 catch ( RtError& e ) {
123 std::cout << '\n' << e.getMessage() << '\n' << std::endl;
128 if ( adac.isStreamOpen() ) adac.closeStream();