# HG changeset patch # User Giulio Moro # Date 1430409521 -3600 # Node ID c98863e63174c8ae31535d98eb8b70377387647a # Parent 31503d9de1019a34e8413a173712d112e837f319 Renamed matrixGpio to digital and matrix to analog diff -r 31503d9de101 -r c98863e63174 core/PRU.cpp --- a/core/PRU.cpp Thu Apr 30 16:02:47 2015 +0100 +++ b/core/PRU.cpp Thu Apr 30 16:58:41 2015 +0100 @@ -16,7 +16,7 @@ #include "../include/PRU.h" #include "../include/prussdrv.h" #include "../include/pruss_intc_mapping.h" -#include "../include/matrix_gpio_mapping.h" +#include "../include/digital_gpio_mapping.h" #include "../include/GPIOcontrol.h" #include "../include/render.h" #include "../include/pru_rtaudio_bin.h" @@ -42,8 +42,8 @@ #define PRU_MEM_DAC_OFFSET 0x0 // Offset within PRU0 RAM #define PRU_MEM_DAC_LENGTH 0x2000 // Length of ADC+DAC memory, in bytes #define PRU_MEM_COMM_OFFSET 0x0 // Offset within PRU-SHARED RAM -#define PRU_MEM_MATRIX_GPIO_OFFSET 0x1000 //Offset within PRU-SHARED RAM -#define MEM_MATRIX_GPIO_BUFFER1_OFFSET 0x400 //Start pointer to MATRIX_GPIO_BUFFER1, which is 256 words. +#define PRU_MEM_DIGITAL_OFFSET 0x1000 //Offset within PRU-SHARED RAM +#define MEM_DIGITAL_BUFFER1_OFFSET 0x400 //Start pointer to DIGITAL_BUFFER1, which is 256 words. // 256 is the maximum number of frames allowed #define PRU_SHOULD_STOP 0 #define PRU_CURRENT_BUFFER 1 @@ -56,9 +56,9 @@ #define PRU_FRAME_COUNT 8 #define PRU_USE_SPI 9 #define PRU_SPI_NUM_CHANNELS 10 -#define PRU_USE_GPIO_MATRIX 11 +#define PRU_USE_GPIO_ANALOG 11 -short int matrixGpioPins[NUM_MATRIX_GPIOS]={ +short int digitalPins[NUM_DIGITALS]={ GPIO_NO_BIT_0, GPIO_NO_BIT_1, GPIO_NO_BIT_2, @@ -127,7 +127,7 @@ // viewed on a scope. If include_led is set, // user LED 3 on the BBB is taken over by the PRU // to indicate activity -int PRU::prepareGPIO(int use_spi, int use_matrix_gpio, int include_test_pin, int include_led) +int PRU::prepareGPIO(int use_spi, int use_digital, int include_test_pin, int include_led) { if(use_spi) { // Prepare DAC CS/ pin: output, high to begin @@ -165,25 +165,25 @@ spi_enabled = true; } - if(use_matrix_gpio){ - printf("gNumMatrixGpioChannels: %d;\n",gNumMatrixGpioChannels); - for(int i=0; i 65535) out = 65535; pru_buffer_spi_dac[n] = (uint16_t)out; } - if(matrix_gpio_enabled){ // keep track of past matrix_gpio values - for(unsigned int n = 0; n < matrix_gpio_buffer_frames; n++){ - matrixGpioBufferTemp[n]=matrixGpioBuffer0[n]; + if(digital_enabled){ // keep track of past digital values + for(unsigned int n = 0; n < digital_buffer_frames; n++){ + digitalBufferTemp[n]=digitalBuffer0[n]; } } } else - render(0, 0, audio_buffer_frames, audioInBuffer, audioOutBuffer, 0, 0, 0); // we still pass matrixGpioBuffer, just it is unused + render(0, 0, audio_buffer_frames, audioInBuffer, audioOutBuffer, 0, 0, 0); // we still pass digitalBuffer, just it is unused // Convert float back to short for(unsigned int n = 0; n < 2 * audio_buffer_frames; n++) { int out = audioOutBuffer[n] * 32768.0; @@ -545,37 +545,37 @@ if(spi_enabled) { for(unsigned int n = 0; n < spi_num_channels * spi_buffer_frames; n++) - matrixInBuffer[n] = (float)pru_buffer_spi_adc[n + spi_buffer_frames * spi_num_channels] / 65536.0; + analogInBuffer[n] = (float)pru_buffer_spi_adc[n + spi_buffer_frames * spi_num_channels] / 65536.0; - //use past matrix_gpio values to initialize the array properly: + //use past digital values to initialize the array properly: //- pins previously set as outputs will keep their previously set output value, //- pins previously set as inputs will carry the newly read input value - if(matrix_gpio_enabled){ - for(unsigned int n = 0; n < matrix_gpio_buffer_frames; n++){ - uint16_t inputs=matrixGpioBufferTemp[n]&0xffff;//half-word, has 1 for inputs and 0 for outputs + if(digital_enabled){ + for(unsigned int n = 0; n < digital_buffer_frames; n++){ + uint16_t inputs=digitalBufferTemp[n]&0xffff;//half-word, has 1 for inputs and 0 for outputs uint16_t outputs=~inputs; //half-word has 1 for outputs and one for inputs; - matrixGpioBuffer1[n]=(matrixGpioBufferTemp[n]&(outputs<<16))| //keep output values set in previous matrixGpioBuffer1[n] - (matrixGpioBuffer1[n]&(inputs<<16)) | //inputs from current matrixGpioBuffer1[n]; - (matrixGpioBufferTemp[n]&(inputs)); //keep pin configuration from previous matrixGpioBuffer1[n] -// matrixGpioBuffer1[n]=matrixGpioBufferTemp[n]; //ignores inputs + digitalBuffer1[n]=(digitalBufferTemp[n]&(outputs<<16))| //keep output values set in previous digitalBuffer1[n] + (digitalBuffer1[n]&(inputs<<16)) | //inputs from current digitalBuffer1[n]; + (digitalBufferTemp[n]&(inputs)); //keep pin configuration from previous digitalBuffer1[n] +// digitalBuffer1[n]=digitalBufferTemp[n]; //ignores inputs } } - render(spi_buffer_frames, matrix_gpio_buffer_frames, audio_buffer_frames, audioInBuffer, audioOutBuffer, - matrixInBuffer, matrixOutBuffer, matrixGpioBuffer1); + render(spi_buffer_frames, digital_buffer_frames, audio_buffer_frames, audioInBuffer, audioOutBuffer, + analogInBuffer, analogOutBuffer, digitalBuffer1); for(unsigned int n = 0; n < spi_num_channels * spi_buffer_frames; n++) { - int out = matrixOutBuffer[n] * 65536.0; + int out = analogOutBuffer[n] * 65536.0; if(out < 0) out = 0; else if(out > 65535) out = 65535; pru_buffer_spi_dac[n + spi_buffer_frames * spi_num_channels] = (uint16_t)out; } - if(matrix_gpio_enabled){ // keep track of past matrix_gpio values - for(unsigned int n = 0; n < matrix_gpio_buffer_frames; n++){ - matrixGpioBufferTemp[n]=matrixGpioBuffer1[n]; + if(digital_enabled){ // keep track of past digital values + for(unsigned int n = 0; n < digital_buffer_frames; n++){ + digitalBufferTemp[n]=digitalBuffer1[n]; } } } else - render(0, 0, audio_buffer_frames, audioInBuffer, audioOutBuffer, 0, 0, 0); // we still pass matrixGpioBuffer, just it is unused + render(0, 0, audio_buffer_frames, audioInBuffer, audioOutBuffer, 0, 0, 0); // we still pass digitalBuffer, just it is unused // Convert float back to short for(unsigned int n = 0; n < 2 * audio_buffer_frames; n++) { @@ -594,11 +594,11 @@ // Tell PRU to stop pru_buffer_comm[PRU_SHOULD_STOP] = 1; - free(matrixOutBuffer); + free(analogOutBuffer); free(audioInBuffer); free(audioOutBuffer); - free(matrixInBuffer); - free(matrixGpioBufferTemp); + free(analogInBuffer); + free(digitalBufferTemp); } // Wait for an interrupt from the PRU indicate it is finished diff -r 31503d9de101 -r c98863e63174 core/RTAudio.cpp --- a/core/RTAudio.cpp Thu Apr 30 16:02:47 2015 +0100 +++ b/core/RTAudio.cpp Thu Apr 30 16:58:41 2015 +0100 @@ -61,21 +61,21 @@ int gAmplifierMutePin = -1; int gAmplifierShouldBeginMuted = 0; -// Number of audio and matrix channels, globally accessible -// At least gNumMatrixChannels and gNumMatrixGpioChannels need to be global to be used -// by the analogRead() and analogWrite() and the digital macros without creating +// Number of audio and analog channels, globally accessible +// At least gNumAnalogChannels and gNumDigitalChannels need to be global to be used +// by the AnalogRead() and AnalogWrite() and the digital macros without creating // extra confusion in their use cases by passing this argument int gNumAudioChannels = 0; -int gNumMatrixChannels = 0; -int gNumMatrixGpioChannels = 0; +int gNumAnalogChannels = 0; +int gNumDigitalChannels = 0; // initAudio() prepares the infrastructure for running PRU-based real-time // audio, but does not actually start the calculations. // periodSize indicates the number of _sensor_ frames per period: the audio period size // is twice this value. In total, the audio latency in frames will be 4*periodSize, // plus any latency inherent in the ADCs and DACs themselves. -// useMatrix indicates whether to enable the ADC and DAC or just use the audio codec. -// numMatrixChannels indicates how many ADC and DAC channels to use. +// useAnalog indicates whether to enable the ADC and DAC or just use the audio codec. +// numAnalogChannels indicates how many ADC and DAC channels to use. // userData is an opaque pointer which will be passed through to the initialise_render() // function for application-specific use // @@ -91,10 +91,10 @@ if(gRTAudioVerbose) { cout << "Starting with period size " << settings->periodSize << "; "; - if(settings->useMatrix) - cout << "matrix enabled\n"; + if(settings->useAnalog) + cout << "analog enabled\n"; else - cout << "matrix disabled\n"; + cout << "analog disabled\n"; cout << "DAC level " << settings->dacLevel << "dB; ADC level " << settings->adcLevel; cout << "dB; headphone level " << settings->headphoneLevel << "dB\n"; if(settings->beginMuted) @@ -122,21 +122,21 @@ } } - // Limit the matrix channels to sane values - if(settings->numMatrixChannels >= 8) - settings->numMatrixChannels = 8; - else if(settings->numMatrixChannels >= 4) - settings->numMatrixChannels = 4; + // Limit the analog channels to sane values + if(settings->numAnalogChannels >= 8) + settings->numAnalogChannels = 8; + else if(settings->numAnalogChannels >= 4) + settings->numAnalogChannels = 4; else - settings->numMatrixChannels = 2; + settings->numAnalogChannels = 2; // Sanity check the combination of channels and period size - if(settings->numMatrixChannels <= 4 && settings->periodSize < 2) { - cout << "Error: " << settings->numMatrixChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; + if(settings->numAnalogChannels <= 4 && settings->periodSize < 2) { + cout << "Error: " << settings->numAnalogChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; return 1; } - if(settings->numMatrixChannels <= 2 && settings->periodSize < 4) { - cout << "Error: " << settings->numMatrixChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; + if(settings->numAnalogChannels <= 2 && settings->periodSize < 4) { + cout << "Error: " << settings->numAnalogChannels << " channels and period size of " << settings->periodSize << " not supported.\n"; return 1; } @@ -144,12 +144,12 @@ gPRU = new PRU(); gAudioCodec = new I2c_Codec(); - gNumMatrixGpioChannels = settings->useMatrixGpio ? settings->numMatrixGpioChannels : 0; //this is called here to make sure prepareGPIO initializes the appropriate GPIO pins - if(gPRU->prepareGPIO(settings->useMatrix, settings->useMatrixGpio, 1, 1)) { + gNumDigitalChannels = settings->useDigital ? settings->numDigitalChannels : 0; //this is called here to make sure prepareGPIO initializes the appropriate GPIO pins + if(gPRU->prepareGPIO(settings->useAnalog, settings->useDigital, 1, 1)) { cout << "Error: unable to prepare GPIO for PRU audio\n"; return 1; } - if(gPRU->initialise(0, settings->periodSize, settings->numMatrixChannels, true)) { + if(gPRU->initialise(0, settings->periodSize, settings->numAnalogChannels, true)) { cout << "Error: unable to initialise PRU\n"; return 1; } @@ -167,23 +167,23 @@ BeagleRT_setADCLevel(settings->adcLevel); BeagleRT_setHeadphoneLevel(settings->headphoneLevel); - // Initialise the rendering environment: pass the number of audio and matrix - // channels, the period size for matrix and audio, and the sample rates + // Initialise the rendering environment: pass the number of audio and analog + // channels, the period size for analog and audio, and the sample rates int audioPeriodSize = settings->periodSize * 2; float audioSampleRate = 44100.0; - float matrixSampleRate = 22050.0; - if(settings->useMatrix) { - audioPeriodSize = settings->periodSize * settings->numMatrixChannels / 4; - matrixSampleRate = audioSampleRate * 4.0 / (float)settings->numMatrixChannels; + float analogSampleRate = 22050.0; + if(settings->useAnalog) { + audioPeriodSize = settings->periodSize * settings->numAnalogChannels / 4; + analogSampleRate = audioSampleRate * 4.0 / (float)settings->numAnalogChannels; } gNumAudioChannels = 2; - gNumMatrixChannels = settings->useMatrix ? settings->numMatrixChannels : 0; - if(!initialise_render(gNumMatrixChannels, gNumMatrixGpioChannels, gNumAudioChannels, - settings->useMatrix ? settings->periodSize : 0, /* matrix period size */ + gNumAnalogChannels = settings->useAnalog ? settings->numAnalogChannels : 0; + if(!initialise_render(gNumAnalogChannels, gNumDigitalChannels, gNumAudioChannels, + settings->useAnalog ? settings->periodSize : 0, /* analog period size */ audioPeriodSize, - matrixSampleRate, audioSampleRate, + analogSampleRate, audioSampleRate, userData)) { cout << "Couldn't initialise audio rendering\n"; return 1; diff -r 31503d9de101 -r c98863e63174 core/RTAudioCommandLine.cpp --- a/core/RTAudioCommandLine.cpp Thu Apr 30 16:02:47 2015 +0100 +++ b/core/RTAudioCommandLine.cpp Thu Apr 30 16:58:41 2015 +0100 @@ -16,10 +16,10 @@ { {"period", 1, NULL, 'p'}, {"verbose", 0, NULL, 'v'}, - {"use-matrix", 1, NULL, 'm'}, - {"use-matrix-gpio", 1, NULL, 'g'}, - {"matrix-channels", 1, NULL, 'C'}, - {"matrix-gpio-channels", 1, NULL, 'G'}, + {"use-analog", 1, NULL, 'm'}, + {"use-analog-gpio", 1, NULL, 'g'}, + {"analog-channels", 1, NULL, 'C'}, + {"analog-gpio-channels", 1, NULL, 'G'}, {"mute-speaker", 1, NULL, 'M'}, {"dac-level", 1, NULL, 'D'}, {"adc-level", 1, NULL, 'A'}, @@ -39,10 +39,10 @@ settings->dacLevel = DEFAULT_DAC_LEVEL; settings->adcLevel = DEFAULT_ADC_LEVEL; settings->headphoneLevel = DEFAULT_HP_LEVEL; - settings->useMatrix = 1; - settings->useMatrixGpio = 1; - settings->numMatrixChannels = 8; - settings->numMatrixGpioChannels = 16; + settings->useAnalog = 1; + settings->useDigital = 1; + settings->numAnalogChannels = 8; + settings->numDigitalChannels = 16; settings->verbose = 0; settings->pruFilename[0]='\0'; settings->codecI2CAddress = CODEC_I2C_ADDRESS; @@ -128,29 +128,29 @@ settings->verbose = 1; break; case 'm': - settings->useMatrix = atoi(optarg); + settings->useAnalog = atoi(optarg); break; case 'g': - settings->useMatrixGpio = atoi(optarg); - settings->numMatrixGpioChannels = 0; + 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 'G': - settings->numMatrixGpioChannels = atoi(optarg); - if(settings->numMatrixGpioChannels >= 16) - settings->numMatrixGpioChannels = 16; - else if (settings->numMatrixGpioChannels < 1){ - settings->numMatrixGpioChannels = 0; - settings->useMatrixGpio = 0; //TODO: this actually works only if -G 0 is specified after -g 1. - //No worries, though: disabling numMatrixGpio will only prevent the pins from being exported. + 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': @@ -182,15 +182,15 @@ // 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 << " --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-matrix [-m] val: Set whether to use ADC/DAC matrix (default: yes)\n"; - std::cerr << " --use-gpio-matrix [-g] val: Set whether to use GPIO matrix (default: yes)\n"; - std::cerr << " --matrix-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; - std::cerr << " --matrix-gpio-channels [-G] val: Set the number of GPIO channels (default: 16)\n"; + std::cerr << " --use-analog [-m] val: Set whether to use ADC/DAC analog (default: yes)\n"; + std::cerr << " --use-gpio-analog [-g] val: Set whether to use GPIO analog (default: yes)\n"; + std::cerr << " --analog-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; + std::cerr << " --analog-gpio-channels [-G] val: Set the number of GPIO channels (default: 16)\n"; std::cerr << " --pru-file [-P] val: Set an optional external file to use for the PRU binary code\n"; std::cerr << " --verbose [-v]: Enable verbose logging information\n"; } diff -r 31503d9de101 -r c98863e63174 include/PRU.h --- a/include/PRU.h Thu Apr 30 16:02:47 2015 +0100 +++ b/include/PRU.h Thu Apr 30 16:58:41 2015 +0100 @@ -27,7 +27,7 @@ ~PRU(); // Prepare the GPIO pins needed for the PRU - int prepareGPIO(int use_spi, int use_matrix_gpio, int include_test_pin, int include_led); + int prepareGPIO(int use_spi, int use_digital, int include_test_pin, int include_led); // Clean up the GPIO at the end void cleanupGPIO(); @@ -56,7 +56,7 @@ int pru_number; // Which PRU we use bool running; // Whether the PRU is running bool spi_enabled; // Whether SPI ADC and DAC are used - bool matrix_gpio_enabled; // Whether Matrix GPIO is used + bool digital_enabled; // Whether digital is used bool gpio_enabled; // Whether GPIO has been prepared bool led_enabled; // Whether a user LED is enabled bool gpio_test_pin_enabled; // Whether the test pin was also enabled @@ -65,11 +65,11 @@ volatile uint32_t *pru_buffer_comm; uint16_t *pru_buffer_spi_dac; uint16_t *pru_buffer_spi_adc; - uint32_t *pru_buffer_matrix_gpio; + uint32_t *pru_buffer_digital; int16_t *pru_buffer_audio_dac; int16_t *pru_buffer_audio_adc; unsigned int spi_buffer_frames; - unsigned int matrix_gpio_buffer_frames; + unsigned int digital_buffer_frames; unsigned int audio_buffer_frames; int xenomai_gpio_fd; // File descriptor for /dev/mem for fast GPIO diff -r 31503d9de101 -r c98863e63174 include/RTAudio.h --- a/include/RTAudio.h Thu Apr 30 16:02:47 2015 +0100 +++ b/include/RTAudio.h Thu Apr 30 16:58:41 2015 +0100 @@ -39,15 +39,15 @@ // real-time audio system typedef struct { // These items might be adjusted by the user: - int periodSize; // Number of (matrix) frames per period; audio is twice this + int periodSize; // Number of (analog) frames per period; audio is twice this int beginMuted; // Whether to begin with the speakers muted float dacLevel; // Level for the audio DAC output float adcLevel; // Level for the audio ADC input float headphoneLevel; // Level for the headphone output - int useMatrix; // Whether to use the matrix - int useMatrixGpio; // Whether to use the 16 programmable GPIOs - int numMatrixChannels; // How many channels for the ADC and DAC - int numMatrixGpioChannels; // How many channels for the GPIOs + int useAnalog; // Whether to use the analog + int useDigital; // Whether to use the 16 programmable GPIOs + int numAnalogChannels; // How many channels for the ADC and DAC + int numDigitalChannels; // How many channels for the GPIOs int verbose; // Whether to use verbose logging char pruFilename[MAX_PRU_FILENAME_LENGTH]; //the external .bin file to load. If empty will use PRU code from pru_rtaudio_bin.h // These items are hardware-dependent and should only be changed diff -r 31503d9de101 -r c98863e63174 include/Utilities.h --- a/include/Utilities.h Thu Apr 30 16:02:47 2015 +0100 +++ b/include/Utilities.h Thu Apr 30 16:58:41 2015 +0100 @@ -9,18 +9,18 @@ #define UTILITIES_H_ extern int gNumAudioChannels; // How many audio channels are present -extern int gNumMatrixChannels; // How many matrix channels are present +extern int gNumAnalogChannels; // How many analog channels are present -// Macros for accessing the matrix values: usable _only_ within render() +// Macros for accessing the analog values: usable _only_ within render() -// Read an analog input from input pin p at frame f -#define analogRead(p, f) (matrixIn[(f)*gNumMatrixChannels + (p)]) -// Write an analog output frame at output pin p, frame f, to value v -#define analogWriteFrame(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (v)) -#define analogWrite(pin, frame, value) \ +// Read an Analog input from input pin p at frame f +#define AnalogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)]) +// Write an Analog output frame at output pin p, frame f, to value v +#define AnalogWriteFrame(p, f, v) (analogOut[(f)*gNumAnalogChannels + (p)] = (v)) +#define AnalogWrite(pin, frame, value) \ (({do {\ - for (int _privateI=(frame); _privateI>(bit))&1) #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) -//matrixGpio API: -#define setDigitalDirectionFrame(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction)) -#define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI #include "../include/Utilities.h" -#include "../include/matrix_gpio_mapping.h" +#include "../include/digital_gpio_mapping.h" // Mappings from pin numbers on PCB to actual DAC channels // This gives the DAC and ADC connectors the same effective pinout #define DAC_PIN0 6 @@ -32,19 +32,19 @@ #define ADC_PIN6 6 #define ADC_PIN7 7 -#define MATRIX_MAX 65535.0 +#define ANALOG_MAX 65535.0 extern int gNumAudioChannels; // How many audio channels are present -extern int gNumMatrixChannels; // How many matrix channels are present -extern int gNumMatrixGpioChannels; -bool initialise_render(int numMatrixChannels, int numMatrixGpioChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, +extern int gNumAnalogChannels; // How many analog channels are present +extern int gNumDigitalChannels; +bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels, + int numAnalogFramesPerPeriod, int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, + float analogSampleRate, float audioSampleRate, void *userData); -void render(int numMatrixFrames, int numAudioFrames, int numMatrixGpioFrames, float *audioIn, float *audioOut, - float *matrixIn, float *matrixOut, uint32_t *matrixGpio); +void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, + float *analogIn, float *analogOut, uint32_t *digital); void render_medium_prio(); void render_low_prio(); diff -r 31503d9de101 -r c98863e63174 projects/analogDigitalDemo/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/analogDigitalDemo/main.cpp Thu Apr 30 16:58:41 2015 +0100 @@ -0,0 +1,107 @@ +/* + * assignment1_crossover + * RTDSP 2015 + * + * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover + * using the BeagleBone Black. + * + * Andrew McPherson and Victor Zappi + * Queen Mary, University of London + */ + +#include +#include +#include +#include +#include +#include "../include/RTAudio.h" +#include +#include +#include + +using namespace std; + +// Handle Ctrl-C by requesting that the audio rendering stop +void interrupt_handler(int var) +{ + gShouldStop = true; +} + +// Print usage information +void usage(const char * processName) +{ + cerr << "Usage: " << processName << " [options]" << endl; + + BeagleRT_usage(); + + cerr << " --help [-h]: Print this menu\n"; +} + +int main(int argc, char *argv[]) +{ + RTAudioSettings settings; // Standard audio settings + float frequency = 1000.0; // Frequency of crossover + + struct option customOptions[] = + { + {"help", 0, NULL, 'h'}, + {"frequency", 1, NULL, 'f'}, + {NULL, 0, NULL, 0} + }; + + // Set default settings + BeagleRT_defaultSettings(&settings); + + // Parse command-line arguments + while (1) { + int c; + if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) + break; + switch (c) { + case 'h': + usage(basename(argv[0])); + exit(0); + case 'f': + frequency = atof(optarg); + if(frequency < 20.0) + frequency = 20.0; + if(frequency > 5000.0) + frequency = 5000.0; + break; + case '?': + default: + usage(basename(argv[0])); + exit(1); + } + } + + // Initialise the PRU audio device + if(BeagleRT_initAudio(&settings, &frequency) != 0) { + cout << "Error: unable to initialise audio" << endl; + return -1; + } + + // Start the audio device running + if(BeagleRT_startAudio()) { + cout << "Error: unable to start real-time audio" << endl; + return -1; + } + + // Set up interrupt handler to catch Control-C + signal(SIGINT, interrupt_handler); + signal(SIGTERM, interrupt_handler); + + // Run until told to stop + while(!gShouldStop) { + usleep(100000); + } + + // Stop the audio device + BeagleRT_stopAudio(); + + // Clean up any resources allocated for audio + BeagleRT_cleanupAudio(); + + // All done! + return 0; +} diff -r 31503d9de101 -r c98863e63174 projects/analogDigitalDemo/render.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/analogDigitalDemo/render.cpp Thu Apr 30 16:58:41 2015 +0100 @@ -0,0 +1,81 @@ +/* + * + * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover + * using the BeagleBone Black. + * + * Andrew McPherson and Victor Zappi + * Queen Mary, University of London + */ + +#include "../include/render.h" +#include +#include + +/* TASK: declare any global variables you need here */ + +// initialise_render() is called once before the audio rendering starts. +// Use it to perform any initialisation and allocation which is dependent +// on the period size or sample rate. +// +// userData holds an opaque pointer to a data structure that was passed +// in from the call to initAudio(). +// +// Return true on success; returning false halts the program. +int gNumMatrixGpioFrames=0; +bool initialise_render(int numMatrixChannels, int numMatrixGpioChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) +{ + gNumMatrixChannels=numMatrixChannels; + return true; +} + +// render() is called regularly at the highest priority by the audio engine. +// Input and output are given from the audio hardware and the other +// ADCs and DACs (if available). If only audio is available, numMatrixFrames +// will be 0. + +long int gCountFrames=0; +void render(int numMatrixFrames, int numMatrixGpioFrames, int numAudioFrames, float *audioIn, float *audioOut, + float *matrixIn, float *matrixOut, uint32_t *matrixGpio) +/* + * Hey, expect buffer underruns to happen here, as we are doing lots of printfs + * */ +{ + gNumMatrixGpioFrames=numMatrixGpioFrames; + if(gCountFrames==0){ //this will be executed only on the first call to render(), but the bits will go through this cycle for every subsequent buffer + // that is, P8_29 will pulse at the beginning of each buffer + } + for(int i=1; i -#include -#include -#include -#include -#include "../include/RTAudio.h" -#include -#include -#include - -using namespace std; - -// Handle Ctrl-C by requesting that the audio rendering stop -void interrupt_handler(int var) -{ - gShouldStop = true; -} - -// Print usage information -void usage(const char * processName) -{ - cerr << "Usage: " << processName << " [options]" << endl; - - BeagleRT_usage(); - - cerr << " --help [-h]: Print this menu\n"; -} - -int main(int argc, char *argv[]) -{ - RTAudioSettings settings; // Standard audio settings - float frequency = 1000.0; // Frequency of crossover - - struct option customOptions[] = - { - {"help", 0, NULL, 'h'}, - {"frequency", 1, NULL, 'f'}, - {NULL, 0, NULL, 0} - }; - - // Set default settings - BeagleRT_defaultSettings(&settings); - - // Parse command-line arguments - while (1) { - int c; - if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) - break; - switch (c) { - case 'h': - usage(basename(argv[0])); - exit(0); - case 'f': - frequency = atof(optarg); - if(frequency < 20.0) - frequency = 20.0; - if(frequency > 5000.0) - frequency = 5000.0; - break; - case '?': - default: - usage(basename(argv[0])); - exit(1); - } - } - - // Initialise the PRU audio device - if(BeagleRT_initAudio(&settings, &frequency) != 0) { - cout << "Error: unable to initialise audio" << endl; - return -1; - } - - // Start the audio device running - if(BeagleRT_startAudio()) { - cout << "Error: unable to start real-time audio" << endl; - return -1; - } - - // Set up interrupt handler to catch Control-C - signal(SIGINT, interrupt_handler); - signal(SIGTERM, interrupt_handler); - - // Run until told to stop - while(!gShouldStop) { - usleep(100000); - } - - // Stop the audio device - BeagleRT_stopAudio(); - - // Clean up any resources allocated for audio - BeagleRT_cleanupAudio(); - - // All done! - return 0; -} diff -r 31503d9de101 -r c98863e63174 projects/matrix_gpio_demo/render.cpp --- a/projects/matrix_gpio_demo/render.cpp Thu Apr 30 16:02:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * - * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover - * using the BeagleBone Black. - * - * Andrew McPherson and Victor Zappi - * Queen Mary, University of London - */ - -#include "../include/render.h" -#include -#include - -/* TASK: declare any global variables you need here */ - -// initialise_render() is called once before the audio rendering starts. -// Use it to perform any initialisation and allocation which is dependent -// on the period size or sample rate. -// -// userData holds an opaque pointer to a data structure that was passed -// in from the call to initAudio(). -// -// Return true on success; returning false halts the program. -int gNumMatrixGpioFrames=0; -bool initialise_render(int numMatrixChannels, int numMatrixGpioChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) -{ - gNumMatrixChannels=numMatrixChannels; - return true; -} - -// render() is called regularly at the highest priority by the audio engine. -// Input and output are given from the audio hardware and the other -// ADCs and DACs (if available). If only audio is available, numMatrixFrames -// will be 0. - -long int gCountFrames=0; -void render(int numMatrixFrames, int numMatrixGpioFrames, int numAudioFrames, float *audioIn, float *audioOut, - float *matrixIn, float *matrixOut, uint32_t *matrixGpio) -/* - * Hey, expect buffer underruns to happen here, as we are doing lots of printfs - * */ -{ - gNumMatrixGpioFrames=numMatrixGpioFrames; - if(gCountFrames==0){ //this will be executed only on the first call to render(), but the bits will go through this cycle for every subsequent buffer - // that is, P8_29 will pulse at the beginning of each buffer - } - for(int i=1; i