Mercurial > hg > beaglert
comparison projects/oscillator_bank/main.cpp @ 0:8a575ba3ab52
Initial commit.
author | andrewm |
---|---|
date | Fri, 31 Oct 2014 19:10:17 +0100 |
parents | |
children | 09f03ac40fcc |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8a575ba3ab52 |
---|---|
1 /* | |
2 * main.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 | |
8 #include <iostream> | |
9 #include <cstdlib> | |
10 #include <libgen.h> | |
11 #include <signal.h> | |
12 #include "../../include/RTAudio.h" | |
13 | |
14 using namespace std; | |
15 | |
16 int gNumOscillators = 32; | |
17 int gWavetableLength = 1024; | |
18 | |
19 | |
20 // Handle Ctrl-C by requesting that the audio rendering stop | |
21 void interrupt_handler(int var) | |
22 { | |
23 gShouldStop = true; | |
24 } | |
25 | |
26 // Print usage information | |
27 void usage(const char * processName) | |
28 { | |
29 cerr << "Usage: " << processName << " [-h] [-v] [-p period] [-f input] [-a input]" << endl; | |
30 cerr << " -h: Print this menu\n"; | |
31 cerr << " -v: Enable verbose messages\n"; | |
32 cerr << " -p period: Set the period (hardware buffer) size in sensor frames\n"; | |
33 cerr << " -n oscs: Set the number of oscillators to use (default: 32)\n"; | |
34 cerr << " -w length: Set the wavetable length in samples (default: 1024)\n"; | |
35 cerr << " -m: Enable the matrix (ADC and DAC) for controlling parameters\n"; | |
36 } | |
37 | |
38 int main(int argc, char *argv[]) | |
39 { | |
40 int periodSize = 8; // Period size in sensor frames | |
41 int verbose = 0; // Verbose printing level | |
42 int useMatrix = 0; | |
43 | |
44 // Parse command-line arguments | |
45 while (1) { | |
46 int c; | |
47 if ((c = getopt(argc, argv, "hp:vn:w:m")) < 0) | |
48 break; | |
49 switch (c) { | |
50 case 'h': | |
51 usage(basename(argv[0])); | |
52 exit(0); | |
53 case 'p': | |
54 periodSize = atoi(optarg); | |
55 if(periodSize < 1) | |
56 periodSize = 1; | |
57 break; | |
58 case 'v': | |
59 verbose = 1; | |
60 break; | |
61 case 'n': | |
62 gNumOscillators = atoi(optarg); | |
63 if(gNumOscillators <= 0) { | |
64 usage(basename(argv[0])); | |
65 exit(0); | |
66 } | |
67 break; | |
68 case 'w': | |
69 gWavetableLength = atoi(optarg); | |
70 if(gWavetableLength < 4) | |
71 gWavetableLength = 4; | |
72 if(gWavetableLength > 16384) | |
73 gWavetableLength = 16384; | |
74 break; | |
75 case 'm': | |
76 useMatrix = 1; | |
77 break; | |
78 case '?': | |
79 default: | |
80 usage(basename(argv[0])); | |
81 exit(1); | |
82 } | |
83 } | |
84 | |
85 | |
86 // Set verbose logging information (optional by using value > 0; default is 0) | |
87 setVerboseLevel(verbose); | |
88 | |
89 if(verbose) { | |
90 cout << "Starting with period size " << periodSize << endl; | |
91 cout << "--> Using " << gNumOscillators << " oscillators and wavetable of " << gWavetableLength << " samples\n"; | |
92 cout << "--> Matrix "; | |
93 if(useMatrix) cout << "enabled\n"; | |
94 else cout << "disabled\n"; | |
95 } | |
96 | |
97 // Initialise the PRU audio device | |
98 if(initAudio(periodSize, useMatrix, 0) != 0) { | |
99 cout << "Error: unable to initialise audio" << endl; | |
100 return -1; | |
101 } | |
102 | |
103 // Start the audio device running | |
104 if(startAudio()) { | |
105 cout << "Error: unable to start real-time audio" << endl; | |
106 return -1; | |
107 } | |
108 | |
109 // Set up interrupt handler to catch Control-C | |
110 signal(SIGINT, interrupt_handler); | |
111 | |
112 // Run until told to stop | |
113 while(!gShouldStop) { | |
114 usleep(100000); | |
115 } | |
116 | |
117 // Stop the audio device | |
118 stopAudio(); | |
119 | |
120 if(verbose) { | |
121 cout << "Cleaning up..." << endl; | |
122 } | |
123 | |
124 // Clean up any resources allocated for audio | |
125 cleanupAudio(); | |
126 | |
127 // All done! | |
128 return 0; | |
129 } |