comparison core/RTAudioCommandLine.cpp @ 108:3068421c0737 ultra-staging

Merged default into ultra-staging
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 18 Aug 2015 00:35:15 +0100
parents a6d223473ea2
children e63563507edd
comparison
equal deleted inserted replaced
54:d3f869b98147 108:3068421c0737
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 #include "../include/RTAudio.h" 12 #include "../include/BeagleRT.h"
13 13
14 #ifndef OPT_PRU_FILE 14 #ifndef OPT_PRU_FILE
15 #define OPT_PRU_FILE 176 // this is an extended ascii code 15 #define OPT_PRU_FILE 176 // this is an extended ASCII code
16 #endif 16 #endif
17
18 enum {
19 kAmplifierMutePin = 61 // P8-26 controls amplifier mute
20 };
17 21
18 // Default command-line options for RTAudio 22 // Default command-line options for RTAudio
19 struct option gDefaultLongOptions[] = 23 struct option gDefaultLongOptions[] =
20 { 24 {
21 {"period", 1, NULL, 'p'}, 25 {"period", 1, NULL, 'p'},
22 {"verbose", 0, NULL, 'v'}, 26 {"verbose", 0, NULL, 'v'},
23 {"use-analog", 1, NULL, 'm'}, 27 {"use-analog", 1, NULL, 'N'},
24 {"use-digital-gpio", 1, NULL, 'g'}, 28 {"use-digital", 1, NULL, 'G'},
25 {"analog-channels", 1, NULL, 'C'}, 29 {"analog-channels", 1, NULL, 'C'},
26 {"digital-channels", 1, NULL, 'G'}, 30 {"digital-channels", 1, NULL, 'B'},
27 {"mute-speaker", 1, NULL, 'M'}, 31 {"mute-speaker", 1, NULL, 'M'},
28 {"dac-level", 1, NULL, 'D'}, 32 {"dac-level", 1, NULL, 'D'},
29 {"adc-level", 1, NULL, 'A'}, 33 {"adc-level", 1, NULL, 'A'},
30 {"hp-level", 1, NULL, 'H'}, 34 {"hp-level", 1, NULL, 'H'},
31 {"receive-port", 1, NULL, 'r'}, 35 {"receive-port", 1, NULL, 'R'},
32 {"transmit-port", 1, NULL, 't'}, 36 {"transmit-port", 1, NULL, 'T'},
33 {"server-name",1,NULL,'s'}, 37 {"server-name", 1, NULL, 'S'},
34 {"pru-file",1,NULL,OPT_PRU_FILE}, 38 {"pru-file", 1, NULL, OPT_PRU_FILE},
35 {NULL, 0, NULL, 0} 39 {NULL, 0, NULL, 0}
36 }; 40 };
37 41
38 const char gDefaultShortOptions[] = "p:vm:M:C:D:A:H:g:G:r:t:s:"; 42 const char gDefaultShortOptions[] = "p:vN:M:C:D:A:H:G:B:R:T:S:";
39 43
40 // This function sets the default settings for the RTAudioSettings structure 44 // This function sets the default settings for the BeagleRTInitSettings structure
41 void BeagleRT_defaultSettings(RTAudioSettings *settings) 45 void BeagleRT_defaultSettings(BeagleRTInitSettings *settings)
42 { 46 {
43 // Set default values for settings 47 // Set default values for settings
44 settings->periodSize = 8; 48 settings->periodSize = 8;
49 settings->useAnalog = 1;
50 settings->useDigital = 1;
51 settings->numAnalogChannels = 8;
52 settings->numDigitalChannels = 16;
53
45 settings->beginMuted = 0; 54 settings->beginMuted = 0;
46 settings->dacLevel = DEFAULT_DAC_LEVEL; 55 settings->dacLevel = DEFAULT_DAC_LEVEL;
47 settings->adcLevel = DEFAULT_ADC_LEVEL; 56 settings->adcLevel = DEFAULT_ADC_LEVEL;
48 settings->headphoneLevel = DEFAULT_HP_LEVEL; 57 settings->headphoneLevel = DEFAULT_HP_LEVEL;
49 settings->useAnalog = 1; 58
50 settings->useDigital = 1;
51 settings->numAnalogChannels = 8;
52 settings->numDigitalChannels = 16;
53 settings->verbose = 0; 59 settings->verbose = 0;
54 settings->pruFilename[0]='\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
55 settings->codecI2CAddress = CODEC_I2C_ADDRESS; 68 settings->codecI2CAddress = CODEC_I2C_ADDRESS;
56 settings->receivePort=9998; 69 settings->receivePort = 9998;
57 settings->transmitPort=9999; 70 settings->transmitPort = 9999;
58 strcpy(settings->serverName, "127.0.0.1"); 71 strcpy(settings->serverName, "127.0.0.1");
59 settings->ampMutePin = kAmplifierMutePin; 72 settings->ampMutePin = kAmplifierMutePin;
60 } 73 }
61 74
62 // This function drops in place of getopt() in the main() function 75 // This function drops in place of getopt() in the main() function
63 // and handles the initialisation of the RTAudio settings using 76 // and handles the initialisation of the RTAudio settings using
64 // standard command-line arguments. System default arguments will 77 // standard command-line arguments. System default arguments will
65 // be stored in settings, otherwise arguments will be returned 78 // be stored in settings, otherwise arguments will be returned
66 // as getopt() normally does. 79 // as getopt() normally does.
67 80
68 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)
69 { 82 {
70 static int firstRun = 1; 83 static int firstRun = 1;
71 static char totalShortOptions[256]; 84 static char totalShortOptions[256];
72 static struct option totalLongOptions[256]; 85 static struct option totalLongOptions[256];
73 86
135 settings->periodSize = 1; 148 settings->periodSize = 1;
136 break; 149 break;
137 case 'v': 150 case 'v':
138 settings->verbose = 1; 151 settings->verbose = 1;
139 break; 152 break;
140 case 'm': 153 case 'N':
141 settings->useAnalog = atoi(optarg); 154 settings->useAnalog = atoi(optarg);
142 break; 155 break;
143 case 'g': 156 case 'G':
144 settings->useDigital = atoi(optarg); 157 settings->useDigital = atoi(optarg);
145 settings->numDigitalChannels = 0; 158 settings->numDigitalChannels = 0;
146 break; 159 break;
147 case 'C': 160 case 'C':
148 settings->numAnalogChannels = atoi(optarg); 161 settings->numAnalogChannels = atoi(optarg);
151 else if(settings->numAnalogChannels >= 4) 164 else if(settings->numAnalogChannels >= 4)
152 settings->numAnalogChannels = 4; 165 settings->numAnalogChannels = 4;
153 else 166 else
154 settings->numAnalogChannels = 2; 167 settings->numAnalogChannels = 2;
155 break; 168 break;
156 case 'G': 169 case 'B':
157 settings->numDigitalChannels = atoi(optarg); 170 settings->numDigitalChannels = atoi(optarg);
158 if(settings->numDigitalChannels >= 16) 171 if(settings->numDigitalChannels >= 16)
159 settings->numDigitalChannels = 16; 172 settings->numDigitalChannels = 16;
160 else if (settings->numDigitalChannels < 1){ 173 else if (settings->numDigitalChannels < 1){
161 settings->numDigitalChannels = 0; 174 settings->numDigitalChannels = 0;
173 settings->adcLevel = atof(optarg); 186 settings->adcLevel = atof(optarg);
174 break; 187 break;
175 case 'H': 188 case 'H':
176 settings->headphoneLevel = atof(optarg); 189 settings->headphoneLevel = atof(optarg);
177 break; 190 break;
178 case 'r': 191 case 'R':
179 settings->receivePort = atoi(optarg); 192 settings->receivePort = atoi(optarg);
180 break; 193 break;
181 case 't': 194 case 'T':
182 settings->transmitPort = atoi(optarg); 195 settings->transmitPort = atoi(optarg);
183 break; 196 break;
184 case 's': 197 case 'S':
185 if(strlen(optarg)<MAX_SERVERNAME_LENGTH) 198 if(strlen(optarg)<MAX_SERVERNAME_LENGTH)
186 strcpy(settings->serverName, optarg); 199 strcpy(settings->serverName, optarg);
187 else 200 else
188 std::cerr << "Warning: server name is too long (>" << MAX_SERVERNAME_LENGTH << " characters)." 201 std::cerr << "Warning: server name is too long (>" << MAX_SERVERNAME_LENGTH << " characters)."
189 " Using default severName Instead ( " << settings->serverName << " ).\n"; 202 " Using default severName Instead ( " << settings->serverName << " ).\n";
190 break; 203 break;
191 case OPT_PRU_FILE: 204 case OPT_PRU_FILE:
192 if(strlen(optarg)<MAX_PRU_FILENAME_LENGTH) 205 if(strlen(optarg) < MAX_PRU_FILENAME_LENGTH)
193 strcpy(settings->pruFilename, optarg); 206 strcpy(settings->pruFilename, optarg);
194 else 207 else
195 std::cerr << "Warning: filename for the PRU code is too long (>" << MAX_PRU_FILENAME_LENGTH << " characters). Using embedded PRU code instead\n"; 208 std::cerr << "Warning: filename for the PRU code is too long (>" << MAX_PRU_FILENAME_LENGTH << " characters). Using embedded PRU code instead\n";
196 break; 209 break;
197 case '?': 210 case '?':
208 std::cerr << " --period [-p] period: Set the hardware period (buffer) size in analog samples\n"; 221 std::cerr << " --period [-p] period: Set the hardware period (buffer) size in analog samples\n";
209 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";
210 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";
211 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";
212 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";
213 std::cerr << " --use-analog [-m] val: Set whether to use ADC/DAC analog (default: yes)\n"; 226 std::cerr << " --use-analog [-N] val: Set whether to use ADC/DAC analog (default: yes)\n";
214 std::cerr << " --use-digital [-g] val: Set whether to use digital GPIO channels (default: yes)\n"; 227 std::cerr << " --use-digital [-G] val: Set whether to use digital GPIO channels (default: yes)\n";
215 std::cerr << " --analog-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; 228 std::cerr << " --analog-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n";
216 std::cerr << " --digital-channels [-G] val: Set the number of GPIO channels (default: 16)\n"; 229 std::cerr << " --digital-channels [-B] val: Set the number of GPIO channels (default: 16)\n";
217 std::cerr << " --digital-channels [-G] val: Set the number of digital GPIO channels (default: 16)\n"; 230 std::cerr << " --receive-port [-R] val: Set the receive port (default: 9998)\n";
218 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";
219 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";
220 std::cerr << " --server-name [-s] val: Set the destination server name (default: '127.0.0.1')\n";
221 std::cerr << " --pru-file val: Set an optional external file to use for the PRU binary code\n"; 233 std::cerr << " --pru-file val: Set an optional external file to use for the PRU binary code\n";
222 std::cerr << " --verbose [-v]: Enable verbose logging information\n"; 234 std::cerr << " --verbose [-v]: Enable verbose logging information\n";
223 } 235 }
224 236