- Edited
Recently I made a post where due to resistor tolerance (~10%), the maximum values I could receive at my inputs where about a 0.1 low.
Today I extracted these values and tried to include them in a vector that I would later use within a map function to make their respective highest value equal to one, hence calibrating the inputs to 0-1. However, this has been giving me problems: when I do, I get no results on the scope.
I am attaching the code here:
#include <Bela.h>
#include <cmath>
#include <libraries/Scope/Scope.h>
#include <iostream>
#include <libraries/Oscillator/Oscillator.h>
#include <vector>
Scope scope;
int gAudioFramesPerAnalogFrame = 0;
float gInverseSampleRate;
const size_t kNumOscs = 8;
std::vector<Oscillator> gOscs;
std::vector<float> gIns(kNumOscs);
std::vector<float> gInsMax(kNumOscs);
bool setup(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < 8; ++n)
gOscs.push_back({context->audioSampleRate});
// setup the scope with 8 channels at the audio sample rate
scope.setup(8, context->audioSampleRate);
if(context->analogFrames)
gAudioFramesPerAnalogFrame = context->audioFrames / context->analogFrames;
gInverseSampleRate = 1.0 / context->audioSampleRate;
return true;
//Set values to map
gInsMax.push_back(0.899);
gInsMax.push_back(0.895);
gInsMax.push_back(0.874);
gInsMax.push_back(0.899);
gInsMax.push_back(0.925);
gInsMax.push_back(0.929);
gInsMax.push_back(0.919);
gInsMax.push_back(0.933);
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->audioFrames; n++)
{
for(unsigned int c = 0; c < gOscs.size() && c < context->analogInChannels; ++c)
{
// Read values from inputs and map them to their maximum values.
gIns[c] = analogRead(context, n / gAudioFramesPerAnalogFrame, c);
gIns[c] = map(gIns[c], 0.f, gInsMax[c], 0.f, 1.f);
}
// log mapped values into scope.
scope.log(gIns[0], gIns[1], gIns[2], gIns[3], gIns[4], gIns[5], gIns[6], gIns[7]);
}
}
void cleanup(BelaContext *context, void *userData)
{
}
I believe this is correct C++ syntax, which in turn should be printing to the scope the correct mapped values. Clearly I must have made some sort of mistake somewhere... But I am pretty clueless at the moment.
Also, there is probably a way to push.back the results into the vector at initialisation with reiteration but I could not quite figure out how.