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 /******************************************/
17 typedef signed long MY_TYPE;
18 #define FORMAT RTAUDIO_SINT24
21 #define FORMAT RTAUDIO_SINT8
23 typedef signed short MY_TYPE;
24 #define FORMAT RTAUDIO_SINT16
26 typedef signed long MY_TYPE;
27 #define FORMAT RTAUDIO_SINT32
29 typedef float MY_TYPE;
30 #define FORMAT RTAUDIO_FLOAT32
33 typedef double MY_TYPE;
34 #define FORMAT RTAUDIO_FLOAT64
37 // Error function in case of incorrect command-line
38 // argument specifications
39 std::cout << "\nuseage: duplex N fs <iDevice> <oDevice> <iChannelOffset> <oChannelOffset>\n";
40 std::cout << " where N = number of channels,\n";
41 std::cout << " fs = the sample rate,\n";
42 std::cout << " iDevice = optional input device to use (default = 0),\n";
43 std::cout << " oDevice = optional output device to use (default = 0),\n";
44 std::cout << " iChannelOffset = an optional input channel offset (default = 0),\n";
45 std::cout << " and oChannelOffset = optional output channel offset (default = 0).\n\n";
49 int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
50 double streamTime, RtAudioStreamStatus status, void *data )
52 // Since the number of input and output channels is equal, we can do
53 // a simple buffer copy operation here.
54 if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
56 unsigned long *bytes = (unsigned long *) data;
57 memcpy( outputBuffer, inputBuffer, *bytes );
61 int main( int argc, char *argv[] )
63 unsigned int channels, fs, bufferBytes, oDevice = 0, iDevice = 0, iOffset = 0, oOffset = 0;
65 // Minimal command-line checking
66 if (argc < 3 || argc > 7 ) usage();
69 if ( adac.getDeviceCount() < 1 ) {
70 std::cout << "\nNo audio devices found!\n";
74 channels = (unsigned int) atoi(argv[1]);
75 fs = (unsigned int) atoi(argv[2]);
77 iDevice = (unsigned int) atoi(argv[3]);
79 oDevice = (unsigned int) atoi(argv[4]);
81 iOffset = (unsigned int) atoi(argv[5]);
83 oOffset = (unsigned int) atoi(argv[6]);
85 // Let RtAudio print messages to stderr.
86 adac.showWarnings( true );
88 // Set the same number of channels for both input and output.
89 unsigned int bufferFrames = 512;
90 RtAudio::StreamParameters iParams, oParams;
91 iParams.deviceId = iDevice;
92 iParams.nChannels = channels;
93 iParams.firstChannel = iOffset;
94 oParams.deviceId = oDevice;
95 oParams.nChannels = channels;
96 oParams.firstChannel = oOffset;
98 RtAudio::StreamOptions options;
99 //options.flags |= RTAUDIO_NONINTERLEAVED;
102 adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
104 catch ( RtError& e ) {
105 std::cout << '\n' << e.getMessage() << '\n' << std::endl;
109 bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
111 // Test RtAudio functionality for reporting latency.
112 std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;
118 std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
124 catch ( RtError& e ) {
125 std::cout << '\n' << e.getMessage() << '\n' << std::endl;
130 if ( adac.isStreamOpen() ) adac.closeStream();