Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Bela.h
Go to the documentation of this file.
1 
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
88 extern "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
99 int rt_printf(const char *format, ...);
100 int rt_fprintf(FILE *stream, const char *format, ...);
101 int rt_vprintf(const char *format, va_list ap);
102 int rt_vfprintf(FILE *stream, const char *format, va_list ap);
103 
107 typedef enum
108 {
109  BelaHw_NoHw = -1,
124 } BelaHw;
125 
126 typedef 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 
143 
148 
152 typedef enum
153 {
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
169 
178 #define BELA_AUDIO_PRIORITY 95
179 
180 // Default volume levels
181 
191 #define DEFAULT_LINE_OUT_LEVEL 0.0
192 
196 #define DEFAULT_PGA_GAIN 16
197 
201 #define DEFAULT_HP_LEVEL -6.0
202 
207 #define BELA_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved
208 
211 #define BELA_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers
212 
215 #define BELA_FLAG_DETECT_UNDERRUNS (1 << 2) // Set if the user will be displayed a message when an underrun occurs
216 
219 #define BELA_FLAG_OFFLINE (1 << 3)
220 
221 struct option;
222 
231 typedef 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;
421 } BelaContext;
422 
424  int channel;
425  float gain;
426 };
427 
429  unsigned int length;
430  struct BelaChannelGain* data;
431 };
441 typedef struct {
442  // These items might be adjusted by the user:
443 
464 
468  float dacLevel;
470  float adcLevel;
472  float pgaGain[2];
478  unsigned int audioExpanderInputs;
480  unsigned int audioExpanderOutputs;
481 
485  char pruFilename[MAX_PRU_FILENAME_LENGTH];
489  int verbose;
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*);
534  char* codecMode;
536  struct BelaChannelGainArray audioInputGains;
538  struct BelaChannelGainArray headphoneGains;
540  struct BelaChannelGainArray adcGains;
542  struct BelaChannelGainArray lineOutGains;
545 
546  char unused[MAX_UNUSED_LENGTH];
547 
550 
552  char* projectName;
553 
555 
561 typedef void* AuxiliaryTask; // Opaque data type to keep track of aux tasks
562 
579 extern int volatile gShouldStop;
580 
581 // *** User-defined render functions ***
582 
609 bool setup(BelaContext *context, void *userData);
610 
625 void render(BelaContext *context, void *userData);
626 
642 void cleanup(BelaContext *context, void *userData);
643 
655 // *** Command-line settings ***
656 
657 
666 
676 
686 void Bela_defaultSettings(BelaInitSettings *settings);
687 
688 #pragma weak Bela_userSettings
689 
700 void Bela_userSettings(BelaInitSettings *settings);
701 
723 int Bela_getopt_long(int argc, char * const argv[], const char *customShortOptions,
724  const struct option *customLongOptions, BelaInitSettings *settings);
725 
733 void Bela_usage();
734 
738 void Bela_getVersion(int* major, int* minor, int* bugfix);
739 
746 void Bela_setVerboseLevel(int level);
747 
748 
756 
757 // *** Audio control functions ***
758 
774 int Bela_initAudio(BelaInitSettings *settings, void *userData);
775 
784 int Bela_startAudio();
785 
795 
802 void Bela_stopAudio();
803 
811 void Bela_cleanupAudio();
812 
820 void Bela_setUserData(void* newUserData);
821 
834 void Bela_requestStop();
835 
845 int Bela_stopRequested();
846 
848 #ifndef BELA_DISABLE_CPU_TIME
849 
871 #include <time.h>
872 typedef 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;
879  float percentage;
880 } BelaCpuData;
886 int Bela_cpuMonitoringInit(int count);
901 void Bela_cpuTic(BelaCpuData* data);
907 void Bela_cpuToc(BelaCpuData* data);
908 
910 #endif // BELA_DISABLE_CPU_TIME
911 
921 // *** Volume and level controls ***
922 
934 int Bela_setLineOutLevel(int channel, float decibel);
935 
943 int Bela_setDacLevel(int channel, float decibels);
944 
950 int Bela_setDACLevel(float decibels);
951 
967 int Bela_setAdcLevel(int channel, float decibels);
968 
974 int Bela_setADCLevel(float decibels);
975 
976 
993 int Bela_setAudioInputGain(int channel, float decibels);
994 
1000 int Bela_setPgaGain(float decibels, int channel);
1001 
1018 int Bela_setHpLevel(int channel, float decibels);
1023 int Bela_setHeadphoneLevel(float decibels);
1024 
1038 int Bela_muteSpeakers(int mute);
1039 
1056 // *** Functions for creating auxiliary tasks ***
1057 
1074 AuxiliaryTask Bela_createAuxiliaryTask(void (*callback)(void*), int priority, const char *name, void* arg
1075 #ifdef __cplusplus
1076 = NULL
1077 #endif /* __cplusplus */
1078 );
1079 
1095 int Bela_scheduleAuxiliaryTask(AuxiliaryTask task);
1096 
1109 #ifdef __cplusplus
1110 AuxiliaryTask Bela_runAuxiliaryTask(void (*callback)(void*), int priority = 0, void* arg = nullptr);
1111 #endif // __cplusplus
1112 
1130 int Bela_startAuxiliaryTask(AuxiliaryTask task);
1131 int Bela_startAllAuxiliaryTasks();
1132 void Bela_stopAllAuxiliaryTasks();
1133 void Bela_deleteAllAuxiliaryTasks();
1134 
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 
1158 enum {
1159  INPUT = 0,
1160  OUTPUT = 1,
1161 };
1170 #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 
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 
1209 static inline float audioRead(BelaContext *context, int frame, int channel);
1210 
1216 static inline float audioReadNI(BelaContext *context, int frame, int channel);
1217 
1231 static inline void audioWrite(BelaContext *context, int frame, int channel, float value);
1232 
1238 static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value);
1239 
1253 static inline float analogRead(BelaContext *context, int frame, int channel);
1254 
1260 static inline float analogReadNI(BelaContext *context, int frame, int channel);
1261 
1278 static inline void analogWrite(BelaContext *context, int frame, int channel, float value);
1279 
1285 static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value);
1286 
1306 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value);
1307 
1313 static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value);
1314 
1329 static inline int digitalRead(BelaContext *context, int frame, int channel);
1330 
1347 static inline void digitalWrite(BelaContext *context, int frame, int channel, int value);
1348 
1367 static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value);
1368 
1385 static inline void pinMode(BelaContext *context, int frame, int channel, int mode);
1386 
1403 static 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 
1428 static 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 
1451 static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame);
1452 
1455 // audioRead()
1456 //
1457 // Returns the value of the given audio input at the given frame number.
1458 static inline float audioRead(BelaContext *context, int frame, int channel) {
1459  return context->audioIn[frame * context->audioInChannels + channel];
1460 }
1461 
1462 static 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
1469 static inline void audioWrite(BelaContext *context, int frame, int channel, float value) {
1470  context->audioOut[frame * context->audioOutChannels + channel] = value;
1471 }
1472 
1473 static 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.
1480 static inline float analogRead(BelaContext *context, int frame, int channel) {
1481  return context->analogIn[frame * context->analogInChannels + channel];
1482 }
1483 
1484 static 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
1491 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) {
1492  context->analogOut[frame * context->analogOutChannels + channel] = value;
1493 }
1494 
1495 static 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
1503 static 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 
1509 static 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
1518 static 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
1525 static 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
1538 static 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
1548 static 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
1561 static 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.
1571 static 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.
1578 static 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_ */
float percentage
Average CPU usage during previous acquisition cycle.
Definition: Bela.h:879
char * codecMode
A codec-specific intialisation parameter.
Definition: Bela.h:534
int detectUnderruns
Whether to detect and log underruns.
Definition: Bela.h:487
uint32_t disabledDigitalChannels
A bitmask of disabled digital channels.
Definition: Bela.h:544
Dummy offline.
Definition: Bela.h:123
read user-specified value from ~/.bela/belaconfig. If it does not exist, fall back to BelaHwDetectMod...
Definition: Bela.h:157
Bela Mini with extra codecs and/or tdm devices.
Definition: Bela.h:118
const uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition: Bela.h:385
Ctag Beast and Bela cape.
Definition: Bela.h:116
const float *const analogIn
Buffer holding analog input samples.
Definition: Bela.h:283
int Bela_stopRequested()
Check whether the program should stop.
static void audioWriteNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of audioWrite()
Definition: Bela.h:1473
Bela with extra codecs and/or tdm devices.
Definition: Bela.h:119
long long unsigned int total
Total CPU time (between tic and previous tic) during the current acquisition cycle.
Definition: Bela.h:876
float adcLevel
Level for the audio ADC input. DEPRECATED: use audioInputGains.
Definition: Bela.h:470
int ampMutePin
Pin where amplifier mute can be found.
Definition: Bela.h:528
const uint32_t audioInChannels
The number of audio input channels.
Definition: Bela.h:324
const float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0)
Definition: Bela.h:371
int Bela_setAudioInputGain(int channel, float decibels)
Set the gain of the audio input preamplifier.
int volatile gShouldStop
const uint32_t analogInChannels
The number of analog input channels.
Definition: Bela.h:346
int Bela_scheduleAuxiliaryTask(AuxiliaryTask task)
Run an auxiliary task which has previously been created.
void Bela_usage()
Print usage information for Bela standard options.
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 audioReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of audioRead()
Definition: Bela.h:1462
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
void Bela_cpuTic(BelaCpuData *data)
float headphoneLevel
Level for the headphone output. DEPRECATED: use headphoneGains.
Definition: Bela.h:474
const uint32_t analogOutChannels
The number of analog output channels.
Definition: Bela.h:351
float gain
Gain in dB.
Definition: Bela.h:425
BelaCpuData * Bela_cpuMonitoringGet()
void Bela_setVerboseLevel(int level)
Set level of verbose (debugging) printing.
const uint32_t multiplexerStartingChannel
Multiplexer channel corresponding to the first analog frame.
Definition: Bela.h:391
static void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWriteNI()
Definition: Bela.h:1495
BelaHwConfig * Bela_HwConfig_new(BelaHw hw)
const uint32_t flags
Other audio/sensor settings.
Definition: Bela.h:414
int Bela_setDACLevel(float decibels)
int verbose
Whether to use verbose logging.
Definition: Bela.h:489
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.
const uint32_t digitalChannels
Number of digital channels.
Definition: Bela.h:369
perform an automatic detection by scanning the peripherals and busses available, and cache value in /...
Definition: Bela.h:154
int Bela_setAdcLevel(int channel, float decibels)
Set the level of the audio ADC.
const uint32_t digitalFrames
Number of digital frames per period.
Definition: Bela.h:365
void Bela_getVersion(int *major, int *minor, int *bugfix)
Get the version of Bela you are running.
Bela Mini with extra codecs.
Definition: Bela.h:117
int numAudioInChannels
How many audio input channels [ignored].
Definition: Bela.h:455
BelaHw
Definition: Bela.h:107
unsigned int audioExpanderOutputs
Which audio expander settings to use on the input.
Definition: Bela.h:480
void Bela_cpuToc(BelaCpuData *data)
int Bela_setHeadphoneLevel(float decibels)
int pruNumber
Which PRU (0 or 1) the code should run on.
Definition: Bela.h:483
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition: render.cpp:96
BelaInitSettings * Bela_InitSettings_alloc()
Allocate the data structure containing settings for Bela.
read cached value from /run/bela/belaconfig first. If it does not exist, fall back to BelaHwDetectMod...
Definition: Bela.h:155
void Bela_requestStop()
Tell the Bela program to stop.
Bela Mini with extra rx and tx I2S data lines.
Definition: Bela.h:120
void Bela_userSettings(BelaInitSettings *settings)
Initialise the data structure containing settings for Bela.
Definition: render.cpp:64
static void analogWriteNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWrite()
Definition: Bela.h:1509
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
Definition: Bela.h:423
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
Structure containing initialisation parameters for the real-time audio control system.
Definition: Bela.h:441
float *const audioOut
Buffer holding audio output samples.
Definition: Bela.h:264
int numAudioOutChannels
How many audio out channels [ignored].
Definition: Bela.h:457
char * projectName
Name of running project.
Definition: Bela.h:552
int interleave
Whether audio/analog data should be interleaved.
Definition: Bela.h:505
const uint32_t audioFrames
The number of audio frames per block.
Definition: Bela.h:322
void Bela_HwConfig_delete(BelaHwConfig *cfg)
void Bela_stopAudio()
Stop processing audio and sensor data.
AuxiliaryTask Bela_runAuxiliaryTask(void(*callback)(void *), int priority=0, void *arg=nullptr)
Create and start an AuxiliaryTask.
void Bela_setUserData(void *newUserData)
Set the userData variable, which is passed to setup(), render() and cleanup().
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
No hardware.
Definition: Bela.h:109
Definition: Bela.h:872
int Bela_muteSpeakers(int mute)
Mute or unmute the onboard speaker amplifiers.
BelaHw board
User selected board to work with (as opposed to detected hardware).
Definition: Bela.h:549
AuxiliaryTask Bela_createAuxiliaryTask(void(*callback)(void *), int priority, const char *name, void *arg=NULL)
Create a new auxiliary task.
const float analogSampleRate
Analog sample rate in Hz.
Definition: Bela.h:362
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition: Bela.h:231
const uint32_t audioExpanderEnabled
Flags for whether audio expander is enabled on given analog channels.
Definition: Bela.h:404
A Bela cape rev C: Es9080 is used for analog outs.
Definition: Bela.h:122
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition: render.cpp:51
BelaHw Bela_detectHw(BelaHwDetectMode mode)
Detect what hardware we are running on.
int uniformSampleRate
Whether the analog channels should be resampled to audio sampling rate.
Definition: Bela.h:512
Ctag Face.
Definition: Bela.h:113
int count
Number of samples (tic/toc pairs) in a acquisition cycle. Use 0 to disable.
Definition: Bela.h:873
int numMuxChannels
How many channels to use on the multiplexer capelet, if enabled.
Definition: Bela.h:476
int Bela_initAudio(BelaInitSettings *settings, void *userData)
Initialise audio and sensor rendering environment.
Salt.
Definition: Bela.h:112
int numAnalogOutChannels
How many analog output channels.
Definition: Bela.h:461
int Bela_setLineOutLevel(int channel, float decibel)
Set the level of the audio line out.
Ctag Face and Bela cape.
Definition: Bela.h:115
Bela.
Definition: Bela.h:110
float *const analogOut
Buffer holding analog output samples.
Definition: Bela.h:298
const uint32_t audioOutChannels
The number of audio output channels.
Definition: Bela.h:326
int Bela_setPgaGain(float decibels, int channel)
int Bela_cpuMonitoringInit(int count)
int beginMuted
Whether to begin with the speakers muted.
Definition: Bela.h:466
int numAnalogInChannels
How many analog input channels.
Definition: Bela.h:459
Definition: Bela.h:428
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
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition: render.cpp:68
BelaHwDetectMode
Definition: Bela.h:152
read cached value from /run/bela/belaconfig. If it does not exist, return BelaHw_NoHw ...
Definition: Bela.h:156
read user-specified value from ~/.bela/belaconfig. If it does not exist, return BelaHw_NoHw ...
Definition: Bela.h:158
uint32_t *const digital
Buffer holding digital input/output samples.
Definition: Bela.h:308
const unsigned int underrunCount
Number of detected underruns.
Definition: Bela.h:420
const uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition: Bela.h:379
unsigned int audioExpanderInputs
Which audio expander settings to use on the input.
Definition: Bela.h:478
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
float dacLevel
Level for the audio DAC output. DEPRECATED: ues lineOutGains.
Definition: Bela.h:468
Bela Mini.
Definition: Bela.h:111
int Bela_setADCLevel(float decibels)
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
void Bela_InitSettings_free(BelaInitSettings *settings)
De-allocate the data structure containing settings for Bela.
const uint32_t analogFrames
The number of analog frames per block.
Definition: Bela.h:341
int highPerformanceMode
Definition: Bela.h:499
int numDigitalChannels
How many channels for the GPIOs.
Definition: Bela.h:463
int stopButtonPin
Definition: Bela.h:494
void * AuxiliaryTask
Definition: Bela.h:561
static float analogReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of analogRead()
Definition: Bela.h:1484
const float *const multiplexerAnalogIn
Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.
Definition: Bela.h:398
Definition: Bela.h:126
int Bela_setDacLevel(int channel, float decibels)
Set the level of the audio DAC.
Ctag Beast.
Definition: Bela.h:114
int Bela_runInSameThread()
Begin processing audio and sensor data in the same thread as the caller.
int channel
Channel number. Negative value means all the channels.
Definition: Bela.h:424
int enableLED
Whether to use the blinking LED to indicate Bela is running.
Definition: Bela.h:491
long long unsigned int busy
Total CPU time spent being busy (between tic and toc) during the current acquisition cycle...
Definition: Bela.h:875
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
int Bela_setHpLevel(int channel, float decibels)
Set the level of the onboard headphone amplifier.
int useAnalog
Whether to use the analog input and output.
Definition: Bela.h:451
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
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0)
Definition: Bela.h:328
int Bela_startAudio()
Begin processing audio and sensor data.
int periodSize
Number of audio frames per period ("blocksize").
Definition: Bela.h:449
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
int analogOutputsPersist
Whether analog outputs should persist to future frames.
Definition: Bela.h:509
const float *const audioIn
Buffer holding audio input samples.
Definition: Bela.h:249
int useDigital
Whether to use the 16 programmable GPIOs.
Definition: Bela.h:453
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
void Bela_defaultSettings(BelaInitSettings *settings)
Initialise the data structure containing settings for Bela.
int Bela_startAuxiliaryTask(AuxiliaryTask task)
Initialize an auxiliary task so that it can be scheduled.
unsigned int currentCount
Number of tics in current acquisition cycle.
Definition: Bela.h:874
A Bela cape with Es9080 EVB on top, all as audio.
Definition: Bela.h:121
void Bela_cleanupAudio()
Clean up resources from audio and sensor processing.