Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
Capelets/multiplexer-display/render.cpp

Display signals from the multiplexer capelet

This sketch displays the values of up to 64 analog inputs connected by the multiplexer capelet. The capelet is a separate piece of hardware that attaches to the Bela cape.

To run the sketch, the multiplexer capelet needs to be enabled using the IDE or with the -X command line option. The multiplexer capelet requires 8 analog inputs to work, and depending on the settings can use either 2, 4 or 8 multiplexer channels per analog input (for a total of 16, 32 or 64 inputs).

/*
____ _____ _ _
| __ )| ____| | / \
| _ \| _| | | / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/ \_\
http://bela.io
*/
#include <Bela.h>
#include <unistd.h>
bool gIsStdoutTty;
unsigned int gPrintCount = 0;
bool setup(BelaContext *context, void *userData)
{
if(context->multiplexerChannels == 0 || context->analogFrames == 0) {
rt_printf("Please enable the Multiplexer Capelet to run this example.\n");
return false;
}
gIsStdoutTty = isatty(1); // Check if stdout is a terminal
return true;
}
void render(BelaContext *context, void *userData)
{
gPrintCount += context->analogFrames;
if(gPrintCount >= (unsigned int)(context->analogSampleRate * 0.1)) {
gPrintCount = 0;
if(gIsStdoutTty)
rt_printf("\e[1;1H\e[2J"); // Command to clear the screen (on a terminal)
/* Go through each multiplexer setting of each analog input and display the value */
for(unsigned int input = 0; input < context->analogInChannels; input++) {
rt_printf("Input %d: ", input);
for(unsigned int muxChannel = 0; muxChannel < context->multiplexerChannels; muxChannel++) {
/* multiplexerAnalogRead() returns the most recent sample from the given
* input and mux channel. Unlike multiplexerChannelForFrame(), it does not
* give you precise control over the frame timing, so this is mainly useful
* for sensors where precise timing and sample rate is not as important.
*/
float sample = multiplexerAnalogRead(context, input, muxChannel);
rt_printf("%f ", sample);
}
rt_printf("\n");
}
}
}
void cleanup(BelaContext *context, void *userData)
{
}
Main Bela public API.
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 render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition render.cpp:68
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition render.cpp:51
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
const uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition Bela.h:385
const uint32_t analogFrames
The number of analog frames per block.
Definition Bela.h:341
const uint32_t analogInChannels
The number of analog input channels.
Definition Bela.h:346
const float analogSampleRate
Analog sample rate in Hz.
Definition Bela.h:362