Files
NeuralSynth/Source/SynthVoice.h
2025-06-23 00:16:47 +01:00

100 lines
3.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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
{
synthIndex
};
juce::dsp::ProcessorChain<
juce::dsp::Oscillator<float>
> processorChain;
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 };
};