Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
Macros
I/O functions and constants

Macros

#define INPUT   0x0
 
#define OUTPUT   0x1
 
static float audioRead (BelaContext *context, int frame, int channel)
 Read an audio input, specifying the frame number (when to read) and the channel. More...
 
static float audioReadNI (BelaContext *context, int frame, int channel)
 
static void audioWrite (BelaContext *context, int frame, int channel, float value)
 Write an audio output, specifying the frame number (when to write) and the channel. More...
 
static void audioWriteNI (BelaContext *context, int frame, int channel, float value)
 
static float analogRead (BelaContext *context, int frame, int channel)
 Read an analog input, specifying the frame number (when to read) and the channel. More...
 
static float analogReadNI (BelaContext *context, int frame, int channel)
 
static void analogWrite (BelaContext *context, int frame, int channel, float value)
 Write an analog output, specifying the frame number (when to write) and the channel. More...
 
static void analogWriteNI (BelaContext *context, int frame, int channel, float value)
 
static void analogWriteOnce (BelaContext *context, int frame, int channel, float value)
 Write an analog output, specifying the frame number (when to write) and the channel. More...
 
static void analogWriteOnceNI (BelaContext *context, int frame, int channel, float value)
 
static int digitalRead (BelaContext *context, int frame, int channel)
 Read a digital input, specifying the frame number (when to read) and the pin. More...
 
static void digitalWrite (BelaContext *context, int frame, int channel, int value)
 Write a digital output, specifying the frame number (when to write) and the pin. More...
 
static void digitalWriteOnce (BelaContext *context, int frame, int channel, int value)
 Write a digital output, specifying the frame number (when to write) and the pin. More...
 
static void pinMode (BelaContext *context, int frame, int channel, int mode)
 Set the direction of a digital pin to input or output. More...
 
static void pinModeOnce (BelaContext *context, int frame, int channel, int mode)
 Set the direction of a digital pin to input or output. More...
 
static float multiplexerAnalogRead (BelaContext *context, int input, int muxChannel)
 Read an audio input, specifying the frame number (when to read) and the channel. More...
 
static unsigned int multiplexerChannelForFrame (BelaContext *context, int frame)
 Read an audio input, specifying the frame number (when to read) and the channel. More...
 

Detailed Description

These functions and macros are used for audio, analog and digital I/O. All the I/O functions require the BelaContext data structure from render() to be passed in. This means that these functions are, by design, only usable from within the rendering thread.

The naming conventions are loosely derived from the Arduino environment, and the syntax is similar. Unlike Arduino, the I/O functions require the frame number at which the read or write should take place, since all I/O happens synchronously with the audio clock.

Function Documentation

static float audioRead ( BelaContext context,
int  frame,
int  channel 
)
inlinestatic

Read an audio input, specifying the frame number (when to read) and the channel.

This function returns the value of an audio input, at the time indicated by frame. The returned value ranges from -1 to 1.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to read the audio input. Valid values range from 0 to (context->audioFrames - 1).
channelWhich audio input to read. Valid values are between 0 and (context->audioChannels - 1), typically 0 to 1 by default.
Returns
Value of the analog input, range to 1.
Examples:
cape-test/render.cpp, delay/render.cpp, FFT-phase-vocoder/render.cpp, level-meter/render.cpp, passthrough/render.cpp, and tremolo/render.cpp.
static float audioReadNI ( BelaContext context,
int  frame,
int  channel 
)
inlinestatic

Non-interleaved version of audioRead()

static void audioWrite ( BelaContext context,
int  frame,
int  channel,
float  value 
)
inlinestatic

Write an audio output, specifying the frame number (when to write) and the channel.

This function sets the value of an audio output, at the time indicated by frame. Valid values are between -1 and 1.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to write the audio output. Valid values range from 0 to (context->audioFrames - 1).
channelWhich analog output to write. Valid values are between 0 and (context->audioChannels - 1), typically 0 to 1 by default.
valueValue to write to the output, range -1 to 1.
Examples:
05-Communication/MIDI/render.cpp, analog-input/render.cpp, cape-test/render.cpp, delay/render.cpp, digital-input/render.cpp, FFT-phase-vocoder/render.cpp, filter-FIR/render.cpp, filter-IIR/render.cpp, LDR/render.cpp, level-meter/render.cpp, oscillator-bank/render.cpp, passthrough/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, second-pru/render.cpp, sinetone/render.cpp, sinetone_optimized/render.cpp, sinetone_optimized_bank/render.cpp, tremolo/render.cpp, and userdata/render.cpp.
static void audioWriteNI ( BelaContext context,
int  frame,
int  channel,
float  value 
)
inlinestatic

Non-interleaved version of audioWrite()

static float analogRead ( BelaContext context,
int  frame,
int  channel 
)
inlinestatic

Read an analog input, specifying the frame number (when to read) and the channel.

This function returns the value of an analog input, at the time indicated by frame. The returned value ranges from 0 to 1, corresponding to a voltage range of 0 to 4.096V.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to read the analog input. Valid values range from 0 to (context->analogFrames - 1).
channelWhich analog input to read. Valid values are between 0 and (context->analogInChannels - 1), typically 0 to 7 by default.
Returns
Value of the analog input, range 0 to 1.
Examples:
analog-input/render.cpp, bicolor-LEDs/render.cpp, cape-test/render.cpp, LDR/render.cpp, logging-sensors/render.cpp, multiplexer_spectrum/render.cpp, passthrough/render.cpp, sample-piezo-trigger/render.cpp, scope-analog/render.cpp, and tremolo/render.cpp.
static float analogReadNI ( BelaContext context,
int  frame,
int  channel 
)
inlinestatic

Non-interleaved version of analogRead()

static void analogWrite ( BelaContext context,
int  frame,
int  channel,
float  value 
)
inlinestatic

Write an analog output, specifying the frame number (when to write) and the channel.

This function sets the value of an analog output, at the time indicated by 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 BELA_FLAG_ANALOG_OUTPUTS_PERSIST is set in context->flags. This is the default behaviour.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to write the analog output. Valid values range from 0 to (context->analogFrames - 1).
channelWhich analog output to write. Valid values are between 0 and (context->analogOutChannels - 1), typically 0 to 7 by default.
valueValue to write to the output, range 0 to 1.
static void analogWriteNI ( BelaContext context,
int  frame,
int  channel,
float  value 
)
inlinestatic

Non-interleaved version of analogWrite()

static void analogWriteOnce ( BelaContext context,
int  frame,
int  channel,
float  value 
)
inlinestatic

Write an analog output, specifying the frame number (when to write) and the channel.

This function sets the value of an analog output, at the time indicated by frame. Valid values are between 0 and 1, corresponding to the range 0 to 5V.

Unlike analogWrite(), the value written will affect only the frame specified, with future values unchanged. This is faster than analogWrite() so is better suited to applications where every frame will be written to a different value. If BELA_FLAG_ANALOG_OUTPUTS_PERSIST is not set within context->flags, then analogWriteOnce() and analogWrite() are equivalent.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to write the analog output. Valid values range from 0 to (context->analogFrames - 1).
channelWhich analog output to write. Valid values are between 0 and (context->analogOutChannels - 1), typically 0 to 7 by default.
valueValue to write to the output, range 0 to 1.
Examples:
analog-output/render.cpp, cape-test/render.cpp, passthrough/render.cpp, and ultrasonic-distance/render.cpp.
static void analogWriteOnceNI ( BelaContext context,
int  frame,
int  channel,
float  value 
)
inlinestatic

Non-interleaved version of analogWriteNI();

static int digitalRead ( BelaContext context,
int  frame,
int  channel 
)
inlinestatic

Read a digital input, specifying the frame number (when to read) and the pin.

This function returns the value of a digital input, at the time indicated by frame. The value is 0 if the pin is low, and nonzero if the pin is high (3.3V).

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to read the digital input. Valid values range from 0 to (context->digitalFrames - 1).
channelWhich digital pin to read. 16 pins across the P8 and P9 headers of the BeagleBone Black are available. See the constants P8_xx and P9_xx defined in digital_gpio_mapping.h.
Returns
Value of the digital input.
Examples:
digital-input/render.cpp, and ultrasonic-distance/render.cpp.
static void digitalWrite ( BelaContext context,
int  frame,
int  channel,
int  value 
)
inlinestatic

Write a digital output, specifying the frame number (when to write) and the pin.

This function sets the value of a digital output, at the time indicated by frame. A value of 0 sets the pin low; any other value sets the pin high (3.3V).

The value written will persist for all future frames.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to write the digital output. Valid values range from 0 to (context->digitalFrames - 1).
channelWhich digital output to write. 16 pins across the P8 and P9 headers of the BeagleBone Black are available. See the constants P8_xx and P9_xx defined in digital_gpio_mapping.h.
valueValue to write to the output.
Examples:
digital-output/render.cpp.
static void digitalWriteOnce ( BelaContext context,
int  frame,
int  channel,
int  value 
)
inlinestatic

Write a digital output, specifying the frame number (when to write) and the pin.

This function sets the value of a digital output, at the time indicated by frame. A value of 0 sets the pin low; any other value sets the pin high (3.3V).

Unlike digitalWrite(), the value written will affect only the frame specified, with future values unchanged. This is faster than digitalWrite() so is better suited to applications where every frame will be written to a different value.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to write the digital output. Valid values range from 0 to (context->digitalFrames - 1).
channelWhich digital output to write. 16 pins across the P8 and P9 headers of the BeagleBone Black are available. See the constants P8_xx and P9_xx defined in digital_gpio_mapping.h.
valueValue to write to the output.
Examples:
bicolor-LEDs/render.cpp, digital-input/render.cpp, and level-meter/render.cpp.
static void pinMode ( BelaContext context,
int  frame,
int  channel,
int  mode 
)
inlinestatic

Set the direction of a digital pin to input or output.

This function sets the direction of a digital pin, at the time indicated by frame. Valid values are INPUT and OUTPUT. All pins begin as inputs by default.

The value written will persist for all future frames.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to set the pin direction. Valid values range from 0 to (context->digitalFrames - 1).
channelWhich digital output to write. 16 pins across the P8 and P9 headers of the BeagleBone Black are available. See the constants P8_xx and P9_xx defined in digital_gpio_mapping.h.
modeDirection of the pin (INPUT or OUTPUT).
Examples:
bicolor-LEDs/render.cpp, digital-input/render.cpp, digital-output/render.cpp, level-meter/render.cpp, and ultrasonic-distance/render.cpp.
static void pinModeOnce ( BelaContext context,
int  frame,
int  channel,
int  mode 
)
inlinestatic

Set the direction of a digital pin to input or output.

This function sets the direction of a digital pin, at the time indicated by frame. Valid values are INPUT and OUTPUT. All pins begin as inputs by default.

The value written will affect only the specified frame.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to set the pin direction. Valid values range from 0 to (context->digitalFrames - 1).
channelWhich digital output to write. 16 pins across the P8 and P9 headers of the BeagleBone Black are available. See the constants P8_xx and P9_xx defined in digital_gpio_mapping.h.
modeDirection of the pin (INPUT or OUTPUT).
Examples:
bicolor-LEDs/render.cpp.
static float multiplexerAnalogRead ( BelaContext context,
int  input,
int  muxChannel 
)
inlinestatic

Read an audio input, specifying the frame number (when to read) and the channel.

This function returns the value of an audio input, at the time indicated by frame. The returned value ranges from -1 to 1.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to read the audio input. Valid values range from 0 to (context->audioFrames - 1).
channelWhich audio input to read. Valid values are between 0 and (context->audioChannels - 1), typically 0 to 1 by default.
Returns
Value of the analog input, range to 1.
Examples:
multiplexer_display/render.cpp.
static unsigned int multiplexerChannelForFrame ( BelaContext context,
int  frame 
)
inlinestatic

Read an audio input, specifying the frame number (when to read) and the channel.

This function returns the value of an audio input, at the time indicated by frame. The returned value ranges from -1 to 1.

Parameters
contextThe I/O data structure which is passed by Bela to render().
frameWhich frame (i.e. what time) to read the audio input. Valid values range from 0 to (context->audioFrames - 1).
channelWhich audio input to read. Valid values are between 0 and (context->audioChannels - 1), typically 0 to 1 by default.
Returns
Value of the analog input, range to 1.
Examples:
multiplexer_spectrum/render.cpp.