1 /******************************************/
4 by Gary P. Scavone, 2002.
6 Test executable using two streams with
9 /******************************************/
15 typedef signed long MY_TYPE;
16 #define FORMAT RtAudio::RTAUDIO_SINT24
17 #define SCALE 2147483647.0
20 #define FORMAT RtAudio::RTAUDIO_SINT8
23 typedef signed short MY_TYPE;
24 #define FORMAT RtAudio::RTAUDIO_SINT16
27 typedef signed long MY_TYPE;
28 #define FORMAT RtAudio::RTAUDIO_SINT32
29 #define SCALE 2147483647.0
31 typedef float MY_TYPE;
32 #define FORMAT RtAudio::RTAUDIO_FLOAT32
36 typedef double MY_TYPE;
37 #define FORMAT RtAudio::RTAUDIO_FLOAT64
39 #define BASE_RATE1 0.005
40 #define BASE_RATE2 0.004
43 /* Error function in case of incorrect command-line
44 argument specifications
46 cout << "\nuseage: call_twostreams N fs\n";
47 cout << " where N = number of channels,\n";
48 cout << " and fs = the sample rate.\n\n";
54 int saw1(char *buffer, int buffer_size, void *data)
58 MY_TYPE *my_buffer = (MY_TYPE *) buffer;
59 double *my_data = (double *) data;
61 for (i=0; i<buffer_size; i++) {
62 for (j=0; j<chans; j++) {
63 *my_buffer++ = (MY_TYPE) (my_data[j] * SCALE);
64 my_data[j] += BASE_RATE1 * (j+1+(j*0.1));
65 if (my_data[j] >= 1.0) my_data[j] -= 2.0;
72 int saw2(char *buffer, int buffer_size, void *data)
76 MY_TYPE *my_buffer = (MY_TYPE *) buffer;
77 double *my_data = (double *) data;
79 for (i=0; i<buffer_size; i++) {
80 for (j=0; j<chans; j++) {
81 *my_buffer++ = (MY_TYPE) (my_data[j] * SCALE);
82 my_data[j] += BASE_RATE2 * (j+1+(j*0.1));
83 if (my_data[j] >= 1.0) my_data[j] -= 2.0;
90 int main(int argc, char *argv[])
92 int device, buffer_size, stream1 = 0, stream2 = 0, fs;
98 // minimal command-line checking
99 if (argc != 3) usage();
101 chans = (int) atoi(argv[1]);
102 fs = (int) atoi(argv[2]);
104 // Open the realtime output device
106 device = 0; // default device
108 audio = new RtAudio();
115 stream1 = audio->openStream(device, chans, 0, 0,
116 FORMAT, fs, &buffer_size, 8);
117 stream2 = audio->openStream(device, chans, 0, 0,
118 FORMAT, fs, &buffer_size, 8);
124 data1 = (double *) calloc(chans, sizeof(double));
125 data2 = (double *) calloc(chans, sizeof(double));
128 audio->setStreamCallback(stream1, &saw1, (void *)data1);
129 audio->setStreamCallback(stream2, &saw2, (void *)data2);
130 audio->startStream(stream1);
131 audio->startStream(stream2);
137 cout << "\nRunning two streams ... press <enter> to quit.\n";
140 cout << "\nStopping both streams.\n";
142 audio->stopStream(stream1);
143 audio->stopStream(stream2);
149 cout << "\nPress <enter> to restart streams:\n";
153 audio->startStream(stream1);
154 audio->startStream(stream2);
160 cout << "\nRunning two streams (quasi-duplex) ... press <enter> to quit.\n";
164 audio->stopStream(stream1);
165 audio->stopStream(stream2);
171 audio->closeStream(stream1);
172 audio->closeStream(stream2);
174 if (data1) free(data1);
175 if (data2) free(data2);