that's great. Next step to integrate into a Bela program: the code in the loop()
function is not suitable to run inside render()
, as it would disrupt the regular audio processing. What you should do, instead, is running it in a separate thread, using an AuxiliaryTask. For instance:
#include <Bela.h>
// paste here the code from MasterTest.cpp before setup()
void sensorLoop(void* arg)
{
while(!gShouldStop)
{
//// paste here the code from the loop() function in MasterTest.cpp
//// test it as it is, at first, then edit it is as needed to set global
//// variables that you can access from within render()
/// make sure you include the closing line `usleep(100000);`
}
}
bool setup(BelaContext* context, void* userData)
{
// paste here the code from `setup()` in `MasterTest.cpp`
//
Bela_scheduleAuxiliaryTask(Bela_createAuxiliaryTask(sensorLoop, 50, "sensorLoop", NULL));
return true;
}
void render(BelaContext* context, void* userData)
{
// perform your audio processing.
// access the global variable set in sensorLoop()
}
void cleanup(BelaContext* context, void* userData)
{}