in C++, using the box in the IDE , it works just fine for me.
I ran the program below after connecting the headphone out back into the input (with headphone level set to the default -6dB) and I tried different values for pga-left (from the IDE):
pga-left val
0 0.00034
10 0.000350
20 0.03599
30 0.3661
40 0.843 (clipping)
50 0.953 (clipping)
59.5 0.978 (clipping)
Can you try to do the same and see if you get any comparable results? You can also open the scope and look at your input signal.
#include <Bela.h>
#include <Scope.h>
#include <math.h>
Scope scope;
float gPhase = 0;
float gPhaseInc;
float gAmplitude = 0.05;
float gFrequency = 600;
int gAccTot = 4410;
bool setup(BelaContext *context, void *userData)
{
scope.setup(2, context->audioSampleRate);
gPhaseInc = 2.f * (float)M_PI / context->audioSampleRate * gFrequency;
return true;
}
void render(BelaContext *context, void *userData)
{
static float acc = 0;
static int accCount = 0;
for (unsigned int n = 0; n < context->audioFrames; ++n)
{
float out = sinf(gPhase) * gAmplitude;
gPhase += gPhaseInc;
if(gPhase > M_PI)
gPhase -= 2.f * (float)M_PI;
audioWrite(context, n, 0, out);
float in = audioRead(context, n, 0);
acc += in * in;
++accCount;
if(accCount == gAccTot)
{
rt_printf("val: %.5f\n", acc / accCount);
accCount = 0;
acc = 0;
}
scope.log(in);
}
}
void cleanup(BelaContext *context, void *userData){}