diff --git a/modules/juce_dsp/processors/juce_Oscillator.h b/modules/juce_dsp/processors/juce_Oscillator.h index 300f5f7685..0e52f1f8b8 100644 --- a/modules/juce_dsp/processors/juce_Oscillator.h +++ b/modules/juce_dsp/processors/juce_Oscillator.h @@ -107,11 +107,11 @@ public: //============================================================================== /** Returns the result of processing a single sample. */ - SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType) noexcept + SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType input) noexcept { jassert (isInitialised()); auto increment = MathConstants::twoPi * frequency.getNextValue() / sampleRate; - return generator (phase.advance (increment) - MathConstants::pi); + return input + generator (phase.advance (increment) - MathConstants::pi); } /** Processes the input and output buffers supplied in the processing context. */ @@ -120,13 +120,14 @@ public: { jassert (isInitialised()); auto&& outBlock = context.getOutputBlock(); + auto&& inBlock = context.getInputBlock(); // this is an output-only processory - jassert (context.getInputBlock().getNumChannels() == 0 || (! context.usesSeparateInputAndOutputBlocks())); jassert (outBlock.getNumSamples() <= static_cast (rampBuffer.size())); auto len = outBlock.getNumSamples(); auto numChannels = outBlock.getNumChannels(); + auto inputChannels = inBlock.getNumChannels(); auto baseIncrement = MathConstants::twoPi / sampleRate; if (context.isBypassed) @@ -142,7 +143,31 @@ public: if (! context.isBypassed) { - for (size_t ch = 0; ch < numChannels; ++ch) + size_t ch; + + if (context.usesSeparateInputAndOutputBlocks()) + { + for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch) + { + auto* dst = outBlock.getChannelPointer (ch); + auto* src = inBlock.getChannelPointer (ch); + + for (size_t i = 0; i < len; ++i) + dst[i] = src[i] + generator (buffer[i]); + } + } + else + { + for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch) + { + auto* dst = outBlock.getChannelPointer (ch); + + for (size_t i = 0; i < len; ++i) + dst[i] += generator (buffer[i]); + } + } + + for (; ch < numChannels; ++ch) { auto* dst = outBlock.getChannelPointer (ch); @@ -163,7 +188,33 @@ public: } else { - for (size_t ch = 0; ch < numChannels; ++ch) + size_t ch; + + if (context.usesSeparateInputAndOutputBlocks()) + { + for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch) + { + p = phase; + auto* dst = outBlock.getChannelPointer (ch); + auto* src = inBlock.getChannelPointer (ch); + + for (size_t i = 0; i < len; ++i) + dst[i] = src[i] + generator (p.advance (freq) - MathConstants::pi); + } + } + else + { + for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch) + { + p = phase; + auto* dst = outBlock.getChannelPointer (ch); + + for (size_t i = 0; i < len; ++i) + dst[i] += generator (p.advance (freq) - MathConstants::pi); + } + } + + for (; ch < numChannels; ++ch) { p = phase; auto* dst = outBlock.getChannelPointer (ch);