Upload files to "Source"

This commit is contained in:
ed
2025-10-22 16:58:43 +00:00
parent 9a452b7c1b
commit 989632d1e0
3 changed files with 778 additions and 371 deletions

View File

@@ -1,124 +1,100 @@
#pragma once
#include <JuceHeader.h>
#include "NeuralSharedParams.h"
#include <iostream>
/*struct ADSRProcessor : public juce::dsp::ProcessorBase
{
// -----------------------------------------------------------------
void prepare(const juce::dsp::ProcessSpec& spec) override
{
adsr.setSampleRate(spec.sampleRate);
}
void reset() override { adsr.reset(); }
void process(const juce::dsp::ProcessContextReplacing<float> &ctx) override
{
DBG("Processing...");
auto& outputBlock = context.getOutputBlock();
const auto numSamples = (int)outputBlock.getNumSamples();
const auto numChannels = (int)outputBlock.getNumChannels();
// Wrap the outputBlock into AudioBuffer
for (int ch = 0; ch < numChannels; ++ch)
buffer.setWritePointer(ch, outputBlock.getChannelPointer(ch));
adsr.applyEnvelopeToBuffer(buffer, 0, numSamples);
}
// -----------------------------------------------------------------
// These two are NOT part of the ProcessorBase interface <20> they are
// your private hooks that the voice will call on note events.
void noteOn(const juce::ADSR::Parameters& p) {
adsr.setParameters(p); adsr.noteOn();
}
void noteOff() { adsr.noteOff(); }
private:
juce::ADSR adsr;
juce::AudioBuffer<float> buffer;
};*/
//==============================================================================
class NeuralSynthVoice : public juce::MPESynthesiserVoice
{
public:
NeuralSynthVoice(NeuralSharedParams& sp);
//==============================================================================
void prepare(const juce::dsp::ProcessSpec& spec);
//==============================================================================
void noteStarted() override;
//==============================================================================
void notePitchbendChanged() override;
//==============================================================================
void noteStopped(bool) override;
//==============================================================================
void notePressureChanged();
void noteTimbreChanged();
void noteKeyStateChanged();
//==============================================================================
void renderNextBlock(juce::AudioBuffer<float>& outputBuffer, int startSample, int numSamples);
void setWaveform(int waveformType);
void changeWaveform(int waveform) noexcept {
this->waveform = waveform;
}
private:
//==============================================================================
juce::HeapBlock<char> heapBlock;
juce::dsp::AudioBlock<float> tempBlock;
enum
{
oscIndex,
distortionPreGain,
distortionIndex,
distortionPostLPF,
flangerIndex,
chorusIndex,
delayIndex,
reverbIndex,
eqLowIndex,
eqMidIndex,
eqHighIndex,
masterIndex
};
juce::dsp::ProcessorChain<
juce::dsp::Oscillator<float>,
juce::dsp::Gain<float>,
juce::dsp::WaveShaper<float, std::function<float(float)>>,
juce::dsp::IIR::Filter<float>,
juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear>,
juce::dsp::Chorus<float>,
juce::dsp::DelayLine<float>,
juce::dsp::Reverb,
juce::dsp::IIR::Filter<float>, // Low shelf
juce::dsp::IIR::Filter<float>, // Mid peak
juce::dsp::IIR::Filter<float>, // High shelf
juce::dsp::Gain<float>
> processorChain;
juce::dsp::ProcessSpec spec;
juce::ADSR adsr;
NeuralSharedParams& shared;
static constexpr size_t lfoUpdateRate = 100;
static inline float msToSecs(float ms) { return ms * 0.001f; }
std::atomic<int> waveform { -1 };
};
#pragma once
#include <JuceHeader.h>
#include <functional>
#include "NeuralSharedParams.h"
#include "BlepOsc.h"
#include "WavetableOsc.h" // <-- new
//==============================================================================
// A single voice with BLEP osc + optional Wavetable osc (morph + anti-aliasing),
// per-voice ADSR, filter ADSR, flanger/delay/chorus/reverb/distortion/EQ/master.
class NeuralSynthVoice : public juce::MPESynthesiserVoice
{
public:
explicit NeuralSynthVoice (NeuralSharedParams& sharedParams);
// JUCE voice API
void prepare (const juce::dsp::ProcessSpec& spec);
void renderNextBlock (juce::AudioBuffer<float>& outputBuffer,
int startSample, int numSamples) override;
void noteStarted() override;
void noteStopped (bool allowTailOff) override;
void notePitchbendChanged() override;
void notePressureChanged() override {}
void noteTimbreChanged() override {}
void noteKeyStateChanged() override {}
// Called from the processor when the GUI waveform param changes
void changeWaveform (int wf) { setWaveform (wf); }
private:
void setWaveform (int waveformType);
//=== Processing chain (without oscillator) =================================
using DelayLine = juce::dsp::DelayLine<float,
juce::dsp::DelayLineInterpolationTypes::Linear>;
using IIR = juce::dsp::IIR::Filter<float>;
using Gain = juce::dsp::Gain<float>;
using WaveShaper = juce::dsp::WaveShaper<float, std::function<float(float)>>;
using Chorus = juce::dsp::Chorus<float>;
using Reverb = juce::dsp::Reverb;
using Limiter = juce::dsp::Limiter<float>;
enum ChainIndex
{
flangerIndex = 0,
delayIndex,
chorusIndex,
reverbIndex,
distortionPreGain,
distortionIndex,
distortionPostLPF,
eqLowIndex,
eqMidIndex,
eqHighIndex,
masterIndex,
limiterIndex
};
using Chain = juce::dsp::ProcessorChain<
DelayLine, // flanger
DelayLine, // simple delay
Chorus, // chorus
Reverb, // reverb
Gain, // distortion pre-gain (drive)
WaveShaper, // distortion waveshaper
IIR, // tone / post-EQ for distortion
IIR, // EQ low
IIR, // EQ mid
IIR, // EQ high
Gain, // master gain
Limiter // safety limiter
>;
private:
NeuralSharedParams& shared;
juce::dsp::ProcessSpec spec {};
// ==== Oscillators ========================================================
BlepOsc osc; // polyBLEP (existing)
std::atomic<int> pendingWaveform { -1 };
WT::Osc wtOsc; // wavetable oscillator (new)
static std::shared_ptr<WT::Bank> wtBank; // shared bank across voices
// ==== Envelopes & Filter =================================================
juce::ADSR adsr;
juce::ADSR filterAdsr;
juce::dsp::StateVariableTPTFilter<float> svf;
// ==== FX chain ===========================================================
Chain chain;
// ==== Scratch buffer =====================================================
juce::AudioBuffer<float> tempBuffer;
juce::dsp::AudioBlock<float> tempBlock;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NeuralSynthVoice)
};