Mercurial > hg > beaglert
diff 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 |
line wrap: on
line diff
--- a/core/RTAudioCommandLine.cpp Sun Feb 08 00:20:01 2015 +0000 +++ b/core/RTAudioCommandLine.cpp Fri Jul 17 15:28:18 2015 +0100 @@ -9,38 +9,66 @@ #include <cstdlib> #include <cstring> #include <getopt.h> +#include "../include/BeagleRT.h" -#include "../include/RTAudio.h" +#ifndef OPT_PRU_FILE +#define OPT_PRU_FILE 176 // this is an extended ASCII code +#endif + +enum { + kAmplifierMutePin = 61 // P8-26 controls amplifier mute +}; // Default command-line options for RTAudio struct option gDefaultLongOptions[] = { {"period", 1, NULL, 'p'}, {"verbose", 0, NULL, 'v'}, - {"use-matrix", 1, NULL, 'm'}, - {"matrix-channels", 1, NULL, 'C'}, + {"use-analog", 1, NULL, 'N'}, + {"use-digital", 1, NULL, 'G'}, + {"analog-channels", 1, NULL, 'C'}, + {"digital-channels", 1, NULL, 'B'}, {"mute-speaker", 1, NULL, 'M'}, {"dac-level", 1, NULL, 'D'}, {"adc-level", 1, NULL, 'A'}, {"hp-level", 1, NULL, 'H'}, + {"receive-port", 1, NULL, 'R'}, + {"transmit-port", 1, NULL, 'T'}, + {"server-name", 1, NULL, 'S'}, + {"pru-file", 1, NULL, OPT_PRU_FILE}, {NULL, 0, NULL, 0} }; -const char gDefaultShortOptions[] = "p:vm:M:C:D:A:H:"; +const char gDefaultShortOptions[] = "p:vN:M:C:D:A:H:G:B:R:T:S:"; -// This function sets the default settings for the RTAudioSettings structure -void BeagleRT_defaultSettings(RTAudioSettings *settings) +// This function sets the default settings for the BeagleRTInitSettings structure +void BeagleRT_defaultSettings(BeagleRTInitSettings *settings) { // Set default values for settings settings->periodSize = 8; + settings->useAnalog = 1; + settings->useDigital = 1; + settings->numAnalogChannels = 8; + settings->numDigitalChannels = 16; + settings->beginMuted = 0; settings->dacLevel = DEFAULT_DAC_LEVEL; settings->adcLevel = DEFAULT_ADC_LEVEL; settings->headphoneLevel = DEFAULT_HP_LEVEL; - settings->useMatrix = 1; - settings->numMatrixChannels = 8; + settings->verbose = 0; + settings->pruFilename[0] = '\0'; + + // These two deliberately have no command-line flags by default. + // A given program might prefer one mode or another, but it's unlikely + // the user would want to switch at runtime + settings->interleave = 1; + settings->analogOutputsPersist = 1; + settings->codecI2CAddress = CODEC_I2C_ADDRESS; + settings->receivePort = 9998; + settings->transmitPort = 9999; + strcpy(settings->serverName, "127.0.0.1"); settings->ampMutePin = kAmplifierMutePin; } @@ -50,7 +78,7 @@ // be stored in settings, otherwise arguments will be returned // as getopt() normally does. -int BeagleRT_getopt_long(int argc, char *argv[], const char *customShortOptions, const struct option *customLongOptions, RTAudioSettings *settings) +int BeagleRT_getopt_long(int argc, char *argv[], const char *customShortOptions, const struct option *customLongOptions, BeagleRTInitSettings *settings) { static int firstRun = 1; static char totalShortOptions[256]; @@ -122,17 +150,31 @@ case 'v': settings->verbose = 1; break; - case 'm': - settings->useMatrix = atoi(optarg); + case 'N': + settings->useAnalog = atoi(optarg); + break; + case 'G': + settings->useDigital = atoi(optarg); + settings->numDigitalChannels = 0; break; case 'C': - settings->numMatrixChannels = atoi(optarg); - if(settings->numMatrixChannels >= 8) - settings->numMatrixChannels = 8; - else if(settings->numMatrixChannels >= 4) - settings->numMatrixChannels = 4; + settings->numAnalogChannels = atoi(optarg); + if(settings->numAnalogChannels >= 8) + settings->numAnalogChannels = 8; + else if(settings->numAnalogChannels >= 4) + settings->numAnalogChannels = 4; else - settings->numMatrixChannels = 2; + settings->numAnalogChannels = 2; + break; + case 'B': + settings->numDigitalChannels = atoi(optarg); + if(settings->numDigitalChannels >= 16) + settings->numDigitalChannels = 16; + else if (settings->numDigitalChannels < 1){ + settings->numDigitalChannels = 0; + settings->useDigital = 0; //TODO: this actually works only if -G 0 is specified after -g 1. + //No worries, though: disabling numDigital will only prevent the pins from being exported. + } break; case 'M': settings->beginMuted = atoi(optarg); @@ -146,6 +188,25 @@ case 'H': settings->headphoneLevel = atof(optarg); break; + case 'R': + settings->receivePort = atoi(optarg); + break; + case 'T': + settings->transmitPort = atoi(optarg); + break; + case 'S': + if(strlen(optarg)<MAX_SERVERNAME_LENGTH) + strcpy(settings->serverName, optarg); + else + std::cerr << "Warning: server name is too long (>" << MAX_SERVERNAME_LENGTH << " characters)." + " Using default severName Instead ( " << settings->serverName << " ).\n"; + break; + case OPT_PRU_FILE: + if(strlen(optarg) < MAX_PRU_FILENAME_LENGTH) + strcpy(settings->pruFilename, optarg); + else + std::cerr << "Warning: filename for the PRU code is too long (>" << MAX_PRU_FILENAME_LENGTH << " characters). Using embedded PRU code instead\n"; + break; case '?': default: return c; @@ -157,12 +218,19 @@ // Call from within your own usage function void BeagleRT_usage() { - std::cerr << " --period [-p] period: Set the hardware period (buffer) size in matrix samples\n"; - std::cerr << " --dac-level [-D] dBs: Set the DAC output level (0dB max; -63.5dB min)\n"; - std::cerr << " --adc-level [-A] dBs: Set the ADC input level (0dB max; -12dB min)\n"; - std::cerr << " --hp-level [-H] dBs: Set the headphone output level (0dB max; -63.5dB min)\n"; - std::cerr << " --mute-speaker [-M] val: Set whether to mute the speaker initially (default: no)\n"; - std::cerr << " --use-matrix [-m] val: Set whether to use ADC/DAC matrix\n"; - std::cerr << " --matrix-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; - std::cerr << " --verbose [-v]: Enable verbose logging information\n"; + std::cerr << " --period [-p] period: Set the hardware period (buffer) size in analog samples\n"; + std::cerr << " --dac-level [-D] dBs: Set the DAC output level (0dB max; -63.5dB min)\n"; + std::cerr << " --adc-level [-A] dBs: Set the ADC input level (0dB max; -12dB min)\n"; + std::cerr << " --hp-level [-H] dBs: Set the headphone output level (0dB max; -63.5dB min)\n"; + std::cerr << " --mute-speaker [-M] val: Set whether to mute the speaker initially (default: no)\n"; + std::cerr << " --use-analog [-N] val: Set whether to use ADC/DAC analog (default: yes)\n"; + std::cerr << " --use-digital [-G] val: Set whether to use digital GPIO channels (default: yes)\n"; + std::cerr << " --analog-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; + std::cerr << " --digital-channels [-B] val: Set the number of GPIO channels (default: 16)\n"; + std::cerr << " --receive-port [-R] val: Set the receive port (default: 9998)\n"; + std::cerr << " --transmit-port [-T] val: Set the transmit port (default: 9999)\n"; + std::cerr << " --server-name [-S] val: Set the destination server name (default: '127.0.0.1')\n"; + std::cerr << " --pru-file val: Set an optional external file to use for the PRU binary code\n"; + std::cerr << " --verbose [-v]: Enable verbose logging information\n"; } +