Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
Classes | Functions | Variables
User-defined render functions

Classes

struct  BelaContext
 Structure holding audio and sensor settings and pointers to I/O data buffers. More...
 

Functions

bool setup (BelaContext *context, void *userData)
 User-defined initialisation function which runs before audio rendering begins. More...
 
void render (BelaContext *context, void *userData)
 User-defined callback function to process audio and sensor data. More...
 
void cleanup (BelaContext *context, void *userData)
 User-defined cleanup function which runs when the program finishes. More...
 

Variables

int volatile gShouldStop
 

Detailed Description

These three functions must be implemented by the developer in every Bela program. Typically they appear in their own .cpp source file.

Function Documentation

bool setup ( BelaContext context,
void *  userData 
)

User-defined initialisation function which runs before audio rendering begins.

This function runs once at the beginning of the program, after most of the system initialisation has begun but before audio rendering starts. Use it to prepare any memory or resources that will be needed in render().

Parameters
contextData structure holding information on sample rates, numbers of channels, frame sizes and other state. Note: the buffers for audio, analog and digital data will not yet be available to use. Do not attempt to read or write audio or sensor data in setup().
userDataAn opaque pointer to an optional user-defined data structure. Whatever is passed as the second argument to Bela_initAudio() will appear here.
Returns
true on success, or false if an error occurred. If no initialisation is required, setup() should return true.
Examples:
05-Communication/MIDI/render.cpp, analog-input/render.cpp, analog-output/render.cpp, bicolor-LEDs/render.cpp, capacitive-touch/render.cpp, cape-test/render.cpp, delay/render.cpp, digital-input/render.cpp, digital-output/render.cpp, FFT-phase-vocoder/render.cpp, filter-FIR/render.cpp, filter-IIR/render.cpp, LDR/render.cpp, level-meter/render.cpp, logging-sensors/render.cpp, minimal/render.cpp, multiplexer_display/render.cpp, multiplexer_spectrum/render.cpp, OSC/render.cpp, oscillator-bank/render.cpp, passthrough/render.cpp, print/render.cpp, sample-loader/render.cpp, sample-piezo-trigger/render.cpp, sample-streamer-multi/render.cpp, sample-streamer/render.cpp, samples/render.cpp, scope-analog/render.cpp, scope-sliders/render.cpp, scope/render.cpp, second-pru/render.cpp, sinetone/render.cpp, sinetone_optimized/render.cpp, sinetone_optimized_bank/render.cpp, synchronous-gpio/render.cpp, tremolo/render.cpp, ultrasonic-distance/render.cpp, and userdata/render.cpp.
void render ( BelaContext context,
void *  userData 
)

User-defined callback function to process audio and sensor data.

This function is called regularly by the system every time there is a new block of audio and/or sensor data to process. Your code should process the requested samples of data, store the results within context, and return.

Parameters
contextData structure holding buffers for audio, analog and digital data. The structure also holds information on numbers of channels, frame sizes and sample rates, which are guaranteed to remain the same throughout the program and to match what was passed to setup().
userDataAn opaque pointer to an optional user-defined data structure. Will be the same as the userData parameter passed to setup().

Checking offset between analog and digital how it should be : The PRU loop does the following (the loop runs at 88.2kHz):

  • Read/write audio sample (once for the left channel, once for the right channel)
  • Write DAC 0 or 0/2 or 0/2/4/6
  • Read ADC 0 or 0/2 or 0/2/4/6, 2 samples (@176.4) older than NOW
  • /During/ the line above, every two loops we also Read/Write GPIO, therefore reading on ADC 0/2/4/6 a value that is being output from GPIO will lead to undefined results
  • Write DAC 1 or 1/3 or 1/3/5/7
  • Read ADC 1 or 1/3 or 1/3/5/7, 2 samples (@176.4) older than NOW
Examples:
05-Communication/MIDI/render.cpp, analog-input/render.cpp, analog-output/render.cpp, bicolor-LEDs/render.cpp, capacitive-touch/render.cpp, cape-test/render.cpp, delay/render.cpp, digital-input/render.cpp, digital-output/render.cpp, FFT-phase-vocoder/render.cpp, filter-FIR/render.cpp, filter-IIR/render.cpp, LDR/render.cpp, level-meter/render.cpp, logging-sensors/render.cpp, minimal/render.cpp, multiplexer_display/render.cpp, multiplexer_spectrum/render.cpp, OSC/render.cpp, oscillator-bank/render.cpp, passthrough/render.cpp, print/render.cpp, sample-loader/render.cpp, sample-piezo-trigger/render.cpp, sample-streamer-multi/render.cpp, sample-streamer/render.cpp, samples/render.cpp, scope-analog/render.cpp, scope-sliders/render.cpp, scope/render.cpp, second-pru/render.cpp, sinetone/render.cpp, sinetone_optimized/render.cpp, sinetone_optimized_bank/render.cpp, synchronous-gpio/render.cpp, tremolo/render.cpp, ultrasonic-distance/render.cpp, and userdata/render.cpp.
void cleanup ( BelaContext context,
void *  userData 
)

User-defined cleanup function which runs when the program finishes.

This function is called by the system once after audio rendering has finished, before the program quits. Use it to release any memory allocated in setup() and to perform any other required cleanup. If no initialisation is performed in setup(), then this function will usually be empty.

Parameters
contextData structure holding information on sample rates, numbers of channels, frame sizes and other state. Note: the buffers for audio, analog and digital data will no longer be available to use. Do not attempt to read or write audio or sensor data in cleanup().
userDataAn opaque pointer to an optional user-defined data structure. Will be the same as the userData parameter passed to setup() and render().
Examples:
05-Communication/MIDI/render.cpp, analog-input/render.cpp, analog-output/render.cpp, bicolor-LEDs/render.cpp, capacitive-touch/render.cpp, cape-test/render.cpp, delay/render.cpp, digital-input/render.cpp, digital-output/render.cpp, FFT-phase-vocoder/render.cpp, filter-FIR/render.cpp, filter-IIR/render.cpp, LDR/render.cpp, level-meter/render.cpp, logging-sensors/render.cpp, minimal/render.cpp, multiplexer_display/render.cpp, multiplexer_spectrum/render.cpp, OSC/render.cpp, oscillator-bank/render.cpp, passthrough/render.cpp, print/render.cpp, sample-loader/render.cpp, sample-piezo-trigger/render.cpp, sample-streamer-multi/render.cpp, sample-streamer/render.cpp, samples/render.cpp, scope-analog/render.cpp, scope-sliders/render.cpp, scope/render.cpp, second-pru/render.cpp, sinetone/render.cpp, sinetone_optimized/render.cpp, sinetone_optimized_bank/render.cpp, synchronous-gpio/render.cpp, tremolo/render.cpp, ultrasonic-distance/render.cpp, and userdata/render.cpp.

Variable Documentation

int volatile gShouldStop

Flag that indicates when the audio will stop. Threads can poll this variable to indicate when they should stop. Additionally, a program can set this to true to indicate that audio processing should terminate. Calling Bela_stopAudio() has the effect of setting this to true.

Examples:
filter-FIR/render.cpp, filter-IIR/render.cpp, and samples/render.cpp.