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