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 /******************************************/
18 #define FORMAT RtAudio::RTAUDIO_SINT8
20 typedef signed short MY_TYPE;
21 #define FORMAT RtAudio::RTAUDIO_SINT16
23 typedef signed long MY_TYPE;
24 #define FORMAT RtAudio::RTAUDIO_SINT24
26 typedef signed long MY_TYPE;
27 #define FORMAT RtAudio::RTAUDIO_SINT32
29 typedef float MY_TYPE;
30 #define FORMAT RtAudio::RTAUDIO_FLOAT32
33 typedef double MY_TYPE;
34 #define FORMAT RtAudio::RTAUDIO_FLOAT64
39 /* Error function in case of incorrect command-line
40 argument specifications
42 cout << "\nuseage: record_raw N fs\n";
43 cout << " where N = number of channels,\n";
44 cout << " and fs = the sample rate.\n\n";
48 int main(int argc, char *argv[])
50 int chans, fs, device, buffer_size, stream;
51 long frames, counter = 0;
56 // minimal command-line checking
57 if (argc != 3) usage();
59 chans = (int) atoi(argv[1]);
60 fs = (int) atoi(argv[2]);
62 // Open the realtime output device
64 device = 0; // default device
66 audio = new RtAudio(&stream, 0, 0, device, chans,
67 FORMAT, fs, &buffer_size, 8);
69 catch (RtAudioError &m) {
74 fd = fopen("test.raw","wb");
75 frames = (long) (fs * TIME);
78 buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
79 audio->startStream(stream);
81 catch (RtAudioError &m) {
86 cout << "\nRecording for " << TIME << " seconds ... writing file test.raw." << endl;
87 while (counter < frames) {
90 audio->tickStream(stream);
92 catch (RtAudioError &m) {
97 fwrite(buffer, sizeof(MY_TYPE), chans * buffer_size, fd);
98 counter += buffer_size;
102 audio->stopStream(stream);
104 catch (RtAudioError &m) {
109 audio->closeStream(stream);