// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later // The reference-test maker for kind "SAMPLE" (see TestVoice.hpp and // IosGoldenInstruments.kt): one SampleVoice playing the script with the engine's // voiceSample() settings; the test sample is put in a store under every id the // slot names (Sampler pads, SoundFont sfSample). #include #include #include "sampler/SampleStore.hpp" #include "sampler/SampleVoice.hpp" #include "TestVoice.hpp" namespace sizzle { namespace { class SampleTestVoice final : public TestVoice { sampler::SampleStore store; sampler::SampleVoice voice; const char *type; const Params *params; public: explicit SampleTestVoice(const TestVoiceSetup &s) : voice(s.sampleRate), type(s.type), params(s.params) { if (s.sample && s.sampleLength > 0) { Sample smp(std::vector(s.sample, s.sample + s.sampleLength), s.sampleRate2, s.loopStart, s.loopEnd); auto putId = [&](const char *id) { if (id && id[0]) store.put(id, smp); }; for (int pad = 0; pad < sampler::SamplerPads::COUNT; ++pad) putId(params->s(sampler::SamplerPads::key(pad).s)); putId(params->s("sfSample")); } } void blockStart(int) override { store.quiescent(); } void noteOn(int midi, int velocity) override { sampler::VoiceSample vs; if (sampler::voiceSample(type, *params, store, midi, vs)) voice.noteOn(vs, midi, velocity); } void noteOff(int) override { voice.noteOff(); } float render() override { return voice.render(); } }; } // namespace std::unique_ptr makeSampleTestVoice(const TestVoiceSetup &setup) { return std::make_unique(setup); } } // namespace sizzle