iOS 0.5.0: hand-built editors (Tape Delay, Tape Engine, Mix Tightener, Granular scope, Wavetable tables, Grain Cloud source)
Effect visualisation through the C++ effect, engine and AU; custom wavetables and grain sources load and persist with the song; the app's slot editor hosts the file picker for bespoke views. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3b035d6a7d
commit
435305e42a
@@ -19,6 +19,19 @@ public:
|
||||
virtual void update(const Params &p, float tempoBpm) = 0;
|
||||
virtual float process(float x) = 0;
|
||||
|
||||
// ---- visualisation (Kotlin's VizEffect), optional
|
||||
// The audio thread publishes a small snapshot while it runs process(); the UI
|
||||
// reads it at frame rate from another thread, without locks (relaxed atomics: a
|
||||
// value one frame stale is harmless). Publishing must never change the audio.
|
||||
|
||||
/** True if this effect publishes a scope and playhead (a VizEffect). */
|
||||
virtual bool hasScope() const { return false; }
|
||||
/** Copy up to [capacity] of the latest scope samples, oldest to newest, into
|
||||
* [out]; returns the count written, or -1 if the effect has no scope. */
|
||||
virtual int copyScope(float *out, int capacity) const { (void)out; (void)capacity; return -1; }
|
||||
/** The read/play head within the scope window, 0 (oldest) to 1 (newest), or -1. */
|
||||
virtual float playhead() const { return -1.f; }
|
||||
|
||||
/** The effect for ToolboxType name [type] ("DELAY", "FILTER", …), or nullptr
|
||||
* for types without an audio processor (the MIDI effects) or not ported yet. */
|
||||
static std::unique_ptr<Effect> create(const char *type, int sampleRate);
|
||||
|
||||
@@ -115,7 +115,11 @@ public:
|
||||
// ---- mixer meters (any thread, display only)
|
||||
float channelMeter(int ch) const;
|
||||
bool channelClipped(int ch) const;
|
||||
/** Effect visualisation isn't ported: always -1 (nothing to draw). */
|
||||
/** Effect visualisation (AudioEngine.effectScope / effectPlayhead), any thread:
|
||||
* toolbox [slotIndex]'s live scope (oldest → newest, up to [capacity] samples)
|
||||
* and read head (0..1) from the first channel chain that runs it, or -1 when it
|
||||
* isn't a scope effect placed on a mixer channel (nothing to draw). Lock-free;
|
||||
* chains swapped out meanwhile are kept alive until the read is done. */
|
||||
int effectScope(int slotIndex, float *out, int capacity) const;
|
||||
float effectPlayhead(int slotIndex) const;
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ int64_t ver(const ToolboxSlot &s) { return (int64_t)(int32_t)s.version; }
|
||||
struct FxUnit {
|
||||
ToolboxSlot *slot;
|
||||
std::unique_ptr<Effect> effect;
|
||||
int slotIndex = -1; // slot->index, kept so viz readers never touch the project
|
||||
int64_t lastVersion = -1;
|
||||
float lastTempo = NaNf;
|
||||
};
|
||||
@@ -219,6 +220,10 @@ public:
|
||||
std::vector<RetiredList> retiredLists;
|
||||
void collectRetired();
|
||||
|
||||
// ---- effect visualisation (UI thread): readers in flight hold retired chains
|
||||
mutable std::atomic<int> vizReaders{0};
|
||||
const Effect *vizFor(const Chains *chains, int slotIndex) const;
|
||||
|
||||
// ---- AudioEngine
|
||||
SynthVoice &allocSynthVoice(int bus);
|
||||
SampleVoice &allocSampleVoice(int bus);
|
||||
@@ -348,8 +353,12 @@ Engine::Impl::~Impl() {
|
||||
|
||||
void Engine::Impl::collectRetired() {
|
||||
const uint64_t done = blocksDone.load();
|
||||
for (size_t i = 0; i < retiredChains.size();)
|
||||
if (done > retiredChains[i].at) retiredChains.erase(retiredChains.begin() + (long)i); else ++i;
|
||||
// A viz reader may still be walking a retired chain; keep them all until it's out.
|
||||
// (seq_cst: a reader that arrives after this check loads the current chains.)
|
||||
if (vizReaders.load() == 0) {
|
||||
for (size_t i = 0; i < retiredChains.size();)
|
||||
if (done > retiredChains[i].at) retiredChains.erase(retiredChains.begin() + (long)i); else ++i;
|
||||
}
|
||||
for (size_t i = 0; i < retiredLists.size();)
|
||||
if (done > retiredLists[i].at) retiredLists.erase(retiredLists.begin() + (long)i); else ++i;
|
||||
}
|
||||
@@ -442,7 +451,7 @@ void Engine::Impl::rebuildFxChains() {
|
||||
ToolboxSlot *slot = slotAt(*proj, slotIndex);
|
||||
if (!slot || slot->type.empty()) continue;
|
||||
if (auto fx = Effect::create(slot->type.c_str(), sampleRate)) {
|
||||
FxUnit u{slot, std::move(fx)};
|
||||
FxUnit u{slot, std::move(fx), slotIndex};
|
||||
next->ch[ch].push_back(std::move(u));
|
||||
}
|
||||
}
|
||||
@@ -1237,8 +1246,31 @@ float Engine::channelMeter(int ch) const {
|
||||
bool Engine::channelClipped(int ch) const {
|
||||
return ch >= 0 && ch < TRACK_COUNT && impl->chClipHold[ch].load(std::memory_order_relaxed) > 0;
|
||||
}
|
||||
int Engine::effectScope(int, float *, int) const { return -1; }
|
||||
float Engine::effectPlayhead(int) const { return -1.f; }
|
||||
/** AudioEngine.vizFor: the first effect of toolbox [slotIndex] in any channel's chain
|
||||
* that publishes a scope, or nullptr. */
|
||||
const Effect *Engine::Impl::vizFor(const Chains *chains, int slotIndex) const {
|
||||
if (!chains) return nullptr;
|
||||
for (const auto &ch : chains->ch)
|
||||
for (const FxUnit &u : ch)
|
||||
if (u.slotIndex == slotIndex && u.effect->hasScope()) return u.effect.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int Engine::effectScope(int slotIndex, float *out, int capacity) const {
|
||||
impl->vizReaders.fetch_add(1);
|
||||
const Effect *e = impl->vizFor(impl->channelChains.load(), slotIndex);
|
||||
int n = e ? e->copyScope(out, capacity) : -1;
|
||||
impl->vizReaders.fetch_sub(1);
|
||||
return n;
|
||||
}
|
||||
|
||||
float Engine::effectPlayhead(int slotIndex) const {
|
||||
impl->vizReaders.fetch_add(1);
|
||||
const Effect *e = impl->vizFor(impl->channelChains.load(), slotIndex);
|
||||
float p = e ? e->playhead() : -1.f;
|
||||
impl->vizReaders.fetch_sub(1);
|
||||
return p;
|
||||
}
|
||||
|
||||
void Engine::setMidiOutEnabled(bool on) { impl->midiOutEnabled.store(on); }
|
||||
bool Engine::midiOutEnabled() const { return impl->midiOutEnabled.load(); }
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Port of GranularGlitch (Effects.kt), audio path only: a rolling 1 s buffer whose
|
||||
// read head randomly jumps back to replay short (sometimes octave-shifted) grains,
|
||||
// dry in between. The VizEffect scope/playhead is not ported (output-independent).
|
||||
// Port of GranularGlitch (Effects.kt): a rolling 1 s buffer whose read head randomly
|
||||
// jumps back to replay short (sometimes octave-shifted) grains, dry in between. Also
|
||||
// its VizEffect side: a decimated scope of the incoming signal and the read head's
|
||||
// place in that window, written here with relaxed atomics (plain stores on arm64 and
|
||||
// x86) and read by the editor from the UI thread. It never feeds back into the audio.
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "sizzle/Effect.hpp"
|
||||
@@ -18,6 +21,8 @@ constexpr float MIN_JUMP_S = 0.03f;
|
||||
constexpr float MAX_JUMP_S = 0.5f;
|
||||
constexpr float GRAIN_MIN_S = 0.02f;
|
||||
constexpr float GRAIN_MAX_S = 0.15f;
|
||||
constexpr int SCOPE_N = 96; // scope points drawn
|
||||
constexpr int SCOPE_DECIM = 96; // input samples per point (~192 ms window at 48 kHz)
|
||||
|
||||
class GranularGlitch final : public Effect {
|
||||
int sampleRate;
|
||||
@@ -30,6 +35,12 @@ class GranularGlitch final : public Effect {
|
||||
float intensity = 0.f;
|
||||
uint32_t rng = 0x2F6E1DB7u;
|
||||
|
||||
// Visualisation: a ring of decimated INPUT samples plus the normalised read head.
|
||||
std::atomic<float> scope[SCOPE_N];
|
||||
std::atomic<int> scopeWrite{0};
|
||||
int decCount = 0;
|
||||
std::atomic<float> playheadNorm{1.f};
|
||||
|
||||
float nextUnit() {
|
||||
uint32_t s = rng; s ^= s << 13; s ^= s >> 17; s ^= s << 5; rng = s;
|
||||
return (float)s * 2.3283064e-10f; // 0 … 1
|
||||
@@ -52,7 +63,9 @@ class GranularGlitch final : public Effect {
|
||||
}
|
||||
|
||||
public:
|
||||
explicit GranularGlitch(int rate) : sampleRate(rate), buf((size_t)rate, 0.f), size(rate) {}
|
||||
explicit GranularGlitch(int rate) : sampleRate(rate), buf((size_t)rate, 0.f), size(rate) {
|
||||
for (auto &v : scope) v.store(0.f, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void update(const Params &p, float) override {
|
||||
intensity = kt::coerceIn(p.f("intensity", 0.3f), 0.f, 1.f);
|
||||
@@ -80,8 +93,33 @@ public:
|
||||
readPos = rp;
|
||||
grainLeft--;
|
||||
}
|
||||
|
||||
// Scope: decimate the incoming signal into the ring.
|
||||
if (++decCount >= SCOPE_DECIM) {
|
||||
decCount = 0;
|
||||
int sw = scopeWrite.load(std::memory_order_relaxed);
|
||||
scope[sw].store(x, std::memory_order_relaxed);
|
||||
sw++; if (sw >= SCOPE_N) sw = 0;
|
||||
scopeWrite.store(sw, std::memory_order_relaxed);
|
||||
}
|
||||
// Playhead: where the read head sits within the displayed window (0 oldest … 1 now).
|
||||
double behind = wp - readPos; if (behind < 0) behind += size;
|
||||
playheadNorm.store(kt::coerceIn(1.f - (float)behind / (float)(SCOPE_N * SCOPE_DECIM), 0.f, 1.f),
|
||||
std::memory_order_relaxed);
|
||||
return out;
|
||||
}
|
||||
|
||||
bool hasScope() const override { return true; }
|
||||
|
||||
int copyScope(float *out, int capacity) const override {
|
||||
int n = capacity < SCOPE_N ? capacity : SCOPE_N;
|
||||
if (n < 0) n = 0;
|
||||
int start = scopeWrite.load(std::memory_order_relaxed); // oldest sample in the ring
|
||||
for (int k = 0; k < n; ++k) out[k] = scope[(start + k) % SCOPE_N].load(std::memory_order_relaxed);
|
||||
return n;
|
||||
}
|
||||
|
||||
float playhead() const override { return playheadNorm.load(std::memory_order_relaxed); }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user