comparison examples/04-Audio/oscillator-bank/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 int gNumOscillators = 32;
34 int gWavetableLength = 1024;
35
36 // Handle Ctrl-C by requesting that the audio rendering stop
37 void interrupt_handler(int var)
38 {
39 gShouldStop = true;
40 }
41
42 // Print usage information
43 void usage(const char * processName)
44 {
45 cerr << "Usage: " << processName << " [options]" << endl;
46
47 Bela_usage();
48
49 cerr << " --num-oscillators [-n] oscs: Set the number of oscillators to use (default: 32)\n";
50 cerr << " --wavetable [-w] length: Set the wavetable length in samples (default: 1024)\n";
51 cerr << " --help [-h]: Print this menu\n";
52 }
53
54 int main(int argc, char *argv[])
55 {
56 BelaInitSettings settings; // Standard audio settings
57
58 struct option customOptions[] =
59 {
60 {"help", 0, NULL, 'h'},
61 {"num-oscillators", 1, NULL, 'n'},
62 {"wavetable", 1, NULL, 'w'},
63 {NULL, 0, NULL, 0}
64 };
65
66 // Set default settings
67 Bela_defaultSettings(&settings);
68
69 // Parse command-line arguments
70 while (1) {
71 int c;
72 if ((c = Bela_getopt_long(argc, argv, "hn:w:", customOptions, &settings)) < 0)
73 break;
74 switch (c) {
75 case 'h':
76 usage(basename(argv[0]));
77 exit(0);
78 case 'n':
79 gNumOscillators = atoi(optarg);
80 if(gNumOscillators <= 0) {
81 usage(basename(argv[0]));
82 exit(0);
83 }
84 break;
85 case 'w':
86 gWavetableLength = atoi(optarg);
87 if(gWavetableLength < 4)
88 gWavetableLength = 4;
89 if(gWavetableLength > 16384)
90 gWavetableLength = 16384;
91 break;
92 case '?':
93 default:
94 usage(basename(argv[0]));
95 exit(1);
96 }
97 }
98
99 // Initialise the PRU audio device
100 if(Bela_initAudio(&settings, 0) != 0) {
101 cout << "Error: unable to initialise audio" << endl;
102 return -1;
103 }
104
105 if(settings.verbose) {
106 cout << "--> Using " << gNumOscillators << " oscillators and wavetable of " << gWavetableLength << " samples\n";
107 }
108
109 // Start the audio device running
110 if(Bela_startAudio()) {
111 cout << "Error: unable to start real-time audio" << endl;
112 return -1;
113 }
114
115 // Set up interrupt handler to catch Control-C and SIGTERM
116 signal(SIGINT, interrupt_handler);
117 signal(SIGTERM, interrupt_handler);
118
119 // Run until told to stop
120 while(!gShouldStop) {
121 usleep(100000);
122 }
123
124 // Stop the audio device
125 Bela_stopAudio();
126
127 // Clean up any resources allocated for audio
128 Bela_cleanupAudio();
129
130 // All done!
131 return 0;
132 }