Mercurial > hg > beaglert
changeset 305:b57d76dcc9ae prerelease
Merge
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 27 May 2016 17:51:34 +0100 |
parents | d2b7df6b355b (current diff) 421a69d42943 (diff) |
children | 132fc61893af |
files | |
diffstat | 19 files changed, 60 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/core/OSCClient.cpp Fri May 27 17:49:05 2016 +0100 +++ b/core/OSCClient.cpp Fri May 27 17:51:34 2016 +0100 @@ -22,7 +22,7 @@ void OSCClient::createAuxTasks(){ char name [30]; sprintf (name, "OSCSendTask %i", port); - OSCSendTask = Bela_createAuxiliaryTask(sendQueue, BEAGLERT_AUDIO_PRIORITY-5, name, this, true); + OSCSendTask = Bela_createAuxiliaryTask(sendQueue, BELA_AUDIO_PRIORITY-5, name, this, true); } void OSCClient::queueMessage(oscpkt::Message msg){
--- a/core/OSCServer.cpp Fri May 27 17:49:05 2016 +0100 +++ b/core/OSCServer.cpp Fri May 27 17:51:34 2016 +0100 @@ -21,7 +21,7 @@ void OSCServer::createAuxTasks(){ char name [30]; sprintf (name, "OSCRecieveTask %i", port); - OSCRecieveTask = Bela_createAuxiliaryTask(OSCServer::checkMessages, BEAGLERT_AUDIO_PRIORITY-5, name, this, true); + OSCRecieveTask = Bela_createAuxiliaryTask(OSCServer::checkMessages, BELA_AUDIO_PRIORITY-5, name, this, true); } void OSCServer::messageCheck(){
--- a/core/PRU.cpp Fri May 27 17:49:05 2016 +0100 +++ b/core/PRU.cpp Fri May 27 17:51:34 2016 +0100 @@ -64,6 +64,7 @@ #define PRU_USE_DIGITAL 11 #define PRU_PRU_NUMBER 12 #define PRU_MUX_CONFIG 13 +#define PRU_MUX_END_CHANNEL 14 short int digitalPins[NUM_DIGITALS] = { GPIO_NO_BIT_0, @@ -113,6 +114,7 @@ PRU::PRU(BelaContext *input_context) : context(input_context), pru_number(0), running(false), analog_enabled(false), digital_enabled(false), gpio_enabled(false), led_enabled(false), + mux_channels(0), gpio_test_pin_enabled(false), pru_buffer_comm(0), pru_buffer_spi_dac(0), pru_buffer_spi_adc(0), pru_buffer_digital(0), pru_buffer_audio_dac(0), pru_buffer_audio_adc(0), @@ -290,6 +292,7 @@ } pru_number = pru_num; + this->mux_channels = mux_channels; /* Initialize structure used by prussdrv_pruintc_intc */ /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */ @@ -478,7 +481,7 @@ // Main loop to read and write data from/to PRU void PRU::loop(RT_INTR *pru_interrupt, void *userData) { -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS RTIME irqTimeout = PRU_SAMPLE_INTERVAL_NS * 1024; // Timeout for PRU interrupt: about 10ms, much longer than any expected period #else // Polling interval is 1/4 of the period @@ -492,7 +495,7 @@ // directions and output values at something other than defaults. if(analog_enabled) { - if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { + if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { // Remember the content of the last_analog_out_frame for(unsigned int ch = 0; ch < context->analogChannels; ch++){ last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch]; @@ -510,7 +513,7 @@ // uint32_t testCount = 0; // RTIME startTime = rt_timer_read(); -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS int result; #else // Which buffer the PRU was last processing @@ -518,7 +521,7 @@ #endif while(!gShouldStop) { -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS // Wait for PRU to move to change buffers; // PRU will send an interrupts which we wait for rt_intr_enable(pru_interrupt); @@ -582,11 +585,19 @@ context->audioIn[n] = (float)pru_buffer_audio_adc[n + pru_audio_offset] / 32768.0f; if(analog_enabled) { + if(mux_channels != 0) { + // If multiplexer is enabled, find out which channels we have by pulling out + // the place that it ended. + // int lastMuxChannel = pru_buffer_comm[PRU_MUX_END_CHANNEL]; + + // TODO + } + // TODO: NEON for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++) context->analogIn[n] = (float)pru_buffer_spi_adc[n + pru_spi_offset] / 65536.0f; - if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { + if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { // Initialize the output buffer with the values that were in the last frame of the previous output for(unsigned int ch = 0; ch < context->analogChannels; ch++){ for(unsigned int n = 0; n < context->analogFrames; n++){ @@ -623,7 +634,7 @@ // *********************** if(analog_enabled) { - if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { + if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { // Remember the content of the last_analog_out_frame for(unsigned int ch = 0; ch < context->analogChannels; ch++){ last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch]; @@ -669,7 +680,7 @@ // break; } -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS // Turn off the interrupt for the PRU if it isn't already off rt_intr_disable(pru_interrupt); #endif
--- a/core/RTAudio.cpp Fri May 27 17:49:05 2016 +0100 +++ b/core/RTAudio.cpp Fri May 27 17:51:34 2016 +0100 @@ -51,12 +51,12 @@ bool autoSchedule; } InternalAuxiliaryTask; -const char gRTAudioThreadName[] = "beaglert-audio"; -const char gRTAudioInterruptName[] = "beaglert-pru-irq"; +const char gRTAudioThreadName[] = "bela-audio"; +const char gRTAudioInterruptName[] = "bela-pru-irq"; // Real-time tasks and objects RT_TASK gRTAudioThread; -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS RT_INTR gRTAudioInterrupt; #endif PRU *gPRU = 0; @@ -199,9 +199,9 @@ // Set flags based on init settings if(settings->interleave) - gContext.flags |= BEAGLERT_FLAG_INTERLEAVED; + gContext.flags |= BELA_FLAG_INTERLEAVED; if(settings->analogOutputsPersist) - gContext.flags |= BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST; + gContext.flags |= BELA_FLAG_ANALOG_OUTPUTS_PERSIST; // Use PRU for audio gPRU = new PRU(&gContext); @@ -285,7 +285,7 @@ } } -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS gPRU->loop(&gRTAudioInterrupt, gUserData); #else gPRU->loop(0, gUserData); @@ -303,7 +303,7 @@ } // Create a calculation loop which can run independently of the audio, at a different -// (equal or lower) priority. Audio priority is defined in BEAGLERT_AUDIO_PRIORITY; +// (equal or lower) priority. Audio priority is defined in BELA_AUDIO_PRIORITY; // priority should be generally be less than this. // Returns an (opaque) pointer to the created task on success; 0 on failure AuxiliaryTask Bela_createAuxiliaryTask(void (*functionToCall)(void* args), int priority, const char *name, void* args, bool autoSchedule) @@ -427,12 +427,12 @@ int Bela_startAudio() { // Create audio thread with high Xenomai priority - if(rt_task_create(&gRTAudioThread, gRTAudioThreadName, 0, BEAGLERT_AUDIO_PRIORITY, T_JOINABLE | T_FPU)) { + if(rt_task_create(&gRTAudioThread, gRTAudioThreadName, 0, BELA_AUDIO_PRIORITY, T_JOINABLE | T_FPU)) { cout << "Error: unable to create Xenomai audio thread" << endl; return -1; } -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS // Create an interrupt which the audio thread receives from the PRU int result = 0; if((result = rt_intr_create(&gRTAudioInterrupt, gRTAudioInterruptName, PRU_RTAUDIO_IRQ, I_NOAUTOENA)) != 0) { @@ -502,7 +502,7 @@ getAuxTasks().clear(); // Delete the audio task and its interrupt -#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS +#ifdef BELA_USE_XENOMAI_INTERRUPTS rt_intr_delete(&gRTAudioInterrupt); #endif rt_task_delete(&gRTAudioThread);
--- a/core/Scope.cpp Fri May 27 17:49:05 2016 +0100 +++ b/core/Scope.cpp Fri May 27 17:51:34 2016 +0100 @@ -31,8 +31,8 @@ socket.setPort(SCOPE_UDP_PORT); // setup the auxiliary tasks - scopeTriggerTask = Bela_createAuxiliaryTask(Scope::triggerTask, BEAGLERT_AUDIO_PRIORITY-2, "scopeTriggerTask", this, true); - scopeSendBufferTask = Bela_createAuxiliaryTask(Scope::sendBufferTask, BEAGLERT_AUDIO_PRIORITY-1, "scopeSendBufferTask", this); + scopeTriggerTask = Bela_createAuxiliaryTask(Scope::triggerTask, BELA_AUDIO_PRIORITY-2, "scopeTriggerTask", this, true); + scopeSendBufferTask = Bela_createAuxiliaryTask(Scope::sendBufferTask, BELA_AUDIO_PRIORITY-1, "scopeSendBufferTask", this); // send an OSC message to address /scope-setup // then wait 1 second for a reply on /scope-setup-reply
--- a/examples/d-box/StatusLED.h Fri May 27 17:49:05 2016 +0100 +++ b/examples/d-box/StatusLED.h Fri May 27 17:51:34 2016 +0100 @@ -8,6 +8,7 @@ #define STATUSLED_H_ #include <pthread.h> +#include <unistd.h> class StatusLED {
--- a/examples/d-box/logger.h Fri May 27 17:49:05 2016 +0100 +++ b/examples/d-box/logger.h Fri May 27 17:51:34 2016 +0100 @@ -11,6 +11,7 @@ #include <string.h> #include <pthread.h> #include <stdio.h> +#include <unistd.h> #include <fstream> // file handle #include <iostream> // stringstream #include <sstream> // stringstream
--- a/examples/d-box/main.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/d-box/main.cpp Fri May 27 17:51:34 2016 +0100 @@ -417,7 +417,7 @@ if(gVerbose==1) cout << "main() : creating control thread" << endl; - if(rt_task_create(&rtSensorThread, rtSensorThreadName, 0, BEAGLERT_AUDIO_PRIORITY - 5, T_JOINABLE | T_FPU)) { + if(rt_task_create(&rtSensorThread, rtSensorThreadName, 0, BELA_AUDIO_PRIORITY - 5, T_JOINABLE | T_FPU)) { cout << "Error:unable to create Xenomai control thread" << endl; return -1; }
--- a/examples/d-box/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/d-box/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -229,9 +229,9 @@ PeakBurst[1].setSustainLevel(0.0); // Initialise auxiliary tasks - if((gMediumPriorityRender = Bela_createAuxiliaryTask(&render_medium_prio, BEAGLERT_AUDIO_PRIORITY - 10, "dbox-calculation-medium")) == 0) + if((gMediumPriorityRender = Bela_createAuxiliaryTask(&render_medium_prio, BELA_AUDIO_PRIORITY - 10, "dbox-calculation-medium")) == 0) return false; - if((gLowPriorityRender = Bela_createAuxiliaryTask(&render_low_prio, BEAGLERT_AUDIO_PRIORITY - 15, "dbox-calculation-low")) == 0) + if((gLowPriorityRender = Bela_createAuxiliaryTask(&render_low_prio, BELA_AUDIO_PRIORITY - 15, "dbox-calculation-low")) == 0) return false; return true;
--- a/examples/filter_FIR/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/filter_FIR/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -105,7 +105,7 @@ bool initialise_trigger() { - if((gTriggerSamplesTask = Bela_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) + if((gTriggerSamplesTask = Bela_createAuxiliaryTask(&trigger_samples, 50, "bela-trigger-samples")) == 0) return false; rt_printf("Press 'a' to trigger sample, 's' to stop\n");
--- a/examples/filter_IIR/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/filter_IIR/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -139,10 +139,10 @@ bool initialise_aux_tasks() { - if((gChangeCoeffTask = Bela_createAuxiliaryTask(&check_coeff, 90, "beaglert-check-coeff")) == 0) + if((gChangeCoeffTask = Bela_createAuxiliaryTask(&check_coeff, 90, "bela-check-coeff")) == 0) return false; - if((gInputTask = Bela_createAuxiliaryTask(&read_input, 50, "beaglert-read-input")) == 0) + if((gInputTask = Bela_createAuxiliaryTask(&read_input, 50, "bela-read-input")) == 0) return false; rt_printf("Press 'a' to trigger sample, 's' to stop\n");
--- a/examples/measure_noisefloor/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/measure_noisefloor/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -47,7 +47,7 @@ } } - gAnalysisTask = Bela_createAuxiliaryTask(analyseResults, 50, "beaglert-analyse-results"); + gAnalysisTask = Bela_createAuxiliaryTask(analyseResults, 50, "bela-analyse-results"); return true; }
--- a/examples/mpr121/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/mpr121/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -54,7 +54,7 @@ return false; } - i2cTask = Bela_createAuxiliaryTask(readMPR121, 50, "beaglert-mpr121"); + i2cTask = Bela_createAuxiliaryTask(readMPR121, 50, "bela-mpr121"); readIntervalSamples = context->audioSampleRate / readInterval; for(int i = 0; i < NUM_TOUCH_PINS; i++) {
--- a/examples/oscillator_bank/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/oscillator_bank/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -137,7 +137,7 @@ } // Initialise auxiliary tasks - if((gFrequencyUpdateTask = Bela_createAuxiliaryTask(&recalculate_frequencies, 85, "beaglert-update-frequencies")) == 0) + if((gFrequencyUpdateTask = Bela_createAuxiliaryTask(&recalculate_frequencies, 85, "bela-update-frequencies")) == 0) return false; //for(int n = 0; n < gNumOscillators; n++)
--- a/examples/samples/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/samples/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -73,7 +73,7 @@ bool initialise_trigger() { - if((gTriggerSamplesTask = Bela_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) + if((gTriggerSamplesTask = Bela_createAuxiliaryTask(&trigger_samples, 50, "bela-trigger-samples")) == 0) return false; rt_printf("Press 'a' to trigger sample, 's' to stop\n");
--- a/examples/tank_wars/render.cpp Fri May 27 17:49:05 2016 +0100 +++ b/examples/tank_wars/render.cpp Fri May 27 17:51:34 2016 +0100 @@ -127,7 +127,7 @@ // Initialise auxiliary tasks if((gScreenUpdateTask = Bela_createAuxiliaryTask(&screen_update, 90, - "beaglert-screen-update")) == 0) + "bela-screen-update")) == 0) return false; return true;
--- a/include/Bela.h Fri May 27 17:49:05 2016 +0100 +++ b/include/Bela.h Fri May 27 17:51:34 2016 +0100 @@ -21,12 +21,12 @@ * Bela is based on the Xenomai real-time Linux extensions (http://xenomai.org) and * uses the BeagleBone %PRU subsystem to address the audio and sensor hardware. * - * Further information can be found at http://beaglert.cc + * Further information can be found at http://bela.io */ -#ifndef BEAGLERT_H_ -#define BEAGLERT_H_ +#ifndef BELA_H_ +#define BELA_H_ #include <stdint.h> #include <unistd.h> @@ -55,7 +55,7 @@ * In general, all auxiliary tasks should have a level lower than this unless for\ * special purposes where the task needs to interrupt audio processing. */ -#define BEAGLERT_AUDIO_PRIORITY 95 +#define BELA_AUDIO_PRIORITY 95 // Default volume levels @@ -90,11 +90,11 @@ /** * Flag for BelaContext. If set, indicates the audio and analog buffers are interleaved. */ -#define BEAGLERT_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved +#define BELA_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved /** * Flag for BelaContext. If set, indicates analog outputs persist for future frames. */ -#define BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers +#define BELA_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers /** * \ingroup control @@ -255,9 +255,9 @@ /// /// Binary combination of flags including: /// - /// BEAGLERT_FLAG_INTERLEAVED: indicates the audio and analog buffers are interleaved + /// BELA_FLAG_INTERLEAVED: indicates the audio and analog buffers are interleaved /// - /// BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will + /// BELA_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will /// persist for future frames. If not set, writes affect one frame only. uint32_t flags; } BelaContext; @@ -576,7 +576,7 @@ * Auxiliary tasks should be created in setup() and never in render() itself. * * The second argument specifies the real-time priority. Valid values are between 0 - * and 99, and usually should be lower than \ref BEAGLERT_AUDIO_PRIORITY. Tasks with higher priority always + * and 99, and usually should be lower than \ref BELA_AUDIO_PRIORITY. Tasks with higher priority always * preempt tasks with lower priority. * * \param functionToCall Function which will run each time the auxiliary task is scheduled. @@ -618,4 +618,4 @@ /** @} */ #include <Utilities.h> -#endif /* BEAGLERT_H_ */ +#endif /* BELA_H_ */
--- a/include/PRU.h Fri May 27 17:49:05 2016 +0100 +++ b/include/PRU.h Fri May 27 17:51:34 2016 +0100 @@ -64,8 +64,10 @@ bool digital_enabled; // Whether digital is used bool gpio_enabled; // Whether GPIO has been prepared bool led_enabled; // Whether a user LED is enabled + int mux_channels; // How many mux channels are used (if enabled) bool gpio_test_pin_enabled; // Whether the test pin was also enabled + volatile uint32_t *pru_buffer_comm; uint16_t *pru_buffer_spi_dac; uint16_t *pru_buffer_spi_adc;
--- a/include/Utilities.h Fri May 27 17:49:05 2016 +0100 +++ b/include/Utilities.h Fri May 27 17:51:34 2016 +0100 @@ -123,7 +123,7 @@ * This function sets the value of an analog output, at the time indicated by \c frame. Valid * values are between 0 and 1, corresponding to the range 0 to 5V. * - * The value written will persist for all future frames if BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST + * The value written will persist for all future frames if BELA_FLAG_ANALOG_OUTPUTS_PERSIST * is set in context->flags. This is the default behaviour. * * \param context The I/O data structure which is passed by Bela to render(). @@ -144,7 +144,7 @@ * Unlike analogWriteFrame(), the value written will affect \b only the frame specified, with * future values unchanged. This is faster than analogWriteFrame() so is better suited * to applications where every frame will be written to a different value. If - * BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST is not set within context->flags, then + * BELA_FLAG_ANALOG_OUTPUTS_PERSIST is not set within context->flags, then * analogWriteFrameOnce() and analogWriteFrame() are equivalent. * * \param context The I/O data structure which is passed by Bela to render(). @@ -358,7 +358,7 @@ // Sets a given analog output channel to a value for the current frame and, if persistent outputs are // enabled, for all subsequent frames static inline void analogWriteFrame(BelaContext *context, int frame, int channel, float value) { - if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { + if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { for(unsigned int f = frame; f < context->analogFrames; f++) context->analogOut[frame * context->analogChannels + channel] = value; }