justasample/Source/Sampler/Effects/RingMod.h

56 lines
1.4 KiB
C
Raw Normal View History

2026-07-24 18:03:15 +02:00
/*
==============================================================================
RingMod.h
Created: 24 Jul 2026
Author: Armin
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "Effect.h"
/** Ring modulation effect driven by the LFO waveform. */
class RingModEffect final : public Effect
{
public:
void initialize(int /*numChannels*/, int /*fxSampleRate*/) override
{
}
void setMix(float m)
{
mix = juce::jlimit(0.f, 1.f, m);
}
void updateParams(const SamplerParameters& samplerSound, bool /*modulating*/) override
{
setMix(samplerSound.modRingModMix->get());
}
/** Process with a pre-computed LFO buffer for ring modulation. */
void processWithLFO(juce::AudioBuffer<float>& buffer, int numSamples, const float* lfoBuffer)
{
for (int ch = 0; ch < buffer.getNumChannels(); ch++)
{
auto* data = buffer.getWritePointer(ch);
for (int i = 0; i < numSamples; i++)
{
float dry = data[i];
float modulated = dry * lfoBuffer[i];
data[i] = dry + (modulated - dry) * mix;
}
}
}
void process(juce::AudioBuffer<float>& /*buffer*/, int /*numSamples*/, int /*startSample*/ = 0) override
{
// No-op without LFO buffer
}
private:
float mix{ 0.5f };
};