comparison core/RTAudioCommandLine.cpp @ 16:670be80463a3 matrix_gpio

- analog matrixIn/matrixOut are now mapped as floats from 0 to 1 - use of an external PRU code can be enabled with -P <filename> - 16 channels of programmable GPIO can be accessed straight from render() either writing directly to the matrixGpio[] array or using digitalWrite(), digitalRead(), setDigitalDirection() macros from Utilities.h .
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 27 Apr 2015 13:01:57 +0100
parents a6beeba3a648
children c98863e63174
comparison
equal deleted inserted replaced
15:901d205d1a3c 16:670be80463a3
7 7
8 #include <iostream> 8 #include <iostream>
9 #include <cstdlib> 9 #include <cstdlib>
10 #include <cstring> 10 #include <cstring>
11 #include <getopt.h> 11 #include <getopt.h>
12
13 #include "../include/RTAudio.h" 12 #include "../include/RTAudio.h"
14 13
15 // Default command-line options for RTAudio 14 // Default command-line options for RTAudio
16 struct option gDefaultLongOptions[] = 15 struct option gDefaultLongOptions[] =
17 { 16 {
18 {"period", 1, NULL, 'p'}, 17 {"period", 1, NULL, 'p'},
19 {"verbose", 0, NULL, 'v'}, 18 {"verbose", 0, NULL, 'v'},
20 {"use-matrix", 1, NULL, 'm'}, 19 {"use-matrix", 1, NULL, 'm'},
20 {"use-matrix-gpio", 1, NULL, 'g'},
21 {"matrix-channels", 1, NULL, 'C'}, 21 {"matrix-channels", 1, NULL, 'C'},
22 {"matrix-gpio-channels", 1, NULL, 'G'},
22 {"mute-speaker", 1, NULL, 'M'}, 23 {"mute-speaker", 1, NULL, 'M'},
23 {"dac-level", 1, NULL, 'D'}, 24 {"dac-level", 1, NULL, 'D'},
24 {"adc-level", 1, NULL, 'A'}, 25 {"adc-level", 1, NULL, 'A'},
25 {"hp-level", 1, NULL, 'H'}, 26 {"hp-level", 1, NULL, 'H'},
27 {"pru-file",1,NULL,'P'},
26 {NULL, 0, NULL, 0} 28 {NULL, 0, NULL, 0}
27 }; 29 };
28 30
29 const char gDefaultShortOptions[] = "p:vm:M:C:D:A:H:"; 31 const char gDefaultShortOptions[] = "p:vm:M:C:D:A:H:P:g:G:";
30 32
31 // This function sets the default settings for the RTAudioSettings structure 33 // This function sets the default settings for the RTAudioSettings structure
32 void BeagleRT_defaultSettings(RTAudioSettings *settings) 34 void BeagleRT_defaultSettings(RTAudioSettings *settings)
33 { 35 {
34 // Set default values for settings 36 // Set default values for settings
36 settings->beginMuted = 0; 38 settings->beginMuted = 0;
37 settings->dacLevel = DEFAULT_DAC_LEVEL; 39 settings->dacLevel = DEFAULT_DAC_LEVEL;
38 settings->adcLevel = DEFAULT_ADC_LEVEL; 40 settings->adcLevel = DEFAULT_ADC_LEVEL;
39 settings->headphoneLevel = DEFAULT_HP_LEVEL; 41 settings->headphoneLevel = DEFAULT_HP_LEVEL;
40 settings->useMatrix = 1; 42 settings->useMatrix = 1;
43 settings->useMatrixGpio = 1;
41 settings->numMatrixChannels = 8; 44 settings->numMatrixChannels = 8;
45 settings->numMatrixGpioChannels = 16;
42 settings->verbose = 0; 46 settings->verbose = 0;
47 settings->pruFilename[0]='\0';
43 settings->codecI2CAddress = CODEC_I2C_ADDRESS; 48 settings->codecI2CAddress = CODEC_I2C_ADDRESS;
44 settings->ampMutePin = kAmplifierMutePin; 49 settings->ampMutePin = kAmplifierMutePin;
45 } 50 }
46 51
47 // This function drops in place of getopt() in the main() function 52 // This function drops in place of getopt() in the main() function
123 settings->verbose = 1; 128 settings->verbose = 1;
124 break; 129 break;
125 case 'm': 130 case 'm':
126 settings->useMatrix = atoi(optarg); 131 settings->useMatrix = atoi(optarg);
127 break; 132 break;
133 case 'g':
134 settings->useMatrixGpio = atoi(optarg);
135 settings->numMatrixGpioChannels = 0;
136 break;
128 case 'C': 137 case 'C':
129 settings->numMatrixChannels = atoi(optarg); 138 settings->numMatrixChannels = atoi(optarg);
130 if(settings->numMatrixChannels >= 8) 139 if(settings->numMatrixChannels >= 8)
131 settings->numMatrixChannels = 8; 140 settings->numMatrixChannels = 8;
132 else if(settings->numMatrixChannels >= 4) 141 else if(settings->numMatrixChannels >= 4)
133 settings->numMatrixChannels = 4; 142 settings->numMatrixChannels = 4;
134 else 143 else
135 settings->numMatrixChannels = 2; 144 settings->numMatrixChannels = 2;
145 break;
146 case 'G':
147 settings->numMatrixGpioChannels = atoi(optarg);
148 if(settings->numMatrixGpioChannels >= 16)
149 settings->numMatrixGpioChannels = 16;
150 else if (settings->numMatrixGpioChannels < 1){
151 settings->numMatrixGpioChannels = 0;
152 settings->useMatrixGpio = 0; //TODO: this actually works only if -G 0 is specified after -g 1.
153 //No worries, though: disabling numMatrixGpio will only prevent the pins from being exported.
154 }
136 break; 155 break;
137 case 'M': 156 case 'M':
138 settings->beginMuted = atoi(optarg); 157 settings->beginMuted = atoi(optarg);
139 break; 158 break;
140 case 'D': 159 case 'D':
144 settings->adcLevel = atof(optarg); 163 settings->adcLevel = atof(optarg);
145 break; 164 break;
146 case 'H': 165 case 'H':
147 settings->headphoneLevel = atof(optarg); 166 settings->headphoneLevel = atof(optarg);
148 break; 167 break;
168 case 'P':
169 if(strlen(optarg)<MAX_PRU_FILENAME_LENGTH)
170 strcpy(settings->pruFilename, optarg);
171 else
172 std::cerr << "Warning: filename for the PRU code is too long (>" << MAX_PRU_FILENAME_LENGTH << " characters). Using embedded PRU code instead\n";
173 break;
149 case '?': 174 case '?':
150 default: 175 default:
151 return c; 176 return c;
152 } 177 }
153 } 178 }
155 180
156 // This function prints standard usage information for default arguments 181 // This function prints standard usage information for default arguments
157 // Call from within your own usage function 182 // Call from within your own usage function
158 void BeagleRT_usage() 183 void BeagleRT_usage()
159 { 184 {
160 std::cerr << " --period [-p] period: Set the hardware period (buffer) size in matrix samples\n"; 185 std::cerr << " --period [-p] period: Set the hardware period (buffer) size in matrix samples\n";
161 std::cerr << " --dac-level [-D] dBs: Set the DAC output level (0dB max; -63.5dB min)\n"; 186 std::cerr << " --dac-level [-D] dBs: Set the DAC output level (0dB max; -63.5dB min)\n";
162 std::cerr << " --adc-level [-A] dBs: Set the ADC input level (0dB max; -12dB min)\n"; 187 std::cerr << " --adc-level [-A] dBs: Set the ADC input level (0dB max; -12dB min)\n";
163 std::cerr << " --hp-level [-H] dBs: Set the headphone output level (0dB max; -63.5dB min)\n"; 188 std::cerr << " --hp-level [-H] dBs: Set the headphone output level (0dB max; -63.5dB min)\n";
164 std::cerr << " --mute-speaker [-M] val: Set whether to mute the speaker initially (default: no)\n"; 189 std::cerr << " --mute-speaker [-M] val: Set whether to mute the speaker initially (default: no)\n";
165 std::cerr << " --use-matrix [-m] val: Set whether to use ADC/DAC matrix\n"; 190 std::cerr << " --use-matrix [-m] val: Set whether to use ADC/DAC matrix (default: yes)\n";
166 std::cerr << " --matrix-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; 191 std::cerr << " --use-gpio-matrix [-g] val: Set whether to use GPIO matrix (default: yes)\n";
167 std::cerr << " --verbose [-v]: Enable verbose logging information\n"; 192 std::cerr << " --matrix-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n";
193 std::cerr << " --matrix-gpio-channels [-G] val: Set the number of GPIO channels (default: 16)\n";
194 std::cerr << " --pru-file [-P] val: Set an optional external file to use for the PRU binary code\n";
195 std::cerr << " --verbose [-v]: Enable verbose logging information\n";
168 } 196 }
197