1 /******************************************/
4 by Gary P. Scavone, 2001
6 Records from default input. Takes
7 number of channels and sample rate
8 as input arguments. Uses blocking calls.
10 /******************************************/
17 #define FORMAT RtAudio::RTAUDIO_SINT8
19 typedef signed short MY_TYPE;
20 #define FORMAT RtAudio::RTAUDIO_SINT16
22 typedef signed long MY_TYPE;
23 #define FORMAT RtAudio::RTAUDIO_SINT24
25 typedef signed long MY_TYPE;
26 #define FORMAT RtAudio::RTAUDIO_SINT32
28 typedef float MY_TYPE;
29 #define FORMAT RtAudio::RTAUDIO_FLOAT32
32 typedef double MY_TYPE;
33 #define FORMAT RtAudio::RTAUDIO_FLOAT64
38 /* Error function in case of incorrect command-line
39 argument specifications
41 cout << "\nuseage: record_raw N fs\n";
42 cout << " where N = number of channels,\n";
43 cout << " and fs = the sample rate.\n\n";
47 int main(int argc, char *argv[])
49 int chans, fs, device, buffer_size, stream;
50 long frames, counter = 0;
55 // minimal command-line checking
56 if (argc != 3) usage();
58 chans = (int) atoi(argv[1]);
59 fs = (int) atoi(argv[2]);
61 // Open the realtime output device
63 device = 0; // default device
65 audio = new RtAudio(&stream, 0, 0, device, chans,
66 FORMAT, fs, &buffer_size, 8);
72 fd = fopen("test.raw","wb");
73 frames = (long) (fs * TIME);
76 buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
77 audio->startStream(stream);
83 cout << "\nRecording for " << TIME << " seconds ... writing file test.raw." << endl;
84 while (counter < frames) {
87 audio->tickStream(stream);
93 fwrite(buffer, sizeof(MY_TYPE), chans * buffer_size, fd);
94 counter += buffer_size;
98 audio->stopStream(stream);
104 audio->closeStream(stream);