comparison core/RTAudioCommandLine.cpp @ 67:472e892c6e41

Merge newapi into default
author Andrew McPherson <a.mcpherson@qmul.ac.uk>
date Fri, 17 Jul 2015 15:28:18 +0100
parents a6d223473ea2
children e63563507edd
comparison
equal deleted inserted replaced
21:0d80ff9e2227 67:472e892c6e41
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 12 #include "../include/BeagleRT.h"
13 #include "../include/RTAudio.h" 13
14 #ifndef OPT_PRU_FILE
15 #define OPT_PRU_FILE 176 // this is an extended ASCII code
16 #endif
17
18 enum {
19 kAmplifierMutePin = 61 // P8-26 controls amplifier mute
20 };
14 21
15 // Default command-line options for RTAudio 22 // Default command-line options for RTAudio
16 struct option gDefaultLongOptions[] = 23 struct option gDefaultLongOptions[] =
17 { 24 {
18 {"period", 1, NULL, 'p'}, 25 {"period", 1, NULL, 'p'},
19 {"verbose", 0, NULL, 'v'}, 26 {"verbose", 0, NULL, 'v'},
20 {"use-matrix", 1, NULL, 'm'}, 27 {"use-analog", 1, NULL, 'N'},
21 {"matrix-channels", 1, NULL, 'C'}, 28 {"use-digital", 1, NULL, 'G'},
29 {"analog-channels", 1, NULL, 'C'},
30 {"digital-channels", 1, NULL, 'B'},
22 {"mute-speaker", 1, NULL, 'M'}, 31 {"mute-speaker", 1, NULL, 'M'},
23 {"dac-level", 1, NULL, 'D'}, 32 {"dac-level", 1, NULL, 'D'},
24 {"adc-level", 1, NULL, 'A'}, 33 {"adc-level", 1, NULL, 'A'},
25 {"hp-level", 1, NULL, 'H'}, 34 {"hp-level", 1, NULL, 'H'},
35 {"receive-port", 1, NULL, 'R'},
36 {"transmit-port", 1, NULL, 'T'},
37 {"server-name", 1, NULL, 'S'},
38 {"pru-file", 1, NULL, OPT_PRU_FILE},
26 {NULL, 0, NULL, 0} 39 {NULL, 0, NULL, 0}
27 }; 40 };
28 41
29 const char gDefaultShortOptions[] = "p:vm:M:C:D:A:H:"; 42 const char gDefaultShortOptions[] = "p:vN:M:C:D:A:H:G:B:R:T:S:";
30 43
31 // This function sets the default settings for the RTAudioSettings structure 44 // This function sets the default settings for the BeagleRTInitSettings structure
32 void BeagleRT_defaultSettings(RTAudioSettings *settings) 45 void BeagleRT_defaultSettings(BeagleRTInitSettings *settings)
33 { 46 {
34 // Set default values for settings 47 // Set default values for settings
35 settings->periodSize = 8; 48 settings->periodSize = 8;
49 settings->useAnalog = 1;
50 settings->useDigital = 1;
51 settings->numAnalogChannels = 8;
52 settings->numDigitalChannels = 16;
53
36 settings->beginMuted = 0; 54 settings->beginMuted = 0;
37 settings->dacLevel = DEFAULT_DAC_LEVEL; 55 settings->dacLevel = DEFAULT_DAC_LEVEL;
38 settings->adcLevel = DEFAULT_ADC_LEVEL; 56 settings->adcLevel = DEFAULT_ADC_LEVEL;
39 settings->headphoneLevel = DEFAULT_HP_LEVEL; 57 settings->headphoneLevel = DEFAULT_HP_LEVEL;
40 settings->useMatrix = 1; 58
41 settings->numMatrixChannels = 8;
42 settings->verbose = 0; 59 settings->verbose = 0;
60 settings->pruFilename[0] = '\0';
61
62 // These two deliberately have no command-line flags by default.
63 // A given program might prefer one mode or another, but it's unlikely
64 // the user would want to switch at runtime
65 settings->interleave = 1;
66 settings->analogOutputsPersist = 1;
67
43 settings->codecI2CAddress = CODEC_I2C_ADDRESS; 68 settings->codecI2CAddress = CODEC_I2C_ADDRESS;
69 settings->receivePort = 9998;
70 settings->transmitPort = 9999;
71 strcpy(settings->serverName, "127.0.0.1");
44 settings->ampMutePin = kAmplifierMutePin; 72 settings->ampMutePin = kAmplifierMutePin;
45 } 73 }
46 74
47 // This function drops in place of getopt() in the main() function 75 // This function drops in place of getopt() in the main() function
48 // and handles the initialisation of the RTAudio settings using 76 // and handles the initialisation of the RTAudio settings using
49 // standard command-line arguments. System default arguments will 77 // standard command-line arguments. System default arguments will
50 // be stored in settings, otherwise arguments will be returned 78 // be stored in settings, otherwise arguments will be returned
51 // as getopt() normally does. 79 // as getopt() normally does.
52 80
53 int BeagleRT_getopt_long(int argc, char *argv[], const char *customShortOptions, const struct option *customLongOptions, RTAudioSettings *settings) 81 int BeagleRT_getopt_long(int argc, char *argv[], const char *customShortOptions, const struct option *customLongOptions, BeagleRTInitSettings *settings)
54 { 82 {
55 static int firstRun = 1; 83 static int firstRun = 1;
56 static char totalShortOptions[256]; 84 static char totalShortOptions[256];
57 static struct option totalLongOptions[256]; 85 static struct option totalLongOptions[256];
58 86
120 settings->periodSize = 1; 148 settings->periodSize = 1;
121 break; 149 break;
122 case 'v': 150 case 'v':
123 settings->verbose = 1; 151 settings->verbose = 1;
124 break; 152 break;
125 case 'm': 153 case 'N':
126 settings->useMatrix = atoi(optarg); 154 settings->useAnalog = atoi(optarg);
155 break;
156 case 'G':
157 settings->useDigital = atoi(optarg);
158 settings->numDigitalChannels = 0;
127 break; 159 break;
128 case 'C': 160 case 'C':
129 settings->numMatrixChannels = atoi(optarg); 161 settings->numAnalogChannels = atoi(optarg);
130 if(settings->numMatrixChannels >= 8) 162 if(settings->numAnalogChannels >= 8)
131 settings->numMatrixChannels = 8; 163 settings->numAnalogChannels = 8;
132 else if(settings->numMatrixChannels >= 4) 164 else if(settings->numAnalogChannels >= 4)
133 settings->numMatrixChannels = 4; 165 settings->numAnalogChannels = 4;
134 else 166 else
135 settings->numMatrixChannels = 2; 167 settings->numAnalogChannels = 2;
168 break;
169 case 'B':
170 settings->numDigitalChannels = atoi(optarg);
171 if(settings->numDigitalChannels >= 16)
172 settings->numDigitalChannels = 16;
173 else if (settings->numDigitalChannels < 1){
174 settings->numDigitalChannels = 0;
175 settings->useDigital = 0; //TODO: this actually works only if -G 0 is specified after -g 1.
176 //No worries, though: disabling numDigital will only prevent the pins from being exported.
177 }
136 break; 178 break;
137 case 'M': 179 case 'M':
138 settings->beginMuted = atoi(optarg); 180 settings->beginMuted = atoi(optarg);
139 break; 181 break;
140 case 'D': 182 case 'D':
143 case 'A': 185 case 'A':
144 settings->adcLevel = atof(optarg); 186 settings->adcLevel = atof(optarg);
145 break; 187 break;
146 case 'H': 188 case 'H':
147 settings->headphoneLevel = atof(optarg); 189 settings->headphoneLevel = atof(optarg);
190 break;
191 case 'R':
192 settings->receivePort = atoi(optarg);
193 break;
194 case 'T':
195 settings->transmitPort = atoi(optarg);
196 break;
197 case 'S':
198 if(strlen(optarg)<MAX_SERVERNAME_LENGTH)
199 strcpy(settings->serverName, optarg);
200 else
201 std::cerr << "Warning: server name is too long (>" << MAX_SERVERNAME_LENGTH << " characters)."
202 " Using default severName Instead ( " << settings->serverName << " ).\n";
203 break;
204 case OPT_PRU_FILE:
205 if(strlen(optarg) < MAX_PRU_FILENAME_LENGTH)
206 strcpy(settings->pruFilename, optarg);
207 else
208 std::cerr << "Warning: filename for the PRU code is too long (>" << MAX_PRU_FILENAME_LENGTH << " characters). Using embedded PRU code instead\n";
148 break; 209 break;
149 case '?': 210 case '?':
150 default: 211 default:
151 return c; 212 return c;
152 } 213 }
155 216
156 // This function prints standard usage information for default arguments 217 // This function prints standard usage information for default arguments
157 // Call from within your own usage function 218 // Call from within your own usage function
158 void BeagleRT_usage() 219 void BeagleRT_usage()
159 { 220 {
160 std::cerr << " --period [-p] period: Set the hardware period (buffer) size in matrix samples\n"; 221 std::cerr << " --period [-p] period: Set the hardware period (buffer) size in analog samples\n";
161 std::cerr << " --dac-level [-D] dBs: Set the DAC output level (0dB max; -63.5dB min)\n"; 222 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"; 223 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"; 224 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"; 225 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"; 226 std::cerr << " --use-analog [-N] val: Set whether to use ADC/DAC analog (default: yes)\n";
166 std::cerr << " --matrix-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; 227 std::cerr << " --use-digital [-G] val: Set whether to use digital GPIO channels (default: yes)\n";
167 std::cerr << " --verbose [-v]: Enable verbose logging information\n"; 228 std::cerr << " --analog-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n";
229 std::cerr << " --digital-channels [-B] val: Set the number of GPIO channels (default: 16)\n";
230 std::cerr << " --receive-port [-R] val: Set the receive port (default: 9998)\n";
231 std::cerr << " --transmit-port [-T] val: Set the transmit port (default: 9999)\n";
232 std::cerr << " --server-name [-S] val: Set the destination server name (default: '127.0.0.1')\n";
233 std::cerr << " --pru-file val: Set an optional external file to use for the PRU binary code\n";
234 std::cerr << " --verbose [-v]: Enable verbose logging information\n";
168 } 235 }
236