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.13.0
35 // - added Bela_setLineOutLevel() which replaces Bela_setDacLevel() (though
36 // with different semantics).
37 // - in BelaInitSettings, dacGains is _replaced_ by lineOutGains
38 // - replaced --dac-level with --line-out-level, -D now means --line-out-level
39 // - replaced DEFAULT_DAC_LEVEL with DEFAULT_LINE_OUT_LEVEL
40 // - removed setAdcLevel(): use setAudioInputGain() instead
41 // - removed -A/--adc-gain, now ignored (non-bw-compatible)
42 // - removed DEFAULT_ADC_LEVEL
43 // - deprecated Bela_setDacLevel()
44 // 1.12.0
45 // - added Bela_cpuTic(), Bela_cpuToc(), Bela_cpuMonitoringInit(),
46 // Bela_cpuMonitoringGet() and BelaCpuData.
47 // 1.11.0
48 // - added BelaChannelGain and BelaChannelGainArray
49 // - added setHpLevel(), setAudioInputGain(), setAdcLevel(), setDacLevel(),
50 // deprecated the functions they are intended to replace
51 // - added the corresponding fields in BelaInitSettings: headphoneGains,
52 // audioInputGains, adcGains, dacGains
53 // 1.10.0
54 // - added parameter to Bela_detectHw(), and associated typedef
55 // - added more values to the BelaHw enum
56 // - added codecMode to BelaInitSettings
57 // 1.9.0
58 // - added Bela_HwConfig_{new,delete}
59 // 1.8.0
60 // - added callback for when the audio thread is done: settings->audioThreadDone
61 // 1.7.0
62 // - Bela_getopt_long takes a char* const []
63 // - added the functions and definitions from Utilities.h
64 // - INPUT and OUTPUT are now an enum
65 // 1.6.0
66 // - added Bela_setUserData(), Bela_requestStop(), Bela_stopRequested()
67 // 1.5.1
68 // - in BelaInitSettings, renamed unused members, preserving binary compatibility
69 // 1.5.0
70 // - in BelaInitSettings, board becomes BelaHw
71 // - added to BelaInitSettings char* projectName
72 // - added to BelaContext char* projectName
73 // 1.4.0
74 // - added allocator/de-allocator for BelaInitSettings
75 // - added char board field to BelaInitSettings
76 // 1.3.0
77 // - removed define for I2C codec address
78 // - removed user option in settings for I2C address
79 // 1.2.0
80 // - renames and re-ordered BelaHw enum
81 // 1.1.0
82 // - adds BelaHw, Bela_detectHw()
83 // - removes digital_gpio_mapping.h
84 
85 #ifdef __cplusplus
86 extern "C"
87 {
88 #endif
89 
90 #include <stdint.h>
91 #include <unistd.h>
92 #include <stdbool.h>
93 #include <stdio.h>
94 // these functions are currently provided by xenomai.
95 // We put these declarations here so we do not have to include
96 // Xenomai specific files
97 int rt_printf(const char *format, ...);
98 int rt_fprintf(FILE *stream, const char *format, ...);
99 int rt_vprintf(const char *format, va_list ap);
100 int rt_vfprintf(FILE *stream, const char *format, va_list ap);
101 
105 typedef enum
106 {
107  BelaHw_NoHw = -1,
122 } BelaHw;
123 
124 typedef struct _BelaHwConfig
125 {
126  float audioSampleRate;
127  unsigned int audioInChannels;
128  unsigned int audioOutChannels;
129  unsigned int analogInChannels;
130  unsigned int analogOutChannels;
131  unsigned int digitalChannels;
132 } BelaHwConfig;
133 
141 
146 
150 typedef enum
151 {
158 
159 #include <GPIOcontrol.h>
160 
161 // Useful constants
162 
164 #define MAX_PRU_FILENAME_LENGTH 256
165 #define MAX_UNUSED_LENGTH 224
166 #define MAX_PROJECTNAME_LENGTH 256
167 
176 #define BELA_AUDIO_PRIORITY 95
177 
178 // Default volume levels
179 
189 #define DEFAULT_LINE_OUT_LEVEL 0.0
190 
194 #define DEFAULT_PGA_GAIN 16
195 
199 #define DEFAULT_HP_LEVEL -6.0
200 
205 #define BELA_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved
206 
209 #define BELA_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers
210 
213 #define BELA_FLAG_DETECT_UNDERRUNS (1 << 2) // Set if the user will be displayed a message when an underrun occurs
214 
217 #define BELA_FLAG_OFFLINE (1 << 3)
218 
219 struct option;
220 
229 typedef struct {
247  const float * const audioIn;
248 
262  float * const audioOut;
263 
281  const float * const analogIn;
282 
296  float * const analogOut;
297 
306  uint32_t * const digital;
307 
320  const uint32_t audioFrames;
322  const uint32_t audioInChannels;
324  const uint32_t audioOutChannels;
326  const float audioSampleRate;
327 
339  const uint32_t analogFrames;
340 
344  const uint32_t analogInChannels;
345 
349  const uint32_t analogOutChannels;
350 
360  const float analogSampleRate;
361 
363  const uint32_t digitalFrames;
367  const uint32_t digitalChannels;
369  const float digitalSampleRate;
370 
377  const uint64_t audioFramesElapsed;
378 
383  const uint32_t multiplexerChannels;
384 
390 
396  const float * const multiplexerAnalogIn;
397 
402  const uint32_t audioExpanderEnabled;
403 
412  const uint32_t flags;
413 
415  char projectName[MAX_PROJECTNAME_LENGTH];
416 
418  const unsigned int underrunCount;
419 } BelaContext;
420 
422  int channel;
423  float gain;
424 };
425 
427  unsigned int length;
428  struct BelaChannelGain* data;
429 };
439 typedef struct {
440  // These items might be adjusted by the user:
441 
462 
466  float dacLevel;
468  float adcLevel;
470  float pgaGain[2];
476  unsigned int audioExpanderInputs;
478  unsigned int audioExpanderOutputs;
479 
483  char pruFilename[MAX_PRU_FILENAME_LENGTH];
487  int verbose;
498 
499  // These items are application-dependent but should probably be
500  // determined by the programmer rather than the user
501 
512  // to 128KiB
513  unsigned int audioThreadStackSize;
515  // to 128KiB
516  unsigned int auxiliaryTaskStackSize;
517 
518  // Pointers to the user-defined functions
519  bool (*setup)(BelaContext*, void*);
520  void (*render)(BelaContext*, void*);
521  void (*cleanup)(BelaContext*, void*);
522  // These items are hardware-dependent and should only be changed
523  // to run on different hardware
524 
527 
530  void (*audioThreadDone)(BelaContext*, void*);
532  char* codecMode;
534  struct BelaChannelGainArray audioInputGains;
536  struct BelaChannelGainArray headphoneGains;
538  struct BelaChannelGainArray adcGains;
540  struct BelaChannelGainArray lineOutGains;
541 
542  char unused[MAX_UNUSED_LENGTH];
543 
546 
548  char* projectName;
549 
551 
557 typedef void* AuxiliaryTask; // Opaque data type to keep track of aux tasks
558 
575 extern int volatile gShouldStop;
576 
577 // *** User-defined render functions ***
578 
605 bool setup(BelaContext *context, void *userData);
606 
621 void render(BelaContext *context, void *userData);
622 
638 void cleanup(BelaContext *context, void *userData);
639 
651 // *** Command-line settings ***
652 
653 
662 
672 
682 void Bela_defaultSettings(BelaInitSettings *settings);
683 
684 #pragma weak Bela_userSettings
685 
696 void Bela_userSettings(BelaInitSettings *settings);
697 
719 int Bela_getopt_long(int argc, char * const argv[], const char *customShortOptions,
720  const struct option *customLongOptions, BelaInitSettings *settings);
721 
729 void Bela_usage();
730 
734 void Bela_getVersion(int* major, int* minor, int* bugfix);
735 
742 void Bela_setVerboseLevel(int level);
743 
744 
752 
753 // *** Audio control functions ***
754 
770 int Bela_initAudio(BelaInitSettings *settings, void *userData);
771 
780 int Bela_startAudio();
781 
791 
798 void Bela_stopAudio();
799 
807 void Bela_cleanupAudio();
808 
816 void Bela_setUserData(void* newUserData);
817 
830 void Bela_requestStop();
831 
841 int Bela_stopRequested();
842 
844 #ifndef BELA_DISABLE_CPU_TIME
845 
867 #include <time.h>
868 typedef struct {
869  int count;
870  unsigned int currentCount;
871  long long unsigned int busy;
872  long long unsigned int total;
873  struct timespec tic;
874  struct timespec toc;
875  float percentage;
876 } BelaCpuData;
882 int Bela_cpuMonitoringInit(int count);
897 void Bela_cpuTic(BelaCpuData* data);
903 void Bela_cpuToc(BelaCpuData* data);
904 
906 #endif // BELA_DISABLE_CPU_TIME
907 
917 // *** Volume and level controls ***
918 
930 int Bela_setLineOutLevel(int channel, float decibel);
931 
939 int Bela_setDacLevel(int channel, float decibels);
940 
946 int Bela_setDACLevel(float decibels);
947 
963 int Bela_setAdcLevel(int channel, float decibels);
964 
970 int Bela_setADCLevel(float decibels);
971 
972 
989 int Bela_setAudioInputGain(int channel, float decibels);
990 
996 int Bela_setPgaGain(float decibels, int channel);
997 
1014 int Bela_setHpLevel(int channel, float decibels);
1019 int Bela_setHeadphoneLevel(float decibels);
1020 
1034 int Bela_muteSpeakers(int mute);
1035 
1052 // *** Functions for creating auxiliary tasks ***
1053 
1070 AuxiliaryTask Bela_createAuxiliaryTask(void (*callback)(void*), int priority, const char *name, void* arg
1071 #ifdef __cplusplus
1072 = NULL
1073 #endif /* __cplusplus */
1074 );
1075 
1091 int Bela_scheduleAuxiliaryTask(AuxiliaryTask task);
1092 
1105 #ifdef __cplusplus
1106 AuxiliaryTask Bela_runAuxiliaryTask(void (*callback)(void*), int priority = 0, void* arg = nullptr);
1107 #endif // __cplusplus
1108 
1126 int Bela_startAuxiliaryTask(AuxiliaryTask task);
1127 int Bela_startAllAuxiliaryTasks();
1128 void Bela_stopAllAuxiliaryTasks();
1129 void Bela_deleteAllAuxiliaryTasks();
1130 
1133 // You may want to define the macro below in case `Utilities.h` causes namespace conflicts
1134 #ifndef BELA_DONT_INCLUDE_UTILITIES
1135 #include <Utilities.h>
1136 #endif // BELA_DONT_INCLUDE_UTILITIES
1137 
1154 enum {
1155  INPUT = 0,
1156  OUTPUT = 1,
1157 };
1166 #define Bela_setBit(word,bit) ((word) | (1 << (bit)))
1168 
1170 #define Bela_clearBit(word,bit) ((word) &~ (1 << (bit)))
1171 
1173 #define Bela_getBit(word,bit) (((word) >> (bit)) & 1)
1174 
1176 #define Bela_changeBit(word,bit,value) ((Bela_clearBit((word),(bit))) | ((value) << (bit)))
1177 
1188 // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup()
1189 // Likewise, thread launch should be able to be called from setup()
1190 // Also, make volume change functions callable from render() thread -- as an aux task?
1191 
1205 static inline float audioRead(BelaContext *context, int frame, int channel);
1206 
1212 static inline float audioReadNI(BelaContext *context, int frame, int channel);
1213 
1227 static inline void audioWrite(BelaContext *context, int frame, int channel, float value);
1228 
1234 static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value);
1235 
1249 static inline float analogRead(BelaContext *context, int frame, int channel);
1250 
1256 static inline float analogReadNI(BelaContext *context, int frame, int channel);
1257 
1274 static inline void analogWrite(BelaContext *context, int frame, int channel, float value);
1275 
1281 static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value);
1282 
1302 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value);
1303 
1309 static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value);
1310 
1325 static inline int digitalRead(BelaContext *context, int frame, int channel);
1326 
1343 static inline void digitalWrite(BelaContext *context, int frame, int channel, int value);
1344 
1363 static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value);
1364 
1381 static inline void pinMode(BelaContext *context, int frame, int channel, int mode);
1382 
1399 static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode);
1400 
1401 /*
1402  * \brief Returns the value of the given multiplexer channel for the given analog input.
1403  *
1404  * This function reads an input from the Multiplexer Capelet hardware, which needs to be
1405  * attached and enabled by selecting 16, 32 or 64 analog input channels in the command line
1406  * arguments. With the Multiplexer Capelet, each analog input can be connected to one of 8
1407  * multiplexer channels. This function will return a particular multiplexer channel for a
1408  * particular input, with the returned valued being the most recent sample taken from that pin.
1409  *
1410  * Depending on the block size, it may take longer than a single block to scan all multiplexer
1411  * channels. For this reason, successive calls to multiplexerAnalogRead() may return the same
1412  * sample. If you want precise timing control on when a multiplexer input was sampled, use
1413  * multiplexerChannelForFrame() instead to determine which multiplexer channels were sampled
1414  * in a particular block.
1415  *
1416  * \param context The I/O data structure which is passed by Bela to render().
1417  * \param input The analog input to read, i.e. what would be passed as \c channel to analogRead().
1418  * Valid values are 0 to (context->analogInChannels - 1).
1419  * \param muxChannel Which multiplexer channel to read. Valid values are 0 to
1420  * (context->multiplexerChannels - 1).
1421  * \return Value of the analog input from the Multiplexer Capelet.
1422  */
1423 
1424 static inline float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel);
1425 
1426 /*
1427  * \brief Returns which multiplexer channel the given analog frame was taken from.
1428  *
1429  * This function indicates what the multiplexer setting was for a given analog input frame.
1430  * This can be used to work out which pin on the Multiplexer Capelet a given analog input sample
1431  * was taken from. For this function to have any meaning, the Multiplexer Capelet hardware must
1432  * be attached and it should be enabled by selecting 16, 32 or 64 analog input channels in the
1433  * command line arguments.
1434  *
1435  * Depending on the block size, it may take longer than a single block to scan all multiplexer
1436  * channels. For this reason, each call to render() may contain only a subset of the available
1437  * multiplexer channels. This function allows you timing precision by knowing at what frame each
1438  * multiplexer reading was taken, but it does not guarantee that all channels can be read in
1439  * any given callback. If you need access to all the multiplexer inputs in every call to render(),
1440  * use multiplexerAnalogRead() instead.
1441  *
1442  * \param context The I/O data structure which is passed by Bela to render().
1443  * \param frame The analog frame (i.e. the time) whose multiplexer setting should be queried.
1444  * \return Multiplexer channel setting at the given frame.
1445  */
1446 
1447 static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame);
1448 
1451 // audioRead()
1452 //
1453 // Returns the value of the given audio input at the given frame number.
1454 static inline float audioRead(BelaContext *context, int frame, int channel) {
1455  return context->audioIn[frame * context->audioInChannels + channel];
1456 }
1457 
1458 static inline float audioReadNI(BelaContext *context, int frame, int channel) {
1459  return context->audioIn[channel * context->audioFrames + frame];
1460 }
1461 
1462 // audioWrite()
1463 //
1464 // Sets a given audio output channel to a value for the current frame
1465 static inline void audioWrite(BelaContext *context, int frame, int channel, float value) {
1466  context->audioOut[frame * context->audioOutChannels + channel] = value;
1467 }
1468 
1469 static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value) {
1470  context->audioOut[channel * context->audioFrames + frame] = value;
1471 }
1472 
1473 // analogRead()
1474 //
1475 // Returns the value of the given analog input at the given frame number.
1476 static inline float analogRead(BelaContext *context, int frame, int channel) {
1477  return context->analogIn[frame * context->analogInChannels + channel];
1478 }
1479 
1480 static inline float analogReadNI(BelaContext *context, int frame, int channel) {
1481  return context->analogIn[channel * context->analogFrames + frame];
1482 }
1483 
1484 // analogWriteOnce()
1485 //
1486 // Sets a given channel to a value for only the current frame
1487 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) {
1488  context->analogOut[frame * context->analogOutChannels + channel] = value;
1489 }
1490 
1491 static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value) {
1492  context->analogOut[channel * context->analogFrames + frame] = value;
1493 }
1494 
1495 // analogWrite()
1496 //
1497 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are
1498 // enabled, for all subsequent frames
1499 static inline void analogWrite(BelaContext *context, int frame, int channel, float value) {
1500  unsigned int f;
1501  for(f = frame; f < context->analogFrames; f++)
1502  analogWriteOnce(context, f, channel, value);
1503 }
1504 
1505 static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value) {
1506  unsigned int f;
1507  for(f = frame; f < context->analogFrames; f++)
1508  analogWriteOnceNI(context, f, channel, value);
1509 }
1510 
1511 // digitalRead()
1512 //
1513 // Returns the value of a given digital input at the given frame number
1514 static inline int digitalRead(BelaContext *context, int frame, int channel) {
1515  return Bela_getBit(context->digital[frame], channel + 16);
1516 }
1517 
1518 // digitalWrite()
1519 //
1520 // Sets a given digital output channel to a value for the current frame and all subsequent frames
1521 static inline void digitalWrite(BelaContext *context, int frame, int channel, int value) {
1522  unsigned int f;
1523  for(f = frame; f < context->digitalFrames; f++) {
1524  if(value)
1525  context->digital[f] |= 1 << (channel + 16);
1526  else
1527  context->digital[f] &= ~(1 << (channel + 16));
1528  }
1529 }
1530 
1531 // digitalWriteOnce()
1532 //
1533 // Sets a given digital output channel to a value for the current frame only
1534 static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value) {
1535  if(value)
1536  context->digital[frame] |= 1 << (channel + 16);
1537  else
1538  context->digital[frame] &= ~(1 << (channel + 16));
1539 }
1540 
1541 // pinMode()
1542 //
1543 // Sets the direction of a digital pin for the current frame and all subsequent frames
1544 static inline void pinMode(BelaContext *context, int frame, int channel, int mode) {
1545  unsigned int f;
1546  for(f = frame; f < context->digitalFrames; f++) {
1547  if(mode == INPUT)
1548  context->digital[f] |= (1 << channel);
1549  else
1550  context->digital[f] &= ~(1 << channel);
1551  }
1552 }
1553 
1554 // pinModeOnce()
1555 //
1556 // Sets the direction of a digital pin for the current frame only
1557 static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode) {
1558  if(mode == INPUT)
1559  context->digital[frame] |= (1 << channel);
1560  else
1561  context->digital[frame] &= ~(1 << channel);
1562 }
1563 
1564 // multiplexerAnalogRead()
1565 //
1566 // Returns the value of the given multiplexer channel for the given analog input.
1567 static inline float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel) {
1568  return context->multiplexerAnalogIn[muxChannel * context->analogInChannels + input];
1569 }
1570 
1571 // multiplexerChannelForFrame()
1572 //
1573 // Returns which multiplexer channel the given analog frame was taken from.
1574 static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame) {
1575  if(context->multiplexerChannels <= 1)
1576  return 1;
1577  return (context->multiplexerStartingChannel + frame) % context->multiplexerChannels;
1578 }
1579 
1580 #ifdef __cplusplus
1581 }
1582 #endif
1583 
1584 #endif /* BELA_H_ */
float percentage
Average CPU usage during previous acquisition cycle.
Definition: Bela.h:875
char * codecMode
A codec-specific intialisation parameter.
Definition: Bela.h:532
int detectUnderruns
Whether to detect and log underruns.
Definition: Bela.h:485
Dummy offline.
Definition: Bela.h:121
read user-specified value from ~/.bela/belaconfig. If it does not exist, fall back to BelaHwDetectMod...
Definition: Bela.h:155
Bela Mini with extra codecs and/or tdm devices.
Definition: Bela.h:116
const uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition: Bela.h:383
Ctag Beast and Bela cape.
Definition: Bela.h:114
const float *const analogIn
Buffer holding analog input samples.
Definition: Bela.h:281
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:1469
Bela with extra codecs and/or tdm devices.
Definition: Bela.h:117
long long unsigned int total
Total CPU time (between tic and previous tic) during the current acquisition cycle.
Definition: Bela.h:872
float adcLevel
Level for the audio ADC input. DEPRECATED: use audioInputGains.
Definition: Bela.h:468
int ampMutePin
Pin where amplifier mute can be found.
Definition: Bela.h:526
const uint32_t audioInChannels
The number of audio input channels.
Definition: Bela.h:322
const float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0)
Definition: Bela.h:369
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:344
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:1476
static float audioReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of audioRead()
Definition: Bela.h:1458
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:1465
void Bela_cpuTic(BelaCpuData *data)
float headphoneLevel
Level for the headphone output. DEPRECATED: use headphoneGains.
Definition: Bela.h:472
const uint32_t analogOutChannels
The number of analog output channels.
Definition: Bela.h:349
float gain
Gain in dB.
Definition: Bela.h:423
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:389
static void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWriteNI()
Definition: Bela.h:1491
BelaHwConfig * Bela_HwConfig_new(BelaHw hw)
const uint32_t flags
Other audio/sensor settings.
Definition: Bela.h:412
int Bela_setDACLevel(float decibels)
int verbose
Whether to use verbose logging.
Definition: Bela.h:487
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:367
perform an automatic detection by scanning the peripherals and busses available, and cache value in /...
Definition: Bela.h:152
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:363
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:115
int numAudioInChannels
How many audio input channels [ignored].
Definition: Bela.h:453
BelaHw
Definition: Bela.h:105
unsigned int audioExpanderOutputs
Which audio expander settings to use on the input.
Definition: Bela.h:478
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:481
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:153
void Bela_requestStop()
Tell the Bela program to stop.
Bela Mini with extra rx and tx I2S data lines.
Definition: Bela.h:118
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:1505
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:1514
Definition: Bela.h:421
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:1574
Structure containing initialisation parameters for the real-time audio control system.
Definition: Bela.h:439
float *const audioOut
Buffer holding audio output samples.
Definition: Bela.h:262
int numAudioOutChannels
How many audio out channels [ignored].
Definition: Bela.h:455
char * projectName
Name of running project.
Definition: Bela.h:548
int interleave
Whether audio/analog data should be interleaved.
Definition: Bela.h:503
const uint32_t audioFrames
The number of audio frames per block.
Definition: Bela.h:320
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:1534
No hardware.
Definition: Bela.h:107
Definition: Bela.h:868
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:545
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:360
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition: Bela.h:229
const uint32_t audioExpanderEnabled
Flags for whether audio expander is enabled on given analog channels.
Definition: Bela.h:402
A Bela cape rev C: Es9080 is used for analog outs.
Definition: Bela.h:120
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:510
Ctag Face.
Definition: Bela.h:111
int count
Number of samples (tic/toc pairs) in a acquisition cycle. Use 0 to disable.
Definition: Bela.h:869
int numMuxChannels
How many channels to use on the multiplexer capelet, if enabled.
Definition: Bela.h:474
int Bela_initAudio(BelaInitSettings *settings, void *userData)
Initialise audio and sensor rendering environment.
Salt.
Definition: Bela.h:110
int numAnalogOutChannels
How many analog output channels.
Definition: Bela.h:459
int Bela_setLineOutLevel(int channel, float decibel)
Set the level of the audio line out.
Ctag Face and Bela cape.
Definition: Bela.h:113
Bela.
Definition: Bela.h:108
float *const analogOut
Buffer holding analog output samples.
Definition: Bela.h:296
const uint32_t audioOutChannels
The number of audio output channels.
Definition: Bela.h:324
int Bela_setPgaGain(float decibels, int channel)
int Bela_cpuMonitoringInit(int count)
int beginMuted
Whether to begin with the speakers muted.
Definition: Bela.h:464
int numAnalogInChannels
How many analog input channels.
Definition: Bela.h:457
Definition: Bela.h:426
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:1487
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition: render.cpp:68
BelaHwDetectMode
Definition: Bela.h:150
read cached value from /run/bela/belaconfig. If it does not exist, return BelaHw_NoHw ...
Definition: Bela.h:154
read user-specified value from ~/.bela/belaconfig. If it does not exist, return BelaHw_NoHw ...
Definition: Bela.h:156
uint32_t *const digital
Buffer holding digital input/output samples.
Definition: Bela.h:306
const unsigned int underrunCount
Number of detected underruns.
Definition: Bela.h:418
const uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition: Bela.h:377
unsigned int audioExpanderInputs
Which audio expander settings to use on the input.
Definition: Bela.h:476
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:1499
float dacLevel
Level for the audio DAC output. DEPRECATED: ues lineOutGains.
Definition: Bela.h:466
Bela Mini.
Definition: Bela.h:109
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:1454
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:339
int highPerformanceMode
Definition: Bela.h:497
int numDigitalChannels
How many channels for the GPIOs.
Definition: Bela.h:461
int stopButtonPin
Definition: Bela.h:492
void * AuxiliaryTask
Definition: Bela.h:557
static float analogReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of analogRead()
Definition: Bela.h:1480
const float *const multiplexerAnalogIn
Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.
Definition: Bela.h:396
Definition: Bela.h:124
int Bela_setDacLevel(int channel, float decibels)
Set the level of the audio DAC.
Ctag Beast.
Definition: Bela.h:112
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:422
int enableLED
Whether to use the blinking LED to indicate Bela is running.
Definition: Bela.h:489
long long unsigned int busy
Total CPU time spent being busy (between tic and toc) during the current acquisition cycle...
Definition: Bela.h:871
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:1544
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:449
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:1557
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0)
Definition: Bela.h:326
int Bela_startAudio()
Begin processing audio and sensor data.
int periodSize
Number of audio frames per period ("blocksize").
Definition: Bela.h:447
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:1521
int analogOutputsPersist
Whether analog outputs should persist to future frames.
Definition: Bela.h:507
const float *const audioIn
Buffer holding audio input samples.
Definition: Bela.h:247
int useDigital
Whether to use the 16 programmable GPIOs.
Definition: Bela.h:451
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:1567
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:870
A Bela cape with Es9080 EVB on top, all as audio.
Definition: Bela.h:119
void Bela_cleanupAudio()
Clean up resources from audio and sensor processing.