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_SINT8
20 typedef signed short MY_TYPE;
21 #define FORMAT RTAUDIO_SINT16
23 typedef signed long MY_TYPE;
24 #define FORMAT RTAUDIO_SINT24
26 typedef signed long MY_TYPE;
27 #define FORMAT RTAUDIO_SINT32
30 typedef float MY_TYPE;
31 #define FORMAT RTAUDIO_FLOAT32
34 typedef double MY_TYPE;
35 #define FORMAT RTAUDIO_FLOAT64
41 /* Error function in case of incorrect command-line
42 argument specifications
44 std::cout << "\nuseage: record_raw N fs <device>\n";
45 std::cout << " where N = number of channels,\n";
46 std::cout << " fs = the sample rate,\n";
47 std::cout << " and device = the device to use (default = 0).\n\n";
51 int main(int argc, char *argv[])
53 int chans, fs, buffer_size, device = 0;
54 long frames, counter = 0;
59 // minimal command-line checking
60 if (argc != 3 && argc != 4 ) usage();
62 chans = (int) atoi(argv[1]);
63 fs = (int) atoi(argv[2]);
65 device = (int) atoi(argv[3]);
67 // Open the realtime output device
70 audio = new RtAudio(0, 0, device, chans,
71 FORMAT, fs, &buffer_size, 8);
73 catch (RtError &error) {
78 fd = fopen("test.raw","wb");
79 frames = (long) (fs * TIME);
82 buffer = (MY_TYPE *) audio->getStreamBuffer();
85 catch (RtError &error) {
90 std::cout << "\nRecording for " << TIME << " seconds ... writing file test.raw (buffer size = " << buffer_size << ")." << std::endl;
91 while (counter < frames) {
96 catch (RtError &error) {
101 fwrite(buffer, sizeof(MY_TYPE), chans * buffer_size, fd);
102 counter += buffer_size;
108 catch (RtError &error) {
109 error.printMessage();
113 audio->closeStream();