Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Public Attributes | List of all members
BelaContext Struct Reference

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

#include <Bela.h>

Public Attributes

const float *const audioIn
 Buffer holding audio input samples. More...
 
float *const audioOut
 Buffer holding audio output samples. More...
 
const float *const analogIn
 Buffer holding analog input samples. More...
 
float *const analogOut
 Buffer holding analog output samples. More...
 
uint32_t *const digital
 Buffer holding digital input/output samples. More...
 
const uint32_t audioFrames
 The number of audio frames per block. More...
 
const uint32_t audioInChannels
 The number of audio input channels.
 
const uint32_t audioOutChannels
 The number of audio output channels.
 
const float audioSampleRate
 The audio sample rate in Hz (currently always 44100.0)
 
const uint32_t analogFrames
 The number of analog frames per block. More...
 
const uint32_t analogInChannels
 The number of analog input channels. More...
 
const uint32_t analogOutChannels
 The number of analog output channels. More...
 
const float analogSampleRate
 Analog sample rate in Hz. More...
 
const uint32_t digitalFrames
 Number of digital frames per period.
 
const uint32_t digitalChannels
 Number of digital channels. More...
 
const float digitalSampleRate
 Digital sample rate in Hz (currently always 44100.0)
 
const uint64_t audioFramesElapsed
 Number of elapsed audio frames since the start of rendering. More...
 
const uint32_t multiplexerChannels
 Number of multiplexer channels for each analog input. More...
 
const uint32_t multiplexerStartingChannel
 Multiplexer channel corresponding to the first analog frame. More...
 
const float *const multiplexerAnalogIn
 Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled. More...
 
const uint32_t audioExpanderEnabled
 Flags for whether audio expander is enabled on given analog channels. More...
 
const uint32_t flags
 Other audio/sensor settings. More...
 
char projectName [MAX_PROJECTNAME_LENGTH]
 Name of running project.
 
const unsigned int underrunCount
 Number of detected underruns.
 

Detailed Description

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

This structure is passed to setup(), render() and cleanup() and provides access to Bela's I/O functionality. It is initialised in Bela_initAudio() based on the contents of the BelaInitSettings structure.

Examples:
Analog/analog-input/render.cpp, Analog/analog-output/render.cpp, Analog/scope-analog/render.cpp, Audio/delay/render.cpp, Audio/envelope-generator/render.cpp, Audio/FFT-phase-vocoder/render.cpp, Audio/filterbanks/render.cpp, Audio/record-audio/render.cpp, Audio/sample-loader/render.cpp, Audio/sample-piezo-trigger/render.cpp, Audio/sample-streamer-multi/render.cpp, Audio/sample-streamer/render.cpp, Audio/tremolo/render.cpp, Capelets/audio-expander/render.cpp, Capelets/multiplexer-display/render.cpp, Capelets/multiplexer-spectrum/render.cpp, Communication/logging-sensors/render.cpp, Communication/MIDI/render.cpp, Communication/OSC/render.cpp, Communication/Serial/render.cpp, Communication/Spi/render.cpp, Digital/bicolor-LEDs/render.cpp, Digital/digital-input/render.cpp, Digital/digital-output/render.cpp, Digital/level-meter/render.cpp, Extras/cape-test/render.cpp, Extras/oscillator-bank/render.cpp, Extras/pru-pwm/render.cpp, Extras/second-pru/render.cpp, Extras/userdata/render.cpp, Fundamentals/minimal/render.cpp, Fundamentals/passthrough/render.cpp, Fundamentals/print/render.cpp, Fundamentals/scope/render.cpp, Fundamentals/sinetone-optimized-bank/render.cpp, Fundamentals/sinetone-optimized/render.cpp, Fundamentals/sinetone/render.cpp, Gui/ambient-ellipse/render.cpp, Gui/bela-to-gui/render.cpp, Gui/clock/render.cpp, Gui/empty-project/render.cpp, Gui/frequency-response/render.cpp, Gui/graph/render.cpp, Gui/gui-to-bela/render.cpp, Gui/mouse-track/render.cpp, Gui/sequencer/render.cpp, Gui/sliders/render.cpp, Sensors/LDR/render.cpp, Sensors/MPR121/render.cpp, Sensors/rotary-encoder/render.cpp, Sensors/shift-register-out/render.cpp, Sensors/stepped-pot/render.cpp, Sensors/ultrasonic-distance-sensor/render.cpp, synchronous-gpio/render.cpp, terminal-only/filter-FIR/render.cpp, terminal-only/filter-IIR/render.cpp, terminal-only/samples/render.cpp, Trill/bar-led/render.cpp, Trill/bar-sound/render.cpp, Trill/bar-visual/render.cpp, Trill/craft-sound/render.cpp, Trill/craft-visual/render.cpp, Trill/custom-slider/render.cpp, Trill/detect-all-devices/render.cpp, Trill/flex-default/render.cpp, Trill/flex-visual/render.cpp, Trill/general-custom-address/render.cpp, Trill/general-print/render.cpp, Trill/general-settings/render.cpp, Trill/general-visual/render.cpp, Trill/hex-sound/render.cpp, Trill/hex-visual/render.cpp, Trill/multiple-devices/render.cpp, Trill/ring-sound/render.cpp, Trill/ring-visual/render.cpp, Trill/square-multitouch/render.cpp, Trill/square-sound/render.cpp, and Trill/square-visual/render.cpp.

Member Data Documentation

const float* const BelaContext::audioIn

Buffer holding audio input samples.

This buffer allows Bela's audio input data to be read during render(). By default the buffer contains data from all the audio input channels arranged in interleaved format.

Every time render() runs this buffer is filled with a block of new audio samples. The block is made up of frames, individual slices of time consisting of one sample taken from each audio input channel simultaneously. The number of frames per block is given by context->audioFrames, and the number of audio input channels by context->audioInChannels. The length of this buffer is the product of these two values.

The buffer can be accessed manually with standard array notation or more conveniently using the audioRead() utility.

Note: this element is available in render() only.

float* const BelaContext::audioOut

Buffer holding audio output samples.

This buffer allows Bela's audio output data to be written during render(). By default the buffer must contain data from all the audio output channels arranged in interleaved format.

Every time render() runs it is the job of the developer to fill this buffer with a block of new audio samples, structured in the same way as context->audioIn.

The buffer can be accessed manually with standard array notation or more conveniently using the audioWrite() utility.

Note: this element is available in render() only.

Examples:
Capelets/multiplexer-spectrum/render.cpp, and Sensors/MPR121/render.cpp.
const float* const BelaContext::analogIn

Buffer holding analog input samples.

This buffer allows Bela's analog input data to be read during render(). By default the buffer contains data from all the analog input channels arranged in interleaved format.

Every time render() runs this buffer is filled with a block of new analog samples. The block is made up of frames, individual slices of time consisting of one sample taken from each analog input channel simultaneously. The number of frames per block is given by context->analogFrames, and the number of analog input channels by context->analogInChannels. The length of this buffer is the product of these two values.

The buffer can be accessed manually with standard array notation or more conveniently using the analogRead() utility.

Note: this element is available in render() only.

Examples:
Communication/logging-sensors/render.cpp, and Extras/oscillator-bank/render.cpp.
float* const BelaContext::analogOut

Buffer holding analog output samples.

This buffer allows Bela's analog output data to be written during render(). By default the buffer must contain data from all the analog output channels arranged in interleaved format.

Every time render() runs it is the job of the developer to fill this buffer with a block of new analog samples, structured in the same way as context->analogIn.

The buffer can be accessed manually with standard array notation or more conveniently using the analogWrite() utility.

Note: this element is available in render() only.

uint32_t* const BelaContext::digital

Buffer holding digital input/output samples.

This buffer allows Bela's digital GPIO data to be read and written during render().

The buffer can be accessed manually with standard array notation or somewhat more conveniently using the digitalRead() and digitalWrite() utilities.

Note: this element is available in render() only.

const uint32_t BelaContext::audioFrames

The number of audio frames per block.

Every time render() runs context->audioIn is filled with a block of new audio samples. The block is made up of frames, individual slices of time consisting of one sample taken from each audio input channel simultaneously.

This value determines the number of audio frames in each block and can be adjusted in the IDE settings tab (or via the command line arguments) from 2 to 128, defaulting to 16.

This value also determines how often render() is called, and reducing it decreases audio latency at the cost of increased CPU consumption.

Examples:
Analog/analog-input/render.cpp, Analog/analog-output/render.cpp, Analog/scope-analog/render.cpp, Audio/delay/render.cpp, Audio/envelope-generator/render.cpp, Audio/FFT-phase-vocoder/render.cpp, Audio/filterbanks/render.cpp, Audio/record-audio/render.cpp, Audio/sample-loader/render.cpp, Audio/sample-piezo-trigger/render.cpp, Audio/sample-streamer-multi/render.cpp, Audio/sample-streamer/render.cpp, Audio/tremolo/render.cpp, Capelets/audio-expander/render.cpp, Capelets/multiplexer-spectrum/render.cpp, Communication/MIDI/render.cpp, Communication/Serial/render.cpp, Communication/Spi/render.cpp, Digital/level-meter/render.cpp, Extras/cape-test/render.cpp, Extras/oscillator-bank/render.cpp, Extras/second-pru/render.cpp, Extras/userdata/render.cpp, Fundamentals/passthrough/render.cpp, Fundamentals/print/render.cpp, Fundamentals/scope/render.cpp, Fundamentals/sinetone-optimized-bank/render.cpp, Fundamentals/sinetone-optimized/render.cpp, Fundamentals/sinetone/render.cpp, Gui/ambient-ellipse/render.cpp, Gui/bela-to-gui/render.cpp, Gui/clock/render.cpp, Gui/frequency-response/render.cpp, Gui/gui-to-bela/render.cpp, Gui/mouse-track/render.cpp, Gui/sequencer/render.cpp, Gui/sliders/render.cpp, Sensors/LDR/render.cpp, Sensors/MPR121/render.cpp, Sensors/stepped-pot/render.cpp, synchronous-gpio/render.cpp, terminal-only/filter-FIR/render.cpp, terminal-only/filter-IIR/render.cpp, terminal-only/samples/render.cpp, Trill/bar-led/render.cpp, Trill/bar-sound/render.cpp, Trill/bar-visual/render.cpp, Trill/craft-sound/render.cpp, Trill/craft-visual/render.cpp, Trill/custom-slider/render.cpp, Trill/flex-default/render.cpp, Trill/flex-visual/render.cpp, Trill/general-custom-address/render.cpp, Trill/general-print/render.cpp, Trill/general-settings/render.cpp, Trill/general-visual/render.cpp, Trill/hex-sound/render.cpp, Trill/hex-visual/render.cpp, Trill/multiple-devices/render.cpp, Trill/ring-sound/render.cpp, Trill/ring-visual/render.cpp, Trill/square-multitouch/render.cpp, Trill/square-sound/render.cpp, and Trill/square-visual/render.cpp.
const uint32_t BelaContext::analogFrames

The number of analog frames per block.

Every time render() runs context->analogIn is filled with a block of new analog samples. The block is made up of frames, individual slices of time consisting of one sample taken from each analog input channel simultaneously.

This value determines the number of analog frames in each block. It cannot be set directly as it is dependant on the number of audio frames per block (context->audioFrames) and the analog sample rate (context->analogSampleRate).

This value will be 0 if analog I/O is disabled.

Examples:
Analog/analog-input/render.cpp, Analog/analog-output/render.cpp, Analog/scope-analog/render.cpp, Audio/sample-piezo-trigger/render.cpp, Audio/tremolo/render.cpp, Capelets/audio-expander/render.cpp, Capelets/multiplexer-display/render.cpp, Capelets/multiplexer-spectrum/render.cpp, Communication/logging-sensors/render.cpp, Extras/cape-test/render.cpp, Extras/oscillator-bank/render.cpp, Fundamentals/passthrough/render.cpp, Gui/graph/render.cpp, and Sensors/LDR/render.cpp.
const uint32_t BelaContext::analogInChannels
const uint32_t BelaContext::analogOutChannels

The number of analog output channels.

This will be 0 if analog I/O is disabled.

Examples:
Analog/analog-output/render.cpp, Capelets/audio-expander/render.cpp, Extras/cape-test/render.cpp, and Fundamentals/passthrough/render.cpp.
const float BelaContext::analogSampleRate

Analog sample rate in Hz.

This value determines the rate at which each analog input is sampled, and is directly related to the number of analog channels available. It can be adjusted in the IDE settings tab (or via the command line arguments) to 22050, 44100 or 88200, allowing 8, 4, or 2 analog channels respectively. By default, all 8 channels are sampled at 22050Hz.

If analog I/O is disabled, this value is 0.

Examples:
Analog/analog-output/render.cpp, Analog/scope-analog/render.cpp, Audio/sample-piezo-trigger/render.cpp, Audio/tremolo/render.cpp, Capelets/audio-expander/render.cpp, Capelets/multiplexer-display/render.cpp, Capelets/multiplexer-spectrum/render.cpp, Gui/graph/render.cpp, and Sensors/LDR/render.cpp.
const uint32_t BelaContext::digitalChannels

Number of digital channels.

Currently this will always be 16, unless digital I/O is disabled, in which case it will be 0.

const uint64_t BelaContext::audioFramesElapsed

Number of elapsed audio frames since the start of rendering.

This holds the total number of audio frames as of the beginning of the current block. To find the current number of analog or digital frames elapsed, multiply by the ratio of the sample rates (e.g. half the number of analog frames will have elapsed if the analog sample rate is 22050).

Examples:
Capelets/multiplexer-spectrum/render.cpp, Digital/level-meter/render.cpp, and Extras/cape-test/render.cpp.
const uint32_t BelaContext::multiplexerChannels

Number of multiplexer channels for each analog input.

This will be 2, 4 or 8 if the multiplexer capelet is enabled, otherwise it will be 1. 2, 4 and 8 correspond to 16, 32 and 64 analog inputs, respectively.

Examples:
Capelets/multiplexer-display/render.cpp, and Capelets/multiplexer-spectrum/render.cpp.
const uint32_t BelaContext::multiplexerStartingChannel

Multiplexer channel corresponding to the first analog frame.

This indicates the multiplexer setting corresponding to the first analog frame in the buffer.

const float* const BelaContext::multiplexerAnalogIn

Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.

Because the analog in buffer size may be smaller than a complete cycle of the multiplexer capelet, this buffer will always be big enough to hold at least one complete cycle of all channels. It will be null if the multiplexer capelet is not enabled.

const uint32_t BelaContext::audioExpanderEnabled

Flags for whether audio expander is enabled on given analog channels.

Bits 0-15, when set, indicate audio expander enabled on the analog inputs. Bits 16-31 indicate audio expander enabled on the analog outputs.

const uint32_t BelaContext::flags

Other audio/sensor settings.

Binary combination of flags including:

BELA_FLAG_INTERLEAVED BELA_FLAG_ANALOG_OUTPUTS_PERSIST BELA_FLAG_DETECT_UNDERRUNS BELA_FLAG_OFFLINE

Examples:
Communication/logging-sensors/render.cpp.

The documentation for this struct was generated from the following file: