Mercurial > hg > beaglert
comparison examples/11-Extras/userdata/main.cpp @ 543:8f8809c77dda prerelease
updated basics, digital, instruments, extras examples
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Fri, 24 Jun 2016 13:19:52 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
542:3016638b4da2 | 543:8f8809c77dda |
---|---|
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 <unistd.h> | |
25 #include <iostream> | |
26 #include <cstdlib> | |
27 #include <libgen.h> | |
28 #include <signal.h> | |
29 #include <getopt.h> | |
30 #include <Bela.h> | |
31 | |
32 using namespace std; | |
33 | |
34 // Handle Ctrl-C by requesting that the audio rendering stop | |
35 void interrupt_handler(int var) | |
36 { | |
37 gShouldStop = true; | |
38 } | |
39 | |
40 // Print usage information | |
41 void usage(const char * processName) | |
42 { | |
43 cerr << "Usage: " << processName << " [options]" << endl; | |
44 | |
45 Bela_usage(); | |
46 | |
47 cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n"; | |
48 cerr << " --help [-h]: Print this menu\n"; | |
49 } | |
50 | |
51 int main(int argc, char *argv[]) | |
52 { | |
53 BelaInitSettings settings; // Standard audio settings | |
54 float frequency = 440.0; // Frequency of oscillator | |
55 | |
56 struct option customOptions[] = | |
57 { | |
58 {"help", 0, NULL, 'h'}, | |
59 {"frequency", 1, NULL, 'f'}, | |
60 {NULL, 0, NULL, 0} | |
61 }; | |
62 | |
63 // Set default settings | |
64 Bela_defaultSettings(&settings); | |
65 | |
66 // Parse command-line arguments | |
67 while (1) { | |
68 int c; | |
69 if ((c = Bela_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) | |
70 break; | |
71 switch (c) { | |
72 case 'h': | |
73 usage(basename(argv[0])); | |
74 exit(0); | |
75 case 'f': | |
76 frequency = atof(optarg); | |
77 break; | |
78 case '?': | |
79 default: | |
80 usage(basename(argv[0])); | |
81 exit(1); | |
82 } | |
83 } | |
84 | |
85 // Initialise the PRU audio device | |
86 | |
87 /* | |
88 * Note how we are passing the frequency parameter so that it | |
89 * can be read from the setup() function inside render.cpp | |
90 */ | |
91 | |
92 if(Bela_initAudio(&settings, &frequency) != 0) { | |
93 cout << "Error: unable to initialise audio" << endl; | |
94 return -1; | |
95 } | |
96 | |
97 // Start the audio device running | |
98 if(Bela_startAudio()) { | |
99 cout << "Error: unable to start real-time audio" << endl; | |
100 return -1; | |
101 } | |
102 | |
103 // Set up interrupt handler to catch Control-C and SIGTERM | |
104 signal(SIGINT, interrupt_handler); | |
105 signal(SIGTERM, interrupt_handler); | |
106 | |
107 // Run until told to stop | |
108 while(!gShouldStop) { | |
109 usleep(100000); | |
110 } | |
111 | |
112 // Stop the audio device | |
113 Bela_stopAudio(); | |
114 | |
115 // Clean up any resources allocated for audio | |
116 Bela_cleanupAudio(); | |
117 | |
118 // All done! | |
119 return 0; | |
120 } |