Expand description
Raw FFI bindings to the Bela core API (libbela) for Bela Gem.
This crate exposes the C surface of the Bela core API (Bela.h):
BelaContext, BelaInitSettings, the Bela_* lifecycle and
auxiliary-task functions, and rt_printf. Bindings are generated
from vendored headers (see vendor/bela/COMMIT for the pinned
upstream commit) with cargo xtask bindgen; see the crate README
for how to regenerate them.
One thing here is not the core API and not generated: the
bela_midi_* functions, a C surface this crate
compiles (shim/midi.cpp) over Bela’s Midi class in
libbelaextra. MIDI is what a Bela program reaches for first after
audio, and the class is C++ with only half a C surface of its own.
The other higher-level C++ libraries (Scope, Trill, Fft, Gui)
remain out of scope.
The setup / render / cleanup callbacks are not bound: they are
either provided to Bela_initAudio via BelaInitSettings or
defined as #[unsafe(no_mangle)] symbols by the linking crate.
Target platform is Bela Gem on PocketBeagle 2
(aarch64-unknown-linux-gnu). For a safe API, use the bela
crate instead.
Structs§
- Bela
Channel Gain - Bela
Channel Gain Array - Bela
Context - \ingroup render \brief Structure holding audio and sensor settings and pointers to I/O data buffers.
- Bela
CpuData - Bela
Init Settings - \ingroup control \brief Structure containing initialisation parameters for the real-time audio control system.
- Bela
Midi - An opened
Midiobject, as an opaque pointee. - _Bela
HwConfig - option
- timespec
Constants§
- BELA_
AUDIO_ PRIORITY - BELA_
BUGFIX_ VERSION - BELA_
FLAG_ ANALOG_ OUTPUTS_ PERSIST - BELA_
FLAG_ DETECT_ UNDERRUNS - BELA_
FLAG_ INTERLEAVED - BELA_
FLAG_ OFFLINE - BELA_
MAJOR_ VERSION - BELA_
MIDI_ ALREADY_ OPEN - That direction of this object is already open.
- BELA_
MIDI_ MESSAGE_ MAX - Bytes of the longest message
bela_midi_get_messagewrites: a status byte and two data bytes. - BELA_
MIDI_ NO_ SUCH_ PORT - No port has the name that was given.
- BELA_
MINOR_ VERSION - Bela
HwDetect Mode_ Cache - < read cached value from
/run/bela/belaconfigfirst. If it does not exist, fall back to #BelaHwDetectMode_Scan - Bela
HwDetect Mode_ Cache Only - <read cached value from
/run/bela/belaconfig. If it does not exist, return #BelaHw_NoHw - Bela
HwDetect Mode_ Scan - < perform an automatic detection by scanning the peripherals and busses available, and cache value in
/run/bela/belaconfig - Bela
HwDetect Mode_ User - <read user-specified value from
~/.bela/belaconfig. If it does not exist, fall back to #BelaHwDetectMode_Cache - Bela
HwDetect Mode_ User Only - <read user-specified value from
~/.bela/belaconfig. If it does not exist, return #BelaHw_NoHw - Bela
Hw_ Batch - < Dummy offline
- Bela
Hw_ Bela - < Bela
- Bela
Hw_ Bela Es9080 - < A Bela cape with Es9080 EVB on top, all as audio
- Bela
Hw_ Bela Mini - < Bela Mini
- Bela
Hw_ Bela Mini Multi Audio - < Bela Mini with extra codecs
- Bela
Hw_ Bela Mini Multi I2s - < Bela Mini with extra rx and tx I2S data lines.
- Bela
Hw_ Bela Mini Multi Tdm - < Bela Mini with extra codecs and/or tdm devices
- Bela
Hw_ Bela Multi Tdm - < Bela with extra codecs and/or tdm devices
- Bela
Hw_ Bela RevC - < A Bela cape rev C: Es9080 is used for analog outs
- Bela
Hw_ Ctag Beast - < Ctag Beast
- Bela
Hw_ Ctag Beast Bela - < Ctag Beast and Bela cape
- Bela
Hw_ Ctag Face - < Ctag Face
- Bela
Hw_ Ctag Face Bela - < Ctag Face and Bela cape
- Bela
Hw_ GemMulti - < Gem Multi
- Bela
Hw_ GemStereo - < Gem Stereo
- Bela
Hw_ NoHw - < No hardware
- Bela
Hw_ Salt - < Salt
- DEFAULT_
HP_ LEVEL - DEFAULT_
LINE_ OUT_ LEVEL - DEFAULT_
PGA_ GAIN - INPUT
- OUTPUT
Functions§
- Bela_
HwConfig_ ⚠delete - Use this to delete a pointer returned by Bela_HwConfig_new()
- Bela_
HwConfig_ ⚠new - Returns the configuration for a given BelaHw or
nullptrifhwis invalid. - Bela_
Init ⚠Settings_ alloc - \brief Allocate the data structure containing settings for Bela.
- Bela_
Init ⚠Settings_ free - \brief De-allocate the data structure containing settings for Bela.
- Bela_
cleanup ⚠Audio - \brief Clean up resources from audio and sensor processing.
- Bela_
clock_ ⚠gettime - Bela_
cpuMonitoring ⚠Get - Get stats about internal CPU monitoring.
- Bela_
cpuMonitoring ⚠Init - Set internal CPU monitoring for the audio thread. @param count Number of samples (tic/toc pairs) in a acquisition cycle. Use 0 to disable. @return 0 on success, an error code otherwise.
- Bela_
cpuTic ⚠ - Start measuring CPU time. When
data->currentCountreachesdata->count, a acquisition cycle is completed.data->percentagegives the average CPU busy time during the latest completed acquisition cycle. - Bela_
cpuToc ⚠ - Stop measuring CPU time.
- Bela_
create ⚠Auxiliary Task - \brief Create a new auxiliary task.
- Bela_
default ⚠Settings - \brief Initialise the data structure containing settings for Bela.
- Bela_
delete ⚠AllAuxiliary Tasks - Bela_
detect ⚠Hw - \brief Detect what hardware we are running on.
- Bela_
getVersion ⚠ - \brief Get the version of Bela you are running.
- Bela_
getopt_ ⚠long - \brief Get long options from command line argument list, including Bela standard options
- Bela_
gettime ⚠ - Bela_
init ⚠Audio - \brief Initialise audio and sensor rendering environment.
- Bela_
init ⚠RtBackend - \defgroup warppers Wrappers for real-time functionalities.
- Bela_
mute ⚠Speakers - \brief Mute or unmute the onboard speaker amplifiers.
- Bela_
nanosleep ⚠ - Bela_
print ⚠Flush Buffers - Bela_
printf ⚠ - Bela_
request ⚠Stop - \brief Tell the Bela program to stop.
- Bela_
runIn ⚠Same Thread - \brief Begin processing audio and sensor data in the same thread as the caller.
- Bela_
schedule ⚠Auxiliary Task - \brief Run an auxiliary task which has previously been created.
- Bela_
setADC ⚠Level - DEPRECATED.
- Bela_
setAdc ⚠Level - \brief Set the level of the audio ADC.
- Bela_
setAudio ⚠Input Gain - \brief Set the gain of the audio input preamplifier.
- Bela_
setDAC ⚠Level - DEPRECATED.
- Bela_
setDac ⚠Level - \brief Set the level of the audio DAC.
- Bela_
setHeadphone ⚠Level - DEPRECATED Equivalent to Bela_setHpLevel(-1, decibels);
- Bela_
setHp ⚠Level - \brief Set the level of the onboard headphone amplifier.
- Bela_
setLine ⚠OutLevel - \brief Set the level of the audio line out.
- Bela_
setPga ⚠Gain - DEPRECATED.
- Bela_
setUser ⚠Data - \brief Set the
userDatavariable, which is passed to setup(), render() and cleanup(). - Bela_
setVerbose ⚠Level - \brief Set level of verbose (debugging) printing.
- Bela_
start ⚠Audio - \brief Begin processing audio and sensor data.
- Bela_
stop ⚠Audio - \brief Stop processing audio and sensor data.
- Bela_
stop ⚠Requested - \brief Check whether the program should stop.
- Bela_
usage ⚠ - \brief Print usage information for Bela standard options.
- Bela_
user ⚠Settings - \brief Initialise the data structure containing settings for Bela.
- bela_
midi_ ⚠available_ messages - How many parsed messages are waiting. Reads two ring indices:
no allocation, no system call — and no synchronisation either,
the input thread writing them as plain
unsigned ints. What that can cost is a count one message stale. - bela_
midi_ ⚠delete - Destroys a
Midiobject, joining its input thread. Null is accepted. Blocks for as long as that thread takes to notice, which is up to its 50 ms poll timeout. - bela_
midi_ ⚠get_ message - Writes the oldest waiting message into
buf, which must have room forBELA_MIDI_MESSAGE_MAXbytes, and returns how many bytes it wrote — 0 when nothing was waiting, leavingbufuntouched. The status byte carries the channel in its low nibble, as on the wire. - bela_
midi_ ⚠list_ ports - Writes every MIDI port ALSA reports into
bufas NUL-terminated names, one after another, and returns the bytes the whole list needs. Alenshorter than that holds as many whole names as fit.bufmay be null whenlenis 0, which is how to ask for the size before allocating. - bela_
midi_ ⚠new - Creates a
Midiobject with its input parser enabled, opening no port. Returns null if it could not be created. - bela_
midi_ ⚠read_ from - Opens
portfor input and starts reading from it, once per object. Returns 0 when input is enabled afterwards,BELA_MIDI_NO_SUCH_PORT,BELA_MIDI_ALREADY_OPEN, or a negative value from Bela —-errnowhen ALSA refused the device. - bela_
midi_ ⚠write_ output - Hands
lengthbytes to Bela’s output task. Returns 1, or 0 if output was never enabled — and 1 says the bytes were handed over, not that they were queued or sent. The-1in the C++ is unreachable whilecommsSendreports success unconditionally, which is what makes 1 and 0 the whole range. - bela_
midi_ ⚠write_ to - Opens
portfor output, once per object, with the same return values asbela_midi_read_fromand the same end after a failure. - rt_
printf ⚠
Type Aliases§
- Auxiliary
Task - \ingroup auxtask
- Bela
Digital Direction - \defgroup iofunctions I/O functions and constants
- BelaHw
- A type of Bela hardware.
- Bela
HwConfig - Bela
HwDetect Mode - Arguments to be passed to Bela_detectHw()
- __
clockid_ t - __
syscall_ slong_ t - __
time_ t - clockid_
t