Independent Oscillator Gain in DSP Tutorial

I’ve run into an issue following this “official” tutorial that uses multiple ProcessorChains and custom oscillators:
https://docs.juce.com/master/tutorial_dsp_introduction.html
I’ve added the second Custom Oscillator according to the tutorial, and it works, but when I go off-script a bit and try to change the gains independently on the two oscillators I’ve found that the 2nd oscillator’s level completely controls the final gain. That is, if I set the 2nd oscillator’s gain to 0 it completely silences the output as if the gain is affecting the entire final chain rather than just that CustomOscillator.
The gains I’m adjusting are inside ProcessorChains for each CustomOscillator so I would assume they would add together in the final Voice and not override one another. Am I missing something?
I didn’t post any code because it’s identical to the tutorial with this small change in noteStarted() that knocks out all audio:

processorChain.get<osc1Index>().setLevel (1);
processorChain.get<osc2Index>().setLevel (0);

Thanks for any ideas.

I have not used these classes, so take this with a grain of sale, but… isn’t a ‘chain’ a series of nodes where the output of one node is passed to the input of the next node? and if so, do you see how that would cause your problem?

Thanks for the response and what you’re saying makes sense. But I guess my confusion lies in what the oscillator is doing to the incoming data: I assume it does an “add” otherwise you wouldn’t hear both oscillators, right? If it’s an add, and each oscillator is getting gained before being added, then it should work the way I expect, I think. Which I guess means it doesn’t work that way after all.
My CustomOscillator has this ProcessorChain:
Oscillator → Gain
And my voice has:
CustomOscillator1 → CustomOscillator2 → Filter
So if I modify the level of those Gains and those waveforms are being added in the Voice ProcessorChain I would expect each to act independently…but that’s not what I’m hearing.
What’s the right way to pull off independent oscillator gains if this isn’t right?

Why are you assiming that an Oscillator would mix incoming data? In my mind, it’s only job is to generate data, not mix it. But, I may be wrong, and the could be something else. But, having said that, speculation only helps point us in the right direction, so as a software developer you need to dig down and figure out what the problem is. And for this, you need to look into the process function in the oscillator to determine what is going wrong. Intuatively it feels like the oscillator is replacing the data in the buffer, vs mixing it (as you desire). Debugging is a major tool for software developement. :nerd_face:

I believe I solved this. The oscillator is indeed summing as expected.
The problem was in the fact that only my Voice had a tempBuffer while my CustomOscillator, the one with the oscillator and gain in series, does not. Each call to process CustomOscillator affects the same tempBuffer. So calling the process on the Voice chain with multiple CustomOscillators was equivalent to calling Osc->Gain->Osc->Gain on a single buffer. Which means the final gain attenuates all oscillators.
My solve was to have my Voice process each CustomOscillator, add the buffer into the outputBuffer, then clear the tempBuffer, and do the next oscillator. I also apply my ADSR at each iteration.
Not sure this is the “correct” solution but it produces the wanted independent gain controls I’m after and makes sense to me.

1 Like