// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later #pragma once // SampleStore.Sample (SampleStore.kt): decoded mono PCM at its own rate, shared by // the Sampler / SoundFont voice (core/src/sampler) and the Grain Cloud's custom // source (core/src/echofield). #include #include #include namespace sizzle { struct Sample { std::vector data; int sampleRate = 0; /** Sample-loop points in frames (from an SF2/XI file), or -1 when the source has * none; the SoundFont voice uses them for sustain looping. */ int loopStart = -1; int loopEnd = -1; /** Players currently holding this sample across audio blocks (SampleVoice pins * it from noteOn until it lets go). sampler::SampleStore frees a removed sample * only once this is 0, which is what "a voice keeps its own reference" means in * the Kotlin. Not copied: a copy is a new, unpinned sample. */ mutable std::atomic users{0}; Sample() = default; Sample(std::vector d, int rate, int ls = -1, int le = -1) : data(std::move(d)), sampleRate(rate), loopStart(ls), loopEnd(le) {} Sample(const Sample &o) : data(o.data), sampleRate(o.sampleRate), loopStart(o.loopStart), loopEnd(o.loopEnd) {} Sample(Sample &&o) noexcept : data(std::move(o.data)), sampleRate(o.sampleRate), loopStart(o.loopStart), loopEnd(o.loopEnd) {} Sample &operator=(const Sample &o) { data = o.data; sampleRate = o.sampleRate; loopStart = o.loopStart; loopEnd = o.loopEnd; return *this; } Sample &operator=(Sample &&o) noexcept { data = std::move(o.data); sampleRate = o.sampleRate; loopStart = o.loopStart; loopEnd = o.loopEnd; return *this; } }; } // namespace sizzle