- Edited
Hello,
In my learning journey, while fiddling around with the "oscillator_bank" example, I wanted to make a simple adjustment that would change the pitch every 1 or 2 seconds. So I extracted the freq setting code into a function like this:
void setFreq(float f, float inc){
for(int n = 0; n < gNumOscillators; n++) {
// Update the frequencies to a regular spread, plus a small amount of randomness
// to avoid weird phase effects
float randScale = 0.99 + .02 * (float)random() / (float)RAND_MAX;
float newFreq = f * randScale;
// For efficiency, frequency is expressed in change in wavetable position per sample, not Hz or radians
osc.setFrequency(n, f); // use newFreq instead for Bela's random thing
f += inc;
}
}
And within render I added this:
int time = (int)(context->audioFramesElapsed) / 44000;
time = time % 2;
if (time != glastTime){
//cout << "!seconds";
glastTime = time;
//setFreq(500 * (time + 2), 0);
}
Sound was like I expected, but this lead to some block dropout warnings while running the code, so I assume I have to put it in another thread? What is the best resource around here for getting and idea of good thread practice? Hopefully some simple examples, since a lot of complex code will quickly blur the intent for me.
Thanks,
Søren
EDIT: is best practice to just always put everything non-audio related into auxiliary tasks? If that is the case, how do you go about providing an auxiliary task with a BelaContent object ?