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