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 9
31 #define BELA_BUGFIX_VERSION 0
32 
33 // Version history / changelog:
34 // 1.9.0
35 // - added Bela_HwConfig_{new,delete}
36 // 1.8.0
37 // - added callback for when the audio thread is done: settings->audioThreadDone
38 // 1.7.0
39 // - Bela_getopt_long takes a char* const []
40 // - added the functions and definitions from Utilities.h
41 // - INPUT and OUTPUT are now an enum
42 // 1.6.0
43 // - added Bela_setUserData(), Bela_requestStop(), Bela_stopRequested()
44 // 1.5.0
45 // - in BelaInitSettings, renamed unused members, preserving binary compatibility
46 // 1.5.0
47 // - in BelaInitSettings, board becomes BelaHw
48 // - added to BelaInitSettings char* projectName
49 // - added to BelaContext char* projectName
50 // 1.4.0
51 // - added allocator/de-allocator for BelaInitSettings
52 // - added char board field to BelaInitSettings
53 // 1.3.0
54 // - removed define for I2C codec address
55 // - removed user option in settings for I2C address
56 // 1.2.0
57 // - renames and re-ordered BelaHw enum
58 // 1.1.0
59 // - adds BelaHw, Bela_detectHw()
60 // - removes digital_gpio_mapping.h
61 
62 #ifdef __cplusplus
63 extern "C"
64 {
65 #endif
66 
67 #include <stdint.h>
68 #include <unistd.h>
69 #include <stdbool.h>
70 #include <stdio.h>
71 // these functions are currently provided by xenomai.
72 // We put these declarations here so we do not have to include
73 // Xenomai specific files
74 int rt_printf(const char *format, ...);
75 int rt_fprintf(FILE *stream, const char *format, ...);
76 int rt_vprintf(const char *format, va_list ap);
77 int rt_vfprintf(FILE *stream, const char *format, va_list ap);
78 
79 typedef enum
80 {
81  BelaHw_NoHw = -1,
82  BelaHw_Bela,
83  BelaHw_BelaMini,
84  BelaHw_Salt,
85  BelaHw_CtagFace,
86  BelaHw_CtagBeast,
87  BelaHw_CtagFaceBela,
88  BelaHw_CtagBeastBela,
89 } BelaHw;
90 
91 typedef struct _BelaHwConfig
92 {
93  float audioSampleRate;
94  unsigned int audioInChannels;
95  unsigned int audioOutChannels;
96  unsigned int analogInChannels;
97  unsigned int analogOutChannels;
98  unsigned int digitalChannels;
99 } BelaHwConfig;
100 
107 BelaHwConfig* Bela_HwConfig_new(BelaHw hw);
108 
113 
114 #include <GPIOcontrol.h>
115 
116 // Useful constants
117 
119 #define MAX_PRU_FILENAME_LENGTH 256
120 #define MAX_UNUSED2_LENGTH 256
121 #define MAX_PROJECTNAME_LENGTH 256
122 
131 #define BELA_AUDIO_PRIORITY 95
132 
133 // Default volume levels
134 
144 #define DEFAULT_DAC_LEVEL 0.0
145 
149 #define DEFAULT_ADC_LEVEL 0.0
150 
151 
155 #define DEFAULT_PGA_GAIN 16
156 
160 #define DEFAULT_HP_LEVEL -6.0
161 
166 #define BELA_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved
167 
170 #define BELA_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers
171 
174 #define BELA_FLAG_DETECT_UNDERRUNS (1 << 2) // Set if the user will be displayed a message when an underrun occurs
175 
176 struct option;
177 
186 typedef struct {
204  const float * const audioIn;
205 
219  float * const audioOut;
220 
238  const float * const analogIn;
239 
253  float * const analogOut;
254 
263  uint32_t * const digital;
264 
277  const uint32_t audioFrames;
279  const uint32_t audioInChannels;
281  const uint32_t audioOutChannels;
283  const float audioSampleRate;
284 
296  const uint32_t analogFrames;
297 
301  const uint32_t analogInChannels;
302 
306  const uint32_t analogOutChannels;
307 
317  const float analogSampleRate;
318 
320  const uint32_t digitalFrames;
324  const uint32_t digitalChannels;
326  const float digitalSampleRate;
327 
334  const uint64_t audioFramesElapsed;
335 
340  const uint32_t multiplexerChannels;
341 
347 
353  const float * const multiplexerAnalogIn;
354 
359  const uint32_t audioExpanderEnabled;
360 
369  const uint32_t flags;
370 
372  char projectName[MAX_PROJECTNAME_LENGTH];
373 
374 } BelaContext;
375 
385 typedef struct {
386  // These items might be adjusted by the user:
387 
407 
411  float dacLevel;
413  float adcLevel;
415  float pgaGain[2];
421  unsigned int audioExpanderInputs;
423  unsigned int audioExpanderOutputs;
424 
428  char pruFilename[MAX_PRU_FILENAME_LENGTH];
432  int verbose;
443 
444  // These items are application-dependent but should probably be
445  // determined by the programmer rather than the user
446 
457  // to 128KiB
458  unsigned int audioThreadStackSize;
460  // to 128KiB
461  unsigned int auxiliaryTaskStackSize;
462 
463  // Pointers to the user-defined functions
464  bool (*setup)(BelaContext*, void*);
465  void (*render)(BelaContext*, void*);
466  void (*cleanup)(BelaContext*, void*);
467  // These items are hardware-dependent and should only be changed
468  // to run on different hardware
469 
472 
475  void (*audioThreadDone)(BelaContext*, void*);
476  int unused1;
477  char unused2[MAX_UNUSED2_LENGTH];
478 
480  BelaHw board;
481 
483  char* projectName;
484 
486 
492 typedef void* AuxiliaryTask; // Opaque data type to keep track of aux tasks
493 
510 extern int volatile gShouldStop;
511 
512 // *** User-defined render functions ***
513 
540 bool setup(BelaContext *context, void *userData);
541 
556 void render(BelaContext *context, void *userData);
557 
573 void cleanup(BelaContext *context, void *userData);
574 
586 // *** Command-line settings ***
587 
588 
597 
607 
617 void Bela_defaultSettings(BelaInitSettings *settings);
618 
619 #pragma weak Bela_userSettings
620 
631 void Bela_userSettings(BelaInitSettings *settings);
632 
654 int Bela_getopt_long(int argc, char * const argv[], const char *customShortOptions,
655  const struct option *customLongOptions, BelaInitSettings *settings);
656 
664 void Bela_usage();
665 
669 void Bela_getVersion(int* major, int* minor, int* bugfix);
670 
677 void Bela_setVerboseLevel(int level);
678 
679 
683 BelaHw Bela_detectHw(void);
684 
685 // *** Audio control functions ***
686 
702 int Bela_initAudio(BelaInitSettings *settings, void *userData);
703 
712 int Bela_startAudio();
713 
723 
730 void Bela_stopAudio();
731 
739 void Bela_cleanupAudio();
740 
748 void Bela_setUserData(void* newUserData);
749 
762 void Bela_requestStop();
763 
773 int Bela_stopRequested();
774 
786 // *** Volume and level controls ***
787 
802 int Bela_setDACLevel(float decibels);
803 
818 int Bela_setADCLevel(float decibels);
819 
820 
837 int Bela_setPgaGain(float decibels, int channel);
838 
854 int Bela_setHeadphoneLevel(float decibels);
855 
869 int Bela_muteSpeakers(int mute);
870 
887 // *** Functions for creating auxiliary tasks ***
888 
905 AuxiliaryTask Bela_createAuxiliaryTask(void (*callback)(void*), int priority, const char *name, void* arg
906 #ifdef __cplusplus
907 = NULL
908 #endif /* __cplusplus */
909 );
910 
926 int Bela_scheduleAuxiliaryTask(AuxiliaryTask task);
927 
940 #ifdef __cplusplus
941 AuxiliaryTask Bela_runAuxiliaryTask(void (*callback)(void*), int priority = 0, void* arg = nullptr);
942 #endif // __cplusplus
943 
961 int Bela_startAuxiliaryTask(AuxiliaryTask task);
962 int Bela_startAllAuxiliaryTasks();
963 void Bela_stopAllAuxiliaryTasks();
964 void Bela_deleteAllAuxiliaryTasks();
965 
968 // You may want to define the macro below in case `Utilities.h` causes namespace conflicts
969 #ifndef BELA_DONT_INCLUDE_UTILITIES
970 #include <Utilities.h>
971 #endif // BELA_DONT_INCLUDE_UTILITIES
972 
989 enum {
990  INPUT = 0,
991  OUTPUT = 1,
992 };
1001 #define Bela_setBit(word,bit) ((word) | (1 << (bit)))
1003 
1005 #define Bela_clearBit(word,bit) ((word) &~ (1 << (bit)))
1006 
1008 #define Bela_getBit(word,bit) (((word) >> (bit)) & 1)
1009 
1011 #define Bela_changeBit(word,bit,value) ((Bela_clearBit((word),(bit))) | ((value) << (bit)))
1012 
1023 // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup()
1024 // Likewise, thread launch should be able to be called from setup()
1025 // Also, make volume change functions callable from render() thread -- as an aux task?
1026 
1040 static inline float audioRead(BelaContext *context, int frame, int channel);
1041 
1047 static inline float audioReadNI(BelaContext *context, int frame, int channel);
1048 
1062 static inline void audioWrite(BelaContext *context, int frame, int channel, float value);
1063 
1069 static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value);
1070 
1084 static inline float analogRead(BelaContext *context, int frame, int channel);
1085 
1091 static inline float analogReadNI(BelaContext *context, int frame, int channel);
1092 
1109 static inline void analogWrite(BelaContext *context, int frame, int channel, float value);
1110 
1116 static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value);
1117 
1137 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value);
1138 
1144 static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value);
1145 
1160 static inline int digitalRead(BelaContext *context, int frame, int channel);
1161 
1178 static inline void digitalWrite(BelaContext *context, int frame, int channel, int value);
1179 
1198 static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value);
1199 
1216 static inline void pinMode(BelaContext *context, int frame, int channel, int mode);
1217 
1234 static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode);
1235 
1236 /*
1237  * \brief Returns the value of the given multiplexer channel for the given analog input.
1238  *
1239  * This function reads an input from the Multiplexer Capelet hardware, which needs to be
1240  * attached and enabled by selecting 16, 32 or 64 analog input channels in the command line
1241  * arguments. With the Multiplexer Capelet, each analog input can be connected to one of 8
1242  * multiplexer channels. This function will return a particular multiplexer channel for a
1243  * particular input, with the returned valued being the most recent sample taken from that pin.
1244  *
1245  * Depending on the block size, it may take longer than a single block to scan all multiplexer
1246  * channels. For this reason, successive calls to multiplexerAnalogRead() may return the same
1247  * sample. If you want precise timing control on when a multiplexer input was sampled, use
1248  * multiplexerChannelForFrame() instead to determine which multiplexer channels were sampled
1249  * in a particular block.
1250  *
1251  * \param context The I/O data structure which is passed by Bela to render().
1252  * \param input The analog input to read, i.e. what would be passed as \c channel to analogRead().
1253  * Valid values are 0 to (context->analogInChannels - 1).
1254  * \param muxChannel Which multiplexer channel to read. Valid values are 0 to
1255  * (context->multiplexerChannels - 1).
1256  * \return Value of the analog input from the Multiplexer Capelet.
1257  */
1258 
1259 static inline float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel);
1260 
1261 /*
1262  * \brief Returns which multiplexer channel the given analog frame was taken from.
1263  *
1264  * This function indicates what the multiplexer setting was for a given analog input frame.
1265  * This can be used to work out which pin on the Multiplexer Capelet a given analog input sample
1266  * was taken from. For this function to have any meaning, the Multiplexer Capelet hardware must
1267  * be attached and it should be enabled by selecting 16, 32 or 64 analog input channels in the
1268  * command line arguments.
1269  *
1270  * Depending on the block size, it may take longer than a single block to scan all multiplexer
1271  * channels. For this reason, each call to render() may contain only a subset of the available
1272  * multiplexer channels. This function allows you timing precision by knowing at what frame each
1273  * multiplexer reading was taken, but it does not guarantee that all channels can be read in
1274  * any given callback. If you need access to all the multiplexer inputs in every call to render(),
1275  * use multiplexerAnalogRead() instead.
1276  *
1277  * \param context The I/O data structure which is passed by Bela to render().
1278  * \param frame The analog frame (i.e. the time) whose multiplexer setting should be queried.
1279  * \return Multiplexer channel setting at the given frame.
1280  */
1281 
1282 static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame);
1283 
1286 // audioRead()
1287 //
1288 // Returns the value of the given audio input at the given frame number.
1289 static inline float audioRead(BelaContext *context, int frame, int channel) {
1290  return context->audioIn[frame * context->audioInChannels + channel];
1291 }
1292 
1293 static inline float audioReadNI(BelaContext *context, int frame, int channel) {
1294  return context->audioIn[channel * context->audioFrames + frame];
1295 }
1296 
1297 // audioWrite()
1298 //
1299 // Sets a given audio output channel to a value for the current frame
1300 static inline void audioWrite(BelaContext *context, int frame, int channel, float value) {
1301  context->audioOut[frame * context->audioOutChannels + channel] = value;
1302 }
1303 
1304 static inline void audioWriteNI(BelaContext *context, int frame, int channel, float value) {
1305  context->audioOut[channel * context->audioFrames + frame] = value;
1306 }
1307 
1308 // analogRead()
1309 //
1310 // Returns the value of the given analog input at the given frame number.
1311 static inline float analogRead(BelaContext *context, int frame, int channel) {
1312  return context->analogIn[frame * context->analogInChannels + channel];
1313 }
1314 
1315 static inline float analogReadNI(BelaContext *context, int frame, int channel) {
1316  return context->analogIn[channel * context->analogFrames + frame];
1317 }
1318 
1319 // analogWriteOnce()
1320 //
1321 // Sets a given channel to a value for only the current frame
1322 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) {
1323  context->analogOut[frame * context->analogOutChannels + channel] = value;
1324 }
1325 
1326 static inline void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value) {
1327  context->analogOut[channel * context->analogFrames + frame] = value;
1328 }
1329 
1330 // analogWrite()
1331 //
1332 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are
1333 // enabled, for all subsequent frames
1334 static inline void analogWrite(BelaContext *context, int frame, int channel, float value) {
1335  unsigned int f;
1336  for(f = frame; f < context->analogFrames; f++)
1337  analogWriteOnce(context, f, channel, value);
1338 }
1339 
1340 static inline void analogWriteNI(BelaContext *context, int frame, int channel, float value) {
1341  unsigned int f;
1342  for(f = frame; f < context->analogFrames; f++)
1343  analogWriteOnceNI(context, f, channel, value);
1344 }
1345 
1346 // digitalRead()
1347 //
1348 // Returns the value of a given digital input at the given frame number
1349 static inline int digitalRead(BelaContext *context, int frame, int channel) {
1350  return Bela_getBit(context->digital[frame], channel + 16);
1351 }
1352 
1353 // digitalWrite()
1354 //
1355 // Sets a given digital output channel to a value for the current frame and all subsequent frames
1356 static inline void digitalWrite(BelaContext *context, int frame, int channel, int value) {
1357  unsigned int f;
1358  for(f = frame; f < context->digitalFrames; f++) {
1359  if(value)
1360  context->digital[f] |= 1 << (channel + 16);
1361  else
1362  context->digital[f] &= ~(1 << (channel + 16));
1363  }
1364 }
1365 
1366 // digitalWriteOnce()
1367 //
1368 // Sets a given digital output channel to a value for the current frame only
1369 static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value) {
1370  if(value)
1371  context->digital[frame] |= 1 << (channel + 16);
1372  else
1373  context->digital[frame] &= ~(1 << (channel + 16));
1374 }
1375 
1376 // pinMode()
1377 //
1378 // Sets the direction of a digital pin for the current frame and all subsequent frames
1379 static inline void pinMode(BelaContext *context, int frame, int channel, int mode) {
1380  unsigned int f;
1381  for(f = frame; f < context->digitalFrames; f++) {
1382  if(mode == INPUT)
1383  context->digital[f] |= (1 << channel);
1384  else
1385  context->digital[f] &= ~(1 << channel);
1386  }
1387 }
1388 
1389 // pinModeOnce()
1390 //
1391 // Sets the direction of a digital pin for the current frame only
1392 static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode) {
1393  if(mode == INPUT)
1394  context->digital[frame] |= (1 << channel);
1395  else
1396  context->digital[frame] &= ~(1 << channel);
1397 }
1398 
1399 // multiplexerAnalogRead()
1400 //
1401 // Returns the value of the given multiplexer channel for the given analog input.
1402 static inline float multiplexerAnalogRead(BelaContext *context, int input, int muxChannel) {
1403  return context->multiplexerAnalogIn[muxChannel * context->analogInChannels + input];
1404 }
1405 
1406 // multiplexerChannelForFrame()
1407 //
1408 // Returns which multiplexer channel the given analog frame was taken from.
1409 static inline unsigned int multiplexerChannelForFrame(BelaContext *context, int frame) {
1410  if(context->multiplexerChannels <= 1)
1411  return 1;
1412  return (context->multiplexerStartingChannel + frame) % context->multiplexerChannels;
1413 }
1414 
1415 #ifdef __cplusplus
1416 }
1417 #endif
1418 
1419 #endif /* BELA_H_ */
int detectUnderruns
Whether to detect and log underruns.
Definition: Bela.h:430
const uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition: Bela.h:340
const float *const analogIn
Buffer holding analog input samples.
Definition: Bela.h:238
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:1304
float adcLevel
Level for the audio ADC input.
Definition: Bela.h:413
int ampMutePin
Pin where amplifier mute can be found.
Definition: Bela.h:471
const uint32_t audioInChannels
The number of audio input channels.
Definition: Bela.h:279
const float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0)
Definition: Bela.h:326
int volatile gShouldStop
const uint32_t analogInChannels
The number of analog input channels.
Definition: Bela.h:301
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:1311
static float audioReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of audioRead()
Definition: Bela.h:1293
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:1300
float headphoneLevel
Level for the headphone output.
Definition: Bela.h:417
const uint32_t analogOutChannels
The number of analog output channels.
Definition: Bela.h:306
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:346
static void analogWriteOnceNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWriteNI()
Definition: Bela.h:1326
BelaHwConfig * Bela_HwConfig_new(BelaHw hw)
const uint32_t flags
Other audio/sensor settings.
Definition: Bela.h:369
int Bela_setDACLevel(float decibels)
Set the level of the audio DAC.
int verbose
Whether to use verbose logging.
Definition: Bela.h:432
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:324
const uint32_t digitalFrames
Number of digital frames per period.
Definition: Bela.h:320
void Bela_getVersion(int *major, int *minor, int *bugfix)
Get the version of Bela you are running.
int numAudioInChannels
How many audio input channels [ignored].
Definition: Bela.h:398
unsigned int audioExpanderOutputs
Which audio expander settings to use on the input.
Definition: Bela.h:423
int Bela_setHeadphoneLevel(float decibels)
Set the level of the onboard headphone amplifier.
int pruNumber
Which PRU (0 or 1) the code should run on.
Definition: Bela.h:426
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition: render.cpp:82
BelaInitSettings * Bela_InitSettings_alloc()
Allocate the data structure containing settings for Bela.
void Bela_requestStop()
Tell the Bela program to stop.
void Bela_userSettings(BelaInitSettings *settings)
Initialise the data structure containing settings for Bela.
Definition: render.cpp:56
static void analogWriteNI(BelaContext *context, int frame, int channel, float value)
Non-interleaved version of analogWrite()
Definition: Bela.h:1340
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:1349
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:1409
Structure containing initialisation parameters for the real-time audio control system.
Definition: Bela.h:385
float *const audioOut
Buffer holding audio output samples.
Definition: Bela.h:219
int numAudioOutChannels
How many audio out channels [ignored].
Definition: Bela.h:400
char * projectName
Name of running project.
Definition: Bela.h:483
int interleave
Whether audio/analog data should be interleaved.
Definition: Bela.h:448
const uint32_t audioFrames
The number of audio frames per block.
Definition: Bela.h:277
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:1369
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:480
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:317
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition: Bela.h:186
BelaHw Bela_detectHw(void)
Detect what hardware we are running on.
const uint32_t audioExpanderEnabled
Flags for whether audio expander is enabled on given analog channels.
Definition: Bela.h:359
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition: render.cpp:36
int uniformSampleRate
Whether the analog channels should be resampled to audio sampling rate.
Definition: Bela.h:455
int numMuxChannels
How many channels to use on the multiplexer capelet, if enabled.
Definition: Bela.h:419
int Bela_initAudio(BelaInitSettings *settings, void *userData)
Initialise audio and sensor rendering environment.
int numAnalogOutChannels
How many analog output channels.
Definition: Bela.h:404
float *const analogOut
Buffer holding analog output samples.
Definition: Bela.h:253
const uint32_t audioOutChannels
The number of audio output channels.
Definition: Bela.h:281
int Bela_setPgaGain(float decibels, int channel)
Set the gain of the audio preamplifier.
int beginMuted
Whether to begin with the speakers muted.
Definition: Bela.h:409
int numAnalogInChannels
How many analog input channels.
Definition: Bela.h:402
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:1322
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition: render.cpp:54
uint32_t *const digital
Buffer holding digital input/output samples.
Definition: Bela.h:263
const uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition: Bela.h:334
unsigned int audioExpanderInputs
Which audio expander settings to use on the input.
Definition: Bela.h:421
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:1334
float dacLevel
Level for the audio DAC output.
Definition: Bela.h:411
int Bela_setADCLevel(float decibels)
Set the level of the audio ADC.
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:1289
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:296
int highPerformanceMode
Definition: Bela.h:442
int numDigitalChannels
How many channels for the GPIOs.
Definition: Bela.h:406
int stopButtonPin
Definition: Bela.h:437
void * AuxiliaryTask
Definition: Bela.h:492
static float analogReadNI(BelaContext *context, int frame, int channel)
Non-interleaved version of analogRead()
Definition: Bela.h:1315
const float *const multiplexerAnalogIn
Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.
Definition: Bela.h:353
Definition: Bela.h:91
int Bela_runInSameThread()
Begin processing audio and sensor data in the same thread as the caller.
int enableLED
Whether to use the blinking LED to indicate Bela is running.
Definition: Bela.h:434
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:1379
int useAnalog
Whether to use the analog input and output.
Definition: Bela.h:394
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:1392
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0)
Definition: Bela.h:283
int Bela_startAudio()
Begin processing audio and sensor data.
int periodSize
Number of (analog) frames per period.
Definition: Bela.h:392
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:1356
int analogOutputsPersist
Whether analog outputs should persist to future frames.
Definition: Bela.h:452
const float *const audioIn
Buffer holding audio input samples.
Definition: Bela.h:204
int useDigital
Whether to use the 16 programmable GPIOs.
Definition: Bela.h:396
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:1402
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.
void Bela_cleanupAudio()
Clean up resources from audio and sensor processing.