Mercurial > hg > beaglert
comparison projects/basic_passthru/main.cpp @ 13:6adb088196a7
Fixed ADC bug; added a simple passthrough test
author | andrewm |
---|---|
date | Fri, 23 Jan 2015 15:17:09 +0000 |
parents | |
children | 901d205d1a3c |
comparison
equal
deleted
inserted
replaced
12:a6beeba3a648 | 13:6adb088196a7 |
---|---|
1 /* | |
2 * main.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 | |
8 #include <iostream> | |
9 #include <cstdlib> | |
10 #include <libgen.h> | |
11 #include <signal.h> | |
12 #include <getopt.h> | |
13 #include "../../include/RTAudio.h" | |
14 | |
15 using namespace std; | |
16 | |
17 // Handle Ctrl-C by requesting that the audio rendering stop | |
18 void interrupt_handler(int var) | |
19 { | |
20 gShouldStop = true; | |
21 } | |
22 | |
23 // Print usage information | |
24 void usage(const char * processName) | |
25 { | |
26 cerr << "Usage: " << processName << " [options]" << endl; | |
27 | |
28 BeagleRT_usage(); | |
29 | |
30 cerr << " --help [-h]: Print this menu\n"; | |
31 } | |
32 | |
33 int main(int argc, char *argv[]) | |
34 { | |
35 RTAudioSettings settings; // Standard audio settings | |
36 | |
37 struct option customOptions[] = | |
38 { | |
39 {"help", 0, NULL, 'h'}, | |
40 {NULL, 0, NULL, 0} | |
41 }; | |
42 | |
43 // Set default settings | |
44 BeagleRT_defaultSettings(&settings); | |
45 | |
46 // Parse command-line arguments | |
47 while (1) { | |
48 int c; | |
49 if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) | |
50 break; | |
51 switch (c) { | |
52 case 'h': | |
53 usage(basename(argv[0])); | |
54 exit(0); | |
55 case '?': | |
56 default: | |
57 usage(basename(argv[0])); | |
58 exit(1); | |
59 } | |
60 } | |
61 | |
62 // Initialise the PRU audio device | |
63 if(BeagleRT_initAudio(&settings, 0) != 0) { | |
64 cout << "Error: unable to initialise audio" << endl; | |
65 return -1; | |
66 } | |
67 | |
68 // Start the audio device running | |
69 if(BeagleRT_startAudio()) { | |
70 cout << "Error: unable to start real-time audio" << endl; | |
71 return -1; | |
72 } | |
73 | |
74 // Set up interrupt handler to catch Control-C | |
75 signal(SIGINT, interrupt_handler); | |
76 | |
77 // Run until told to stop | |
78 while(!gShouldStop) { | |
79 usleep(100000); | |
80 } | |
81 | |
82 // Stop the audio device | |
83 BeagleRT_stopAudio(); | |
84 | |
85 // Clean up any resources allocated for audio | |
86 BeagleRT_cleanupAudio(); | |
87 | |
88 // All done! | |
89 return 0; | |
90 } |