48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "SynthVoice.h"
|
|
#include <JuceHeader.h>
|
|
|
|
class NeuralAudioEngine : public juce::MPESynthesiser
|
|
{
|
|
public:
|
|
static constexpr int maxNumVoices = 8;
|
|
|
|
explicit NeuralAudioEngine(NeuralSharedParams& sp)
|
|
{
|
|
// Create MPE voices
|
|
for (int i = 0; i < maxNumVoices; ++i)
|
|
addVoice(new NeuralSynthVoice(sp)); // <-- takes MPESynthesiserVoice*
|
|
|
|
// MPE synths do not use addSound(); note events are routed via MPE zones.
|
|
setVoiceStealingEnabled(true);
|
|
}
|
|
|
|
void prepare(const juce::dsp::ProcessSpec& spec) noexcept
|
|
{
|
|
setCurrentPlaybackSampleRate(spec.sampleRate);
|
|
|
|
for (auto* v : voices)
|
|
if (auto* nv = dynamic_cast<NeuralSynthVoice*>(v))
|
|
nv->prepare(spec);
|
|
}
|
|
|
|
template <typename VoiceFunc>
|
|
void applyToVoices(VoiceFunc&& fn) noexcept
|
|
{
|
|
for (auto* v : voices)
|
|
fn(dynamic_cast<NeuralSynthVoice*>(v));
|
|
}
|
|
|
|
private:
|
|
// keep base render
|
|
using juce::MPESynthesiser::renderNextSubBlock;
|
|
|
|
void renderNextSubBlock(juce::AudioBuffer<float>& outputAudio,
|
|
int startSample,
|
|
int numSamples) override
|
|
{
|
|
juce::MPESynthesiser::renderNextSubBlock(outputAudio, startSample, numSamples);
|
|
}
|
|
};
|