Printing to the console
This example demonstrates how to print to the console. When working within the audio thread use the function rt_printf(). This has the same functionality as printf() but is safe to call from the audio thread. However, make sure to not make too many calls to this function within a render loop as this may overload the CPU and/or stall communication with the board. In the render() function above a counter is implemented in order to only print to the console after a specified interval has passed. A counter variable is used to keep track of the amount of samples elapsed after starting the program. The usage of rt_printf() is identical to printf(): http://en.cppreference.com/w/cpp/io/c/fprintf
#include <cmath>
float gInterval = 0.5;
float gSecondsElapsed = 0;
int gCount = 0;
{
rt_printf("This Bela example has just started running!\n");
rt_printf("Here's the value of pi: %f\n",M_PI);
return true;
}
{
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
gCount++;
gSecondsElapsed += gInterval;
rt_printf("Time elapsed: %f\n",gSecondsElapsed);
}
}
}
{
}
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 audioFrames
The number of audio frames per block.
Definition Bela.h:322
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328