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
@@ -0,0 +1,66 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#import "SizzleDeviceAU+Sources.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "echofield/GrainSources.hpp"
|
||||
#include "wavetable/WaveTables.hpp"
|
||||
|
||||
using namespace sizzle;
|
||||
namespace WaveTables = wavetable::WaveTables;
|
||||
namespace GrainSources = echofield::GrainSources;
|
||||
|
||||
@implementation SizzleDeviceAU (Sources)
|
||||
|
||||
+ (nullable NSData *)factoryWavetableNamed:(NSString *)name blocking:(BOOL)blocking
|
||||
frames:(NSInteger *)frames size:(NSInteger *)size {
|
||||
const char *n = name.UTF8String ?: "";
|
||||
if (WaveTables::factoryIndex(n) < 0) return nil;
|
||||
const wavetable::WaveTable *t = WaveTables::factory(n);
|
||||
if (!t) {
|
||||
if (blocking) WaveTables::prewarmBlocking(); else WaveTables::prewarm();
|
||||
t = WaveTables::factory(n);
|
||||
}
|
||||
if (!t) return nil;
|
||||
int len = t->size(0);
|
||||
if (frames) *frames = t->frames;
|
||||
if (size) *size = len;
|
||||
return [NSData dataWithBytes:t->data(0) length:(NSUInteger)t->frames * (NSUInteger)len * sizeof(float)];
|
||||
}
|
||||
|
||||
static const Sample *builtInSource(NSString *name, BOOL blocking) {
|
||||
const char *n = name.UTF8String ?: "";
|
||||
if (GrainSources::indexOf(n) < 0) return nullptr;
|
||||
const Sample *s = GrainSources::get(n);
|
||||
if (!s) {
|
||||
if (blocking) GrainSources::prewarmBlocking(); else GrainSources::prewarm();
|
||||
s = GrainSources::get(n);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
+ (nullable NSData *)grainSourcePeaksNamed:(NSString *)name buckets:(NSInteger)buckets blocking:(BOOL)blocking {
|
||||
const Sample *s = builtInSource(name, blocking);
|
||||
if (!s || s->data.empty() || buckets <= 0) return nil;
|
||||
size_t n = s->data.size();
|
||||
const float *x = s->data.data();
|
||||
NSMutableData *d = [NSMutableData dataWithLength:(NSUInteger)buckets * sizeof(float)];
|
||||
float *out = (float *)d.mutableBytes;
|
||||
for (NSInteger b = 0; b < buckets; ++b) {
|
||||
size_t a = n * (size_t)b / (size_t)buckets;
|
||||
size_t e = std::max(a + 1, n * (size_t)(b + 1) / (size_t)buckets);
|
||||
float m = 0.f;
|
||||
for (size_t i = a; i < e && i < n; ++i) m = std::max(m, std::fabs(x[i]));
|
||||
out[b] = std::min(m, 1.f);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
+ (double)grainSourceSecondsNamed:(NSString *)name {
|
||||
const Sample *s = builtInSource(name, NO);
|
||||
return s && s->sampleRate > 0 ? (double)s->data.size() / s->sampleRate : 0;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user