124 lines
3.8 KiB
C++
124 lines
3.8 KiB
C++
#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 – 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 };
|
||
}; |