iOS core: Synth voice, Sampler, sample store and SF2/XI loader ported, bit-exact with Kotlin
All six instruments now run in C++ (61 reference scenarios, 16 sampler tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8d85b14a67
commit
a5b2f4c873
@@ -0,0 +1,45 @@
|
||||
// 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 <atomic>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
struct Sample {
|
||||
std::vector<float> 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<int> users{0};
|
||||
|
||||
Sample() = default;
|
||||
Sample(std::vector<float> 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
|
||||
Reference in New Issue
Block a user