Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs 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...
 

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:
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.

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:
capacitive-touch/render.cpp, FFT-phase-vocoder/render.cpp, and multiplexer_spectrum/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:
logging-sensors/render.cpp, and 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:
05-Communication/MIDI/render.cpp, analog-input/render.cpp, analog-output/render.cpp, capacitive-touch/render.cpp, cape-test/render.cpp, delay/render.cpp, FFT-phase-vocoder/render.cpp, filter-FIR/render.cpp, filter-IIR/render.cpp, LDR/render.cpp, level-meter/render.cpp, multiplexer_spectrum/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, tremolo/render.cpp, and userdata/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-input/render.cpp, analog-output/render.cpp, cape-test/render.cpp, LDR/render.cpp, logging-sensors/render.cpp, multiplexer_display/render.cpp, multiplexer_spectrum/render.cpp, oscillator-bank/render.cpp, passthrough/render.cpp, sample-piezo-trigger/render.cpp, scope-analog/render.cpp, and tremolo/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-output/render.cpp, cape-test/render.cpp, and 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-output/render.cpp, LDR/render.cpp, multiplexer_display/render.cpp, multiplexer_spectrum/render.cpp, sample-piezo-trigger/render.cpp, scope-analog/render.cpp, and tremolo/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:
cape-test/render.cpp, level-meter/render.cpp, and multiplexer_spectrum/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:
multiplexer_display/render.cpp, and 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: indicates the audio and analog buffers are interleaved

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.

Examples:
logging-sensors/render.cpp.

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