Connect the analog output to the analog input, un the code below and open the Bela scope. This generates sinewaves and sends them to the analog outputs, and then displays the analog inputs on the scope.
#include <Bela.h>
#include <Scope.h>
#include <math.h>
Scope scope;
float gPhase;
float gFrequency = 200;
bool setup(BelaContext* context, void* userData)
{
if(context->analogInChannels < 4 || context->analogOutChannels < 4)
{
fprintf(stderr, "Not enough analog channels. Are they enabled?\n");
return false;
}
if(context->analogInChannels != context->analogOutChannels)
{
fprintf(stderr, "This program needs the same number of analog inputs and outputs\n");
return false;
}
scope.setup(context->analogInChannels, context->analogSampleRate);
return true;
}
void render(BelaContext* context, void* userData)
{
for(unsigned int n = 0; n < context->analogFrames; ++n)
{
// send sinewaves to analog outputs
gPhase += 2.f * (float)M_PI * gFrequency / context->analogSampleRate;
if(gPhase > M_PI)
gPhase -= 2.f * (float)M_PI;
float out = (sinf(gPhase) + 1.f) * 0.4f; // out is between 0 and 0.8
for(unsigned int ch = 0; ch < context->analogInChannels; ++ch)
{
analogWriteOnce(context, n, ch, out);
}
// log analog inputs to the scope
scope.log(context->analogIn + n * context->analogInChannels);
}
}
void cleanup(BelaContext* context, void* userData)
{}