How can I make multiple audio callbacks play simultaneously?

I think your code should look something like this if you want to run 32 osc’s at the same time:

void AudioCallback(float *in, float *out, size_t size)
{  
	float sig;

    for(size_t i = 0; i < size; i += 2)
    {
		sig = 0;

		for (int j = 0; j < 32; j++)
		{
	        sig += osc[j].Process() / 32;
		}
        out[i] = sig;
        out[i + 1] = sig;
    }
}

You control the volume from each osc using for example an ADSR or a multiplication factor in the audio callback (instead of dividing by 32, you could multiply with 1/32 or 0 if you want that osc to be silent).

You can look at my code here (OscPocketD - Portable music tool (sequencing drums and synths) - #10 by StaffanMelin) to see how I mix different oscillators in the audio callback.

If this is not what you want, please elaborate on what your goal is. :slight_smile:

Staffan

1 Like