1 /******************************************/
4 by Gary P. Scavone, 2001
6 Play a raw file. It is necessary that the
7 file be of the same format as defined below.
8 Uses blocking functionality.
10 /******************************************/
18 #define FORMAT RTAUDIO_SINT8
21 typedef signed short MY_TYPE;
22 #define FORMAT RTAUDIO_SINT16
25 typedef signed long MY_TYPE;
26 #define FORMAT RTAUDIO_SINT24
27 #define SCALE 8388607.0
29 typedef signed long MY_TYPE;
30 #define FORMAT RTAUDIO_SINT32
31 #define SCALE 2147483647.0
34 typedef float MY_TYPE;
35 #define FORMAT RTAUDIO_FLOAT32
39 typedef double MY_TYPE;
40 #define FORMAT RTAUDIO_FLOAT64
45 /* Error function in case of incorrect command-line
46 argument specifications
48 std::cout << "\nuseage: play_raw N fs file <device>\n";
49 std::cout << " where N = number of channels,\n";
50 std::cout << " fs = the sample rate, \n";
51 std::cout << " file = the raw file to play,\n";
52 std::cout << " and device = the device to use (default = 0).\n\n";
56 int main(int argc, char *argv[])
58 int chans, fs, buffer_size, count, device = 0;
65 // minimal command-line checking
66 if (argc != 4 && argc != 5 ) usage();
68 chans = (int) atoi(argv[1]);
69 fs = (int) atoi(argv[2]);
72 device = (int) atoi(argv[4]);
74 fd = fopen(file,"rb");
76 std::cout << "can't find file!\n";
80 // Open the realtime output device
83 audio = new RtAudio(device, chans, 0, 0,
84 FORMAT, fs, &buffer_size, 2);
86 catch (RtError &error) {
93 buffer = (MY_TYPE *) audio->getStreamBuffer();
96 catch (RtError &error) {
102 count = fread(buffer, chans * sizeof(MY_TYPE), buffer_size, fd);
104 if (count == buffer_size) {
108 catch (RtError &error) {
109 error.printMessage();
116 counter += buffer_size;
122 catch (RtError &error) {
123 error.printMessage();
127 audio->closeStream();