Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
Bela.h
Go to the documentation of this file.
1
13
26
27#ifndef BELA_H_
28#define BELA_H_
29#define BELA_MAJOR_VERSION 1
30#define BELA_MINOR_VERSION 13
31#define BELA_BUGFIX_VERSION 0
32
33// Version history / changelog:
34// 1.14.0
35// - added disabledDigitalChannels to BelaInitSettings and corresponding command-line
36// 1.13.0
37// - added Bela_setLineOutLevel() which replaces Bela_setDacLevel() (though
38// with different semantics).
39// - in BelaInitSettings, dacGains is _replaced_ by lineOutGains
40// - replaced --dac-level with --line-out-level, -D now means --line-out-level
41// - replaced DEFAULT_DAC_LEVEL with DEFAULT_LINE_OUT_LEVEL
42// - removed setAdcLevel(): use setAudioInputGain() instead
43// - removed -A/--adc-gain, now ignored (non-bw-compatible)
44// - removed DEFAULT_ADC_LEVEL
45// - deprecated Bela_setDacLevel()
46// 1.12.0
47// - added Bela_cpuTic(), Bela_cpuToc(), Bela_cpuMonitoringInit(),
48// Bela_cpuMonitoringGet() and BelaCpuData.
49// 1.11.0
50// - added BelaChannelGain and BelaChannelGainArray
51// - added setHpLevel(), setAudioInputGain(), setAdcLevel(), setDacLevel(),
52// deprecated the functions they are intended to replace
53// - added the corresponding fields in BelaInitSettings: headphoneGains,
54// audioInputGains, adcGains, dacGains
55// 1.10.0
56// - added parameter to Bela_detectHw(), and associated typedef
57// - added more values to the BelaHw enum
58// - added codecMode to BelaInitSettings
59// 1.9.0
60// - added Bela_HwConfig_{new,delete}
61// 1.8.0
62// - added callback for when the audio thread is done: settings->audioThreadDone
63// 1.7.0
64// - Bela_getopt_long takes a char* const []
65// - added the functions and definitions from Utilities.h
66// - INPUT and OUTPUT are now an enum
67// 1.6.0
68// - added Bela_setUserData(), Bela_requestStop(), Bela_stopRequested()
69// 1.5.1
70// - in BelaInitSettings, renamed unused members, preserving binary compatibility
71// 1.5.0
72// - in BelaInitSettings, board becomes BelaHw
73// - added to BelaInitSettings char* projectName
74// - added to BelaContext char* projectName
75// 1.4.0
76// - added allocator/de-allocator for BelaInitSettings
77// - added char board field to BelaInitSettings
78// 1.3.0
79// - removed define for I2C codec address
80// - removed user option in settings for I2C address
81// 1.2.0
82// - renames and re-ordered BelaHw enum
83// 1.1.0
84// - adds BelaHw, Bela_detectHw()
85// - removes digital_gpio_mapping.h
86
87#ifdef __cplusplus
88extern "C"
89{
90#endif
91
92#include <stdint.h>
93#include <unistd.h>
94#include <stdbool.h>
95#include <stdio.h>
96// these functions are currently provided by xenomai.
97// We put these declarations here so we do not have to include
98// Xenomai specific files
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);
103
125
126typedef struct _BelaHwConfig
127{
128 float audioSampleRate;
129 unsigned int audioInChannels;
130 unsigned int audioOutChannels;
131 unsigned int analogInChannels;
132 unsigned int analogOutChannels;
133 unsigned int digitalChannels;
134} BelaHwConfig;
135
142BelaHwConfig* Bela_HwConfig_new(BelaHw hw);
143
147void Bela_HwConfig_delete(BelaHwConfig* cfg);
148
160
161#include <GPIOcontrol.h>
162
163// Useful constants
164
166#define MAX_PRU_FILENAME_LENGTH 256
167#define MAX_UNUSED_LENGTH 220
168#define MAX_PROJECTNAME_LENGTH 256
170
178#define BELA_AUDIO_PRIORITY 95
179
180// Default volume levels
181
187
191#define DEFAULT_LINE_OUT_LEVEL 0.0
192
196#define DEFAULT_PGA_GAIN 16
197
201#define DEFAULT_HP_LEVEL -6.0
203
207#define BELA_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved
211#define BELA_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers
215#define BELA_FLAG_DETECT_UNDERRUNS (1 << 2) // Set if the user will be displayed a message when an underrun occurs
219#define BELA_FLAG_OFFLINE (1 << 3)
220
221struct option;
222
231typedef struct {
249 const float * const audioIn;
250
264 float * const audioOut;
265
283 const float * const analogIn;
284
298 float * const analogOut;
299
308 uint32_t * const digital;
309
322 const uint32_t audioFrames;
324 const uint32_t audioInChannels;
326 const uint32_t audioOutChannels;
328 const float audioSampleRate;
329
341 const uint32_t analogFrames;
342
346 const uint32_t analogInChannels;
347
351 const uint32_t analogOutChannels;
352
362 const float analogSampleRate;
363
365 const uint32_t digitalFrames;
369 const uint32_t digitalChannels;
371 const float digitalSampleRate;
372
379 const uint64_t audioFramesElapsed;
380
385 const uint32_t multiplexerChannels;
386
392
398 const float * const multiplexerAnalogIn;
399
404 const uint32_t audioExpanderEnabled;
405
414 const uint32_t flags;
415
417 char projectName[MAX_PROJECTNAME_LENGTH];
418
420 const unsigned int underrunCount;
422
425 float gain;
426};
427
429 unsigned int length;
430 struct BelaChannelGain* data;
431};
432
441typedef struct {
442 // These items might be adjusted by the user:
443
464
468 float dacLevel;
470 float adcLevel;
472 float pgaGain[2];
481
485 char pruFilename[MAX_PRU_FILENAME_LENGTH];
500
501 // These items are application-dependent but should probably be
502 // determined by the programmer rather than the user
503
514 // to 128KiB
515 unsigned int audioThreadStackSize;
517 // to 128KiB
518 unsigned int auxiliaryTaskStackSize;
519
520 // Pointers to the user-defined functions
521 bool (*setup)(BelaContext*, void*);
522 void (*render)(BelaContext*, void*);
523 void (*cleanup)(BelaContext*, void*);
524 // These items are hardware-dependent and should only be changed
525 // to run on different hardware
526
529
532 void (*audioThreadDone)(BelaContext*, void*);
545
546 char unused[MAX_UNUSED_LENGTH];
547
550
553
555
561typedef void* AuxiliaryTask; // Opaque data type to keep track of aux tasks
562
579extern int volatile gShouldStop;
580
581// *** User-defined render functions ***
582
591
609bool setup(BelaContext *context, void *userData);
610
625void render(BelaContext *context, void *userData);
626
642void cleanup(BelaContext *context, void *userData);
643
645
654
655// *** Command-line settings ***
656
657
666
676
687
688#pragma weak Bela_userSettings
700void Bela_userSettings(BelaInitSettings *settings);
701
723int Bela_getopt_long(int argc, char * const argv[], const char *customShortOptions,
724 const struct option *customLongOptions, BelaInitSettings *settings);
725
734
738void Bela_getVersion(int* major, int* minor, int* bugfix);
739
746void Bela_setVerboseLevel(int level);
747
748
756
757// *** Audio control functions ***
758
774int Bela_initAudio(BelaInitSettings *settings, void *userData);
775
785
795
803
812
820void Bela_setUserData(void* newUserData);
821
835
846
848#ifndef BELA_DISABLE_CPU_TIME
871#include <time.h>
872typedef struct {
873 int count;
874 unsigned int currentCount;
875 long long unsigned int busy;
876 long long unsigned int total;
877 struct timespec tic;
878 struct timespec toc;
881
908
910#endif // BELA_DISABLE_CPU_TIME
911
920
921// *** Volume and level controls ***
922
934int Bela_setLineOutLevel(int channel, float decibel);
935
943int Bela_setDacLevel(int channel, float decibels);
944
950int Bela_setDACLevel(float decibels);
951
967int Bela_setAdcLevel(int channel, float decibels);
968
974int Bela_setADCLevel(float decibels);
975
976
993int Bela_setAudioInputGain(int channel, float decibels);
994
1000int Bela_setPgaGain(float decibels, int channel);
1001
1018int Bela_setHpLevel(int channel, float decibels);
1023int Bela_setHeadphoneLevel(float decibels);
1024
1038int Bela_muteSpeakers(int mute);
1039
1041
1055
1056// *** Functions for creating auxiliary tasks ***
1057
1074AuxiliaryTask Bela_createAuxiliaryTask(void (*callback)(void*), int priority, const char *name, void* arg
1075#ifdef __cplusplus
1076= NULL
1077#endif /* __cplusplus */
1078);
1079
1096
1109#ifdef __cplusplus
1110AuxiliaryTask Bela_runAuxiliaryTask(void (*callback)(void*), int priority = 0, void* arg = nullptr);
1111#endif // __cplusplus
1129
1131int Bela_startAllAuxiliaryTasks();
1132void Bela_stopAllAuxiliaryTasks();
1133void Bela_deleteAllAuxiliaryTasks();
1134
1136
1137// You may want to define the macro below in case `Utilities.h` causes namespace conflicts
1138#ifndef BELA_DONT_INCLUDE_UTILITIES
1139#include <Utilities.h>
1140#endif // BELA_DONT_INCLUDE_UTILITIES
1141
1157
1158enum {
1159 INPUT = 0,
1160 OUTPUT = 1,
1161};
1163
1169
1171#define Bela_setBit(word,bit) ((word) | (1 << (bit)))
1172
1174#define Bela_clearBit(word,bit) ((word) &~ (1 << (bit)))
1175
1177#define Bela_getBit(word,bit) (((word) >> (bit)) & 1)
1178
1180#define Bela_changeBit(word,bit,value) ((Bela_clearBit((word),(bit))) | ((value) << (bit)))
1181
1185
1191
1192// Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup()
1193// Likewise, thread launch should be able to be called from setup()
1194// Also, make volume change functions callable from render() thread -- as an aux task?
1195
1209static inline float audioRead(BelaContext *context, int frame, int channel);
1210
1216static inline float audioReadNI(BelaContext *context, int frame, int channel);
1217
1231static inline void audioWrite(BelaContext *context, int frame, int channel, float value);
1232
1238static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value);
1239
1253static inline float analogRead(BelaContext *context, int frame, int channel);
1254
1260static inline float analogReadNI(BelaContext *context, int frame, int channel);
1261
1278static inline void analogWrite(BelaContext *context, int frame, int channel, float value);
1279
1285static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value);
1286
1306static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value);
1307
1313static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value);
1314
1329static inline int digitalRead(BelaContext *context, int frame, int channel);
1330
1347static inline void digitalWrite(BelaContext *context, int frame, int channel, int value);
1348
1367static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value);
1368
1385static inline void pinMode(BelaContext *context, int frame, int channel, int mode);
1386
1403static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode);
1404
1405/*
1406 * \brief Returns the value of the given multiplexer channel for the given analog input.
1407 *
1408 * This function reads an input from the Multiplexer Capelet hardware, which needs to be
1409 * attached and enabled by selecting 16, 32 or 64 analog input channels in the command line
1410 * arguments. With the Multiplexer Capelet, each analog input can be connected to one of 8
1411 * multiplexer channels. This function will return a particular multiplexer channel for a
1412 * particular input, with the returned valued being the most recent sample taken from that pin.
1413 *
1414 * Depending on the block size, it may take longer than a single block to scan all multiplexer
1415 * channels. For this reason, successive calls to multiplexerAnalogRead() may return the same
1416 * sample. If you want precise timing control on when a multiplexer input was sampled, use
1417 * multiplexerChannelForFrame() instead to determine which multiplexer channels were sampled
1418 * in a particular block.
1419 *
1420 * \param context The I/O data structure which is passed by Bela to render().
1421 * \param input The analog input to read, i.e. what would be passed as \c channel to analogRead().
1422 * Valid values are 0 to (context->analogInChannels - 1).
1423 * \param muxChannel Which multiplexer channel to read. Valid values are 0 to
1424 * (context->multiplexerChannels - 1).
1425 * \return Value of the analog input from the Multiplexer Capelet.
1426 */
1427
1428static inline float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel);
1429
1430/*
1431 * \brief Returns which multiplexer channel the given analog frame was taken from.
1432 *
1433 * This function indicates what the multiplexer setting was for a given analog input frame.
1434 * This can be used to work out which pin on the Multiplexer Capelet a given analog input sample
1435 * was taken from. For this function to have any meaning, the Multiplexer Capelet hardware must
1436 * be attached and it should be enabled by selecting 16, 32 or 64 analog input channels in the
1437 * command line arguments.
1438 *
1439 * Depending on the block size, it may take longer than a single block to scan all multiplexer
1440 * channels. For this reason, each call to render() may contain only a subset of the available
1441 * multiplexer channels. This function allows you timing precision by knowing at what frame each
1442 * multiplexer reading was taken, but it does not guarantee that all channels can be read in
1443 * any given callback. If you need access to all the multiplexer inputs in every call to render(),
1444 * use multiplexerAnalogRead() instead.
1445 *
1446 * \param context The I/O data structure which is passed by Bela to render().
1447 * \param frame The analog frame (i.e. the time) whose multiplexer setting should be queried.
1448 * \return Multiplexer channel setting at the given frame.
1449 */
1450
1451static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame);
1452
1454
1455// audioRead()
1456//
1457// Returns the value of the given audio input at the given frame number.
1458static inline float audioRead(BelaContext *context, int frame, int channel) {
1459 return context->audioIn[frame * context->audioInChannels + channel];
1460}
1461
1462static inline float audioReadNI(BelaContext *context, int frame, int channel) {
1463 return context->audioIn[channel * context->audioFrames + frame];
1464}
1465
1466// audioWrite()
1467//
1468// Sets a given audio output channel to a value for the current frame
1469static inline void audioWrite(BelaContext *context, int frame, int channel, float value) {
1470 context->audioOut[frame * context->audioOutChannels + channel] = value;
1471}
1472
1473static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value) {
1474 context->audioOut[channel * context->audioFrames + frame] = value;
1475}
1476
1477// analogRead()
1478//
1479// Returns the value of the given analog input at the given frame number.
1480static inline float analogRead(BelaContext *context, int frame, int channel) {
1481 return context->analogIn[frame * context->analogInChannels + channel];
1482}
1483
1484static inline float analogReadNI(BelaContext *context, int frame, int channel) {
1485 return context->analogIn[channel * context->analogFrames + frame];
1486}
1487
1488// analogWriteOnce()
1489//
1490// Sets a given channel to a value for only the current frame
1491static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) {
1492 context->analogOut[frame * context->analogOutChannels + channel] = value;
1493}
1494
1495static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value) {
1496 context->analogOut[channel * context->analogFrames + frame] = value;
1497}
1498
1499// analogWrite()
1500//
1501// Sets a given analog output channel to a value for the current frame and, if persistent outputs are
1502// enabled, for all subsequent frames
1503static inline void analogWrite(BelaContext *context, int frame, int channel, float value) {
1504 unsigned int f;
1505 for(f = frame; f < context->analogFrames; f++)
1506 analogWriteOnce(context, f, channel, value);
1507}
1508
1509static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value) {
1510 unsigned int f;
1511 for(f = frame; f < context->analogFrames; f++)
1512 analogWriteOnceNI(context, f, channel, value);
1513}
1514
1515// digitalRead()
1516//
1517// Returns the value of a given digital input at the given frame number
1518static inline int digitalRead(BelaContext *context, int frame, int channel) {
1519 return Bela_getBit(context->digital[frame], channel + 16);
1520}
1521
1522// digitalWrite()
1523//
1524// Sets a given digital output channel to a value for the current frame and all subsequent frames
1525static inline void digitalWrite(BelaContext *context, int frame, int channel, int value) {
1526 unsigned int f;
1527 for(f = frame; f < context->digitalFrames; f++) {
1528 if(value)
1529 context->digital[f] |= 1 << (channel + 16);
1530 else
1531 context->digital[f] &= ~(1 << (channel + 16));
1532 }
1533}
1534
1535// digitalWriteOnce()
1536//
1537// Sets a given digital output channel to a value for the current frame only
1538static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value) {
1539 if(value)
1540 context->digital[frame] |= 1 << (channel + 16);
1541 else
1542 context->digital[frame] &= ~(1 << (channel + 16));
1543}
1544
1545// pinMode()
1546//
1547// Sets the direction of a digital pin for the current frame and all subsequent frames
1548static inline void pinMode(BelaContext *context, int frame, int channel, int mode) {
1549 unsigned int f;
1550 for(f = frame; f < context->digitalFrames; f++) {
1551 if(mode == INPUT)
1552 context->digital[f] |= (1 << channel);
1553 else
1554 context->digital[f] &= ~(1 << channel);
1555 }
1556}
1557
1558// pinModeOnce()
1559//
1560// Sets the direction of a digital pin for the current frame only
1561static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode) {
1562 if(mode == INPUT)
1563 context->digital[frame] |= (1 << channel);
1564 else
1565 context->digital[frame] &= ~(1 << channel);
1566}
1567
1568// multiplexerAnalogRead()
1569//
1570// Returns the value of the given multiplexer channel for the given analog input.
1571static inline float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel) {
1572 return context->multiplexerAnalogIn[muxChannel * context->analogInChannels + input];
1573}
1574
1575// multiplexerChannelForFrame()
1576//
1577// Returns which multiplexer channel the given analog frame was taken from.
1578static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame) {
1579 if(context->multiplexerChannels <= 1)
1580 return 1;
1581 return (context->multiplexerStartingChannel + frame) % context->multiplexerChannels;
1582}
1583
1584#ifdef __cplusplus
1585}
1586#endif
1587
1588#endif /* BELA_H_ */
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
int volatile gShouldStop
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
Definition Bela.h:428
Definition Bela.h:423
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
Definition Bela.h:872
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
Definition Bela.h:127