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