Mercurial > hg > beaglert
comparison examples/01-Basics/passthrough/main.cpp @ 464:8fcfbfb32aa0 prerelease
Examples reorder with subdirectories. Added header to each project. Moved Doxygen to bottom of render.cpp.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Mon, 20 Jun 2016 16:20:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
463:c47709e8b5c9 | 464:8fcfbfb32aa0 |
---|---|
1 /* | |
2 ____ _____ _ _ | |
3 | __ )| ____| | / \ | |
4 | _ \| _| | | / _ \ | |
5 | |_) | |___| |___ / ___ \ | |
6 |____/|_____|_____/_/ \_\ | |
7 | |
8 The platform for ultra-low latency audio and sensor processing | |
9 | |
10 http://bela.io | |
11 | |
12 A project of the Augmented Instruments Laboratory within the | |
13 Centre for Digital Music at Queen Mary University of London. | |
14 http://www.eecs.qmul.ac.uk/~andrewm | |
15 | |
16 (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, | |
17 Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, | |
18 Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. | |
19 | |
20 The Bela software is distributed under the GNU Lesser General Public License | |
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt | |
22 */ | |
23 | |
24 #include <iostream> | |
25 #include <cstdlib> | |
26 #include <libgen.h> | |
27 #include <signal.h> | |
28 #include <getopt.h> | |
29 #include <Bela.h> | |
30 | |
31 using namespace std; | |
32 | |
33 // Handle Ctrl-C by requesting that the audio rendering stop | |
34 void interrupt_handler(int var) | |
35 { | |
36 gShouldStop = true; | |
37 } | |
38 | |
39 // Print usage information | |
40 void usage(const char * processName) | |
41 { | |
42 cerr << "Usage: " << processName << " [options]" << endl; | |
43 | |
44 Bela_usage(); | |
45 | |
46 cerr << " --help [-h]: Print this menu\n"; | |
47 } | |
48 | |
49 int main(int argc, char *argv[]) | |
50 { | |
51 BelaInitSettings settings; // Standard audio settings | |
52 | |
53 struct option customOptions[] = | |
54 { | |
55 {"help", 0, NULL, 'h'}, | |
56 {NULL, 0, NULL, 0} | |
57 }; | |
58 | |
59 // Set default settings | |
60 Bela_defaultSettings(&settings); | |
61 | |
62 // Parse command-line arguments | |
63 while (1) { | |
64 int c; | |
65 if ((c = Bela_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) | |
66 break; | |
67 switch (c) { | |
68 case 'h': | |
69 usage(basename(argv[0])); | |
70 exit(0); | |
71 case '?': | |
72 default: | |
73 usage(basename(argv[0])); | |
74 exit(1); | |
75 } | |
76 } | |
77 | |
78 // Initialise the PRU audio device | |
79 if(Bela_initAudio(&settings, 0) != 0) { | |
80 cout << "Error: unable to initialise audio" << endl; | |
81 return -1; | |
82 } | |
83 | |
84 // Start the audio device running | |
85 if(Bela_startAudio()) { | |
86 cout << "Error: unable to start real-time audio" << endl; | |
87 return -1; | |
88 } | |
89 | |
90 // Set up interrupt handler to catch Control-C and SIGTERM | |
91 signal(SIGINT, interrupt_handler); | |
92 signal(SIGTERM, interrupt_handler); | |
93 | |
94 // Run until told to stop | |
95 while(!gShouldStop) { | |
96 usleep(100000); | |
97 } | |
98 | |
99 // Stop the audio device | |
100 Bela_stopAudio(); | |
101 | |
102 // Clean up any resources allocated for audio | |
103 Bela_cleanupAudio(); | |
104 | |
105 // All done! | |
106 return 0; | |
107 } |