I am trying to call multiple AudioCallbacks simultaneously, but I can’t. I can only hear one of them. I think it can be due to the configuration of the output of each AudioCallback.
The idea is that each AudioCallback contains a different sound process and to be able to mix them later. How could I do this?
Here part of the code:
#include "daisy_seed.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
DaisySeed hardware;
Oscillator osc[32];
int bin[32];
float freq[32];
void Audio0Callback(float **in, float **out, size_t size)
{
for(size_t i = 0; i < size; i++)
{
out[0][i] = osc[0].Process();
out[1][i] = osc[0].Process();
}
}
void Audio1Callback(float **in, float **out, size_t size)
{
for(size_t i = 0; i < size; i++)
{
out[0][i] = osc[1].Process();
out[1][i] = osc[1].Process();
}
}
void Audio2Callback(float **in, float **out, size_t size)
{
for(size_t i = 0; i < size; i++)
{
out[0][i] = osc[2].Process();
out[1][i] = osc[2].Process();
}
}
void SetupOsc(float samplerate)
{
for(int i = 0; i < 32; i++)
{
osc[i].Init(samplerate);
osc[i].SetAmp(.7);
}
}
void FreqOsc()
{
for(int i = 0; i < 32; i++)
{
//NO FUNCIONAN!! srand (time(NULL)); srand (getpid());
freq[i] = 100.0 + rand() % 5000;
osc[i].SetFreq(freq[i]);
}
}
int main
{
hardware.Configure();
hardware.Init();
float samplerate = hardware.AudioSampleRate();
AdcChannelConfig adcConfig[2];
adcConfig[0].InitSingle(hardware.GetPin(21));
adcConfig[1].InitSingle(hardware.GetPin(22));
hardware.adc.Init(adcConfig, 2);
hardware.adc.Start();
SetupOsc(samplerate);
FreqOsc();
int val = hardware.adc.GetFloat(0);
for(int i = 0; i < 32; i++)
{
int temp = val >> i;
bin[i] = temp& 0x00000001; /
}
if(bin[0] == 1)
{
hardware.StartAudio(Audio0Callback);
}
if(bin[1] == 1)
{
hardware.StartAudio(Audio1Callback);
}
if(bin[2] == 1)
{
hardware.StartAudio(Audio2Callback);
}
for(;;) {}
}
I know that I could put the oscillators in the same AudioCallback but the idea is to be able to activate and deactivate their output based on a series of bits that I saved in an array. In the end I would like to create 32 AudioCallback. One for each cell in the array.
Thanks.