29#define BELA_MAJOR_VERSION 1
30#define BELA_MINOR_VERSION 13
31#define BELA_BUGFIX_VERSION 0
99int rt_printf(
const char *format, ...);
100int rt_fprintf(FILE *stream,
const char *format, ...);
101int rt_vprintf(
const char *format, va_list ap);
102int rt_vfprintf(FILE *stream,
const char *format, va_list ap);
128 float audioSampleRate;
129 unsigned int audioInChannels;
130 unsigned int audioOutChannels;
131 unsigned int analogInChannels;
132 unsigned int analogOutChannels;
133 unsigned int digitalChannels;
161#include <GPIOcontrol.h>
166#define MAX_PRU_FILENAME_LENGTH 256
167#define MAX_UNUSED_LENGTH 220
168#define MAX_PROJECTNAME_LENGTH 256
178#define BELA_AUDIO_PRIORITY 95
191#define DEFAULT_LINE_OUT_LEVEL 0.0
196#define DEFAULT_PGA_GAIN 16
201#define DEFAULT_HP_LEVEL -6.0
207#define BELA_FLAG_INTERLEAVED (1 << 0)
211#define BELA_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1)
215#define BELA_FLAG_DETECT_UNDERRUNS (1 << 2)
219#define BELA_FLAG_OFFLINE (1 << 3)
515 unsigned int audioThreadStackSize;
518 unsigned int auxiliaryTaskStackSize;
546 char unused[MAX_UNUSED_LENGTH];
688#pragma weak Bela_userSettings
848#ifndef BELA_DISABLE_CPU_TIME
1131int Bela_startAllAuxiliaryTasks();
1132void Bela_stopAllAuxiliaryTasks();
1133void Bela_deleteAllAuxiliaryTasks();
1138#ifndef BELA_DONT_INCLUDE_UTILITIES
1139#include <Utilities.h>
1171#define Bela_setBit(word,bit) ((word) | (1 << (bit)))
1174#define Bela_clearBit(word,bit) ((word) &~ (1 << (bit)))
1177#define Bela_getBit(word,bit) (((word) >> (bit)) & 1)
1180#define Bela_changeBit(word,bit,value) ((Bela_clearBit((word),(bit))) | ((value) << (bit)))
1519 return Bela_getBit(context->
digital[frame], channel + 16);
1529 context->
digital[f] |= 1 << (channel + 16);
1531 context->
digital[f] &= ~(1 << (channel + 16));
1540 context->
digital[frame] |= 1 << (channel + 16);
1542 context->
digital[frame] &= ~(1 << (channel + 16));
1552 context->
digital[f] |= (1 << channel);
1554 context->
digital[f] &= ~(1 << channel);
1563 context->
digital[frame] |= (1 << channel);
1565 context->
digital[frame] &= ~(1 << channel);
BelaHwDetectMode
Definition Bela.h:153
@ BelaHwDetectMode_Cache
read cached value from /run/bela/belaconfig first. If it does not exist, fall back to BelaHwDetectMod...
Definition Bela.h:155
@ BelaHwDetectMode_User
read user-specified value from ~/.bela/belaconfig. If it does not exist, fall back to BelaHwDetectMod...
Definition Bela.h:157
@ BelaHwDetectMode_Scan
perform an automatic detection by scanning the peripherals and busses available, and cache value in /...
Definition Bela.h:154
@ BelaHwDetectMode_CacheOnly
read cached value from /run/bela/belaconfig. If it does not exist, return BelaHw_NoHw
Definition Bela.h:156
@ BelaHwDetectMode_UserOnly
read user-specified value from ~/.bela/belaconfig. If it does not exist, return BelaHw_NoHw
Definition Bela.h:158
BelaHw
Definition Bela.h:108
@ BelaHw_BelaMini
Bela Mini.
Definition Bela.h:111
@ BelaHw_CtagBeast
Ctag Beast.
Definition Bela.h:114
@ BelaHw_CtagFaceBela
Ctag Face and Bela cape.
Definition Bela.h:115
@ BelaHw_BelaMiniMultiAudio
Bela Mini with extra codecs.
Definition Bela.h:117
@ BelaHw_BelaMultiTdm
Bela with extra codecs and/or tdm devices.
Definition Bela.h:119
@ BelaHw_Salt
Salt.
Definition Bela.h:112
@ BelaHw_NoHw
No hardware.
Definition Bela.h:109
@ BelaHw_BelaMiniMultiTdm
Bela Mini with extra codecs and/or tdm devices.
Definition Bela.h:118
@ BelaHw_Batch
Dummy offline.
Definition Bela.h:123
@ BelaHw_BelaMiniMultiI2s
Bela Mini with extra rx and tx I2S data lines.
Definition Bela.h:120
@ BelaHw_BelaRevC
A Bela cape rev C: Es9080 is used for analog outs.
Definition Bela.h:122
@ BelaHw_Bela
Bela.
Definition Bela.h:110
@ BelaHw_CtagBeastBela
Ctag Beast and Bela cape.
Definition Bela.h:116
@ BelaHw_BelaEs9080
A Bela cape with Es9080 EVB on top, all as audio.
Definition Bela.h:121
@ BelaHw_CtagFace
Ctag Face.
Definition Bela.h:113
void Bela_HwConfig_delete(BelaHwConfig *cfg)
BelaHwConfig * Bela_HwConfig_new(BelaHw hw)
void Bela_cpuToc(BelaCpuData *data)
BelaCpuData * Bela_cpuMonitoringGet()
void Bela_cpuTic(BelaCpuData *data)
int Bela_cpuMonitoringInit(int count)
int Bela_startAuxiliaryTask(AuxiliaryTask task)
Initialize an auxiliary task so that it can be scheduled.
void * AuxiliaryTask
Definition Bela.h:561
AuxiliaryTask Bela_runAuxiliaryTask(void(*callback)(void *), int priority=0, void *arg=nullptr)
Create and start an AuxiliaryTask.
int Bela_scheduleAuxiliaryTask(AuxiliaryTask task)
Run an auxiliary task which has previously been created.
AuxiliaryTask Bela_createAuxiliaryTask(void(*callback)(void *), int priority, const char *name, void *arg=NULL)
Create a new auxiliary task.
void Bela_userSettings(BelaInitSettings *settings)
Initialise the data structure containing settings for Bela.
Definition render.cpp:64
void Bela_requestStop()
Tell the Bela program to stop.
int Bela_initAudio(BelaInitSettings *settings, void *userData)
Initialise audio and sensor rendering environment.
BelaHw Bela_detectHw(BelaHwDetectMode mode)
Detect what hardware we are running on.
void Bela_defaultSettings(BelaInitSettings *settings)
Initialise the data structure containing settings for Bela.
int Bela_getopt_long(int argc, char *const argv[], const char *customShortOptions, const struct option *customLongOptions, BelaInitSettings *settings)
Get long options from command line argument list, including Bela standard options.
int Bela_startAudio()
Begin processing audio and sensor data.
int Bela_stopRequested()
Check whether the program should stop.
void Bela_setUserData(void *newUserData)
Set the userData variable, which is passed to setup(), render() and cleanup().
int Bela_runInSameThread()
Begin processing audio and sensor data in the same thread as the caller.
BelaInitSettings * Bela_InitSettings_alloc()
Allocate the data structure containing settings for Bela.
void Bela_setVerboseLevel(int level)
Set level of verbose (debugging) printing.
void Bela_stopAudio()
Stop processing audio and sensor data.
void Bela_cleanupAudio()
Clean up resources from audio and sensor processing.
void Bela_getVersion(int *major, int *minor, int *bugfix)
Get the version of Bela you are running.
void Bela_usage()
Print usage information for Bela standard options.
void Bela_InitSettings_free(BelaInitSettings *settings)
De-allocate the data structure containing settings for Bela.
static float audioRead(BelaContext *context, int frame, int channel)
Read an audio input, specifying the frame number (when to read) and the channel.
Definition Bela.h:1458
static unsigned int multiplexerChannelForFrame(BelaContext *context, int frame)
Read an audio input, specifying the frame number (when to read) and the channel.
Definition Bela.h:1578
static float audioReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of audioRead().
Definition Bela.h:1462
static void audioWriteNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of audioWrite().
Definition Bela.h:1473
static float analogRead(BelaContext *context, int frame, int channel)
Read an analog input, specifying the frame number (when to read) and the channel.
Definition Bela.h:1480
static float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel)
Read an audio input, specifying the frame number (when to read) and the channel.
Definition Bela.h:1571
static void pinModeOnce(BelaContext *context, int frame, int channel, int mode)
Set the direction of a digital pin to input or output.
Definition Bela.h:1561
static int digitalRead(BelaContext *context, int frame, int channel)
Read a digital input, specifying the frame number (when to read) and the pin.
Definition Bela.h:1518
static void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWriteNI().
Definition Bela.h:1495
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.
Definition Bela.h:1469
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.
Definition Bela.h:1538
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.
Definition Bela.h:1503
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.
Definition Bela.h:1525
static void pinMode(BelaContext *context, int frame, int channel, int mode)
Set the direction of a digital pin to input or output.
Definition Bela.h:1548
static float analogReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of analogRead().
Definition Bela.h:1484
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.
Definition Bela.h:1491
static void analogWriteNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWrite().
Definition Bela.h:1509
int Bela_setLineOutLevel(int channel, float decibel)
Set the level of the audio line out.
int Bela_setAudioInputGain(int channel, float decibels)
Set the gain of the audio input preamplifier.
int Bela_setAdcLevel(int channel, float decibels)
Set the level of the audio ADC.
int Bela_setHpLevel(int channel, float decibels)
Set the level of the onboard headphone amplifier.
int Bela_setDACLevel(float decibels)
int Bela_setDacLevel(int channel, float decibels)
Set the level of the audio DAC.
int Bela_setHeadphoneLevel(float decibels)
int Bela_muteSpeakers(int mute)
Mute or unmute the onboard speaker amplifiers.
int Bela_setPgaGain(float decibels, int channel)
int Bela_setADCLevel(float decibels)
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition render.cpp:68
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition render.cpp:51
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
int channel
Channel number. Negative value means all the channels.
Definition Bela.h:424
float gain
Gain in dB.
Definition Bela.h:425
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
const uint32_t digitalFrames
Number of digital frames per period.
Definition Bela.h:365
const uint32_t audioOutChannels
The number of audio output channels.
Definition Bela.h:326
const uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition Bela.h:385
const uint32_t audioFrames
The number of audio frames per block.
Definition Bela.h:322
const float *const audioIn
Buffer holding audio input samples.
Definition Bela.h:249
const uint32_t audioInChannels
The number of audio input channels.
Definition Bela.h:324
const float *const multiplexerAnalogIn
Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.
Definition Bela.h:398
const unsigned int underrunCount
Number of detected underruns.
Definition Bela.h:420
const uint32_t audioExpanderEnabled
Flags for whether audio expander is enabled on given analog channels.
Definition Bela.h:404
const uint32_t digitalChannels
Number of digital channels.
Definition Bela.h:369
char projectName[MAX_PROJECTNAME_LENGTH]
Name of running project.
Definition Bela.h:417
const float *const analogIn
Buffer holding analog input samples.
Definition Bela.h:283
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328
const uint32_t analogFrames
The number of analog frames per block.
Definition Bela.h:341
const uint32_t flags
Other audio/sensor settings.
Definition Bela.h:414
const float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0).
Definition Bela.h:371
float *const analogOut
Buffer holding analog output samples.
Definition Bela.h:298
uint32_t *const digital
Buffer holding digital input/output samples.
Definition Bela.h:308
const uint32_t analogOutChannels
The number of analog output channels.
Definition Bela.h:351
const uint32_t analogInChannels
The number of analog input channels.
Definition Bela.h:346
const uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition Bela.h:379
const uint32_t multiplexerStartingChannel
Multiplexer channel corresponding to the first analog frame.
Definition Bela.h:391
const float analogSampleRate
Analog sample rate in Hz.
Definition Bela.h:362
float *const audioOut
Buffer holding audio output samples.
Definition Bela.h:264
long long unsigned int total
Total CPU time (between tic and previous tic) during the current acquisition cycle.
Definition Bela.h:876
struct timespec toc
Time of last toc.
Definition Bela.h:878
long long unsigned int busy
Total CPU time spent being busy (between tic and toc) during the current acquisition cycle.
Definition Bela.h:875
int count
Number of samples (tic/toc pairs) in a acquisition cycle. Use 0 to disable.
Definition Bela.h:873
struct timespec tic
Time of last tic.
Definition Bela.h:877
float percentage
Average CPU usage during previous acquisition cycle.
Definition Bela.h:879
unsigned int currentCount
Number of tics in current acquisition cycle.
Definition Bela.h:874
Structure containing initialisation parameters for the real-time audio control system.
Definition Bela.h:441
int ampMutePin
Pin where amplifier mute can be found.
Definition Bela.h:528
struct BelaChannelGainArray headphoneGains
level for headphone outputs
Definition Bela.h:538
struct BelaChannelGainArray audioInputGains
audio input gains
Definition Bela.h:536
BelaHw board
User selected board to work with (as opposed to detected hardware).
Definition Bela.h:549
unsigned int audioExpanderInputs
Which audio expander settings to use on the input.
Definition Bela.h:478
int useAnalog
Whether to use the analog input and output.
Definition Bela.h:451
char * codecMode
A codec-specific intialisation parameter.
Definition Bela.h:534
int numAnalogOutChannels
How many analog output channels.
Definition Bela.h:461
int interleave
Whether audio/analog data should be interleaved.
Definition Bela.h:505
char pruFilename[MAX_PRU_FILENAME_LENGTH]
The external .bin file to load. If empty will use PRU code from pru_rtaudio_bin.h.
Definition Bela.h:485
int uniformSampleRate
Whether the analog channels should be resampled to audio sampling rate.
Definition Bela.h:512
int detectUnderruns
Whether to detect and log underruns.
Definition Bela.h:487
struct BelaChannelGainArray lineOutGains
Level for the audio line level output.
Definition Bela.h:542
int pruNumber
Which PRU (0 or 1) the code should run on.
Definition Bela.h:483
int numDigitalChannels
How many channels for the GPIOs.
Definition Bela.h:463
int analogOutputsPersist
Whether analog outputs should persist to future frames.
Definition Bela.h:509
float pgaGain[2]
Gains for the PGA, left and right channels. DEPRECATED: use audioInputGains.
Definition Bela.h:472
float dacLevel
Level for the audio DAC output. DEPRECATED: ues lineOutGains.
Definition Bela.h:468
int numAudioInChannels
How many audio input channels [ignored].
Definition Bela.h:455
int periodSize
Number of audio frames per period ("blocksize").
Definition Bela.h:449
char * projectName
Name of running project.
Definition Bela.h:552
float adcLevel
Level for the audio ADC input. DEPRECATED: use audioInputGains.
Definition Bela.h:470
int beginMuted
Whether to begin with the speakers muted.
Definition Bela.h:466
int enableLED
Whether to use the blinking LED to indicate Bela is running.
Definition Bela.h:491
int stopButtonPin
Definition Bela.h:494
float headphoneLevel
Level for the headphone output. DEPRECATED: use headphoneGains.
Definition Bela.h:474
int numAudioOutChannels
How many audio out channels [ignored].
Definition Bela.h:457
int verbose
Whether to use verbose logging.
Definition Bela.h:489
int useDigital
Whether to use the 16 programmable GPIOs.
Definition Bela.h:453
unsigned int audioExpanderOutputs
Which audio expander settings to use on the input.
Definition Bela.h:480
uint32_t disabledDigitalChannels
A bitmask of disabled digital channels.
Definition Bela.h:544
int highPerformanceMode
Definition Bela.h:499
void(* audioThreadDone)(BelaContext *, void *)
Definition Bela.h:532
struct BelaChannelGainArray adcGains
Level for the audio ADC input DEPRECATED: use audioInputGains.
Definition Bela.h:540
int numMuxChannels
How many channels to use on the multiplexer capelet, if enabled.
Definition Bela.h:476
int numAnalogInChannels
How many analog input channels.
Definition Bela.h:459