you can use something like this:
#include <Bela.h>
#include <libraries/OscSender/OscSender.h>
#include <libraries/Biquad/Biquad.h>
#include <vector>
std::vector<float> gFilteredAnalogIns;
std::vector<Biquad> filters;
OscSender oscSender;
int remotePort = 7563;
const char* remoteIp = "192.168.7.1";
const float kSendPeriod = 0.05; // 50 ms
void sendThread(void*)
{
while(!Bela_stopRequested())
{
for(int c = 0; c < int(gFilteredAnalogIns.size()); ++c)
{
// access the filtered values from the global variable and send them
oscSender.newMessage("/analog-in").add(c).add(gFilteredAnalogIns[c]).send();
}
usleep(kSendPeriod * 1000000);
}
}
bool setup(BelaContext *context, void *userData)
{
gFilteredAnalogIns.resize(context->analogInChannels);
// The analog inputs are sent over OSC every kSendPeriod seconds.
// This amounts to a downsampling of the input signals and so
// we filter them with a lowpass filter before downsampling
// in order to reduce noise and aliasing
float cutoff = 0.7f * 1.f / kSendPeriod;
BiquadCoeff::Settings settings = {
.fs = context->analogSampleRate,
.type = BiquadCoeff::lowpass,
.cutoff = cutoff,
.q = 0.707,
.peakGainDb = 0,
};
filters.resize(gFilteredAnalogIns.size(), settings);
oscSender.setup(remotePort, remoteIp);
Bela_runAuxiliaryTask(sendThread);
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->analogFrames; ++n)
{
for(unsigned int c = 0; c < context->analogInChannels; ++c)
// filter the input signals here and store them in the
// global variable
gFilteredAnalogIns[c] = filters[c].process(analogRead(context, n, c));
}
}
void cleanup(BelaContext *context, void *userData)
{
}
on the host, open UDP port 7563 and listen for incoming messages. E.g.:
