iOS 0.1.0: the eight audio effects as AUv3 plugins on a C++ core
C++ ports of the Kotlin effects, checked against audio the Kotlin code renders (25 scenarios, IosGoldenExport); an Objective-C++ AUv3 wrapper checked on the Mac against the core (parameters, presets, saved state); a container app that checks each plugin on the device. Built as a TrollStore .ipa. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c9ad186de1
commit
dcf85ba915
@@ -0,0 +1,148 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package cc.tiredsysadmin.android.sizzle.audio
|
||||
|
||||
import cc.tiredsysadmin.android.sizzle.model.MixTightenerPresets
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxKind
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.exp
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sin
|
||||
|
||||
/**
|
||||
* Feeds the iOS port (ios/core): the Kotlin DSP is the reference the C++ port must
|
||||
* reproduce. Runs only when SIZZLE_GOLDEN_DIR is set (`make -C ios golden`), so the
|
||||
* normal `make check` skips it. Writes:
|
||||
*
|
||||
* - `ios/core/include/sizzle/DeviceSpecs.gen.hpp` (SIZZLE_SPECS_OUT): every
|
||||
* device's parameters and the Mix Tightener presets, so iOS shares one definition;
|
||||
* - into SIZZLE_GOLDEN_DIR: `input.f32` (a fixed test signal) and, per audio
|
||||
* effect and scenario, `<TYPE>__<scenario>.scn` (its parameters) and
|
||||
* `<TYPE>__<scenario>.f32` (the Kotlin output), all raw little-endian float32.
|
||||
*/
|
||||
class IosGoldenExport {
|
||||
|
||||
@Test fun export() {
|
||||
val dir = System.getenv("SIZZLE_GOLDEN_DIR")
|
||||
assumeTrue("set SIZZLE_GOLDEN_DIR to export", dir != null)
|
||||
val out = File(dir!!).apply { mkdirs() }
|
||||
System.getenv("SIZZLE_SPECS_OUT")?.let { File(it).writeText(specsHeader()) }
|
||||
|
||||
val input = testSignal()
|
||||
writeF32(File(out, "input.f32"), input)
|
||||
|
||||
for (type in ToolboxType.entries) {
|
||||
if (AudioEffect.create(type, SR) == null) continue
|
||||
for ((name, values) in scenarios(type)) {
|
||||
val slot = ToolboxSlot(0).apply { fill(type) }
|
||||
values.forEach { (k, v) -> slot.set(k, v) }
|
||||
val fx = AudioEffect.create(type, SR)!!
|
||||
fx.update(slot, TEMPO)
|
||||
val y = FloatArray(input.size) { fx.process(input[it]) }
|
||||
val base = "${type.name}__$name"
|
||||
File(out, "$base.scn").writeText(buildString {
|
||||
append("type ${type.name}\nsr $SR\ntempo $TEMPO\n")
|
||||
// Every value the effect can read, in the slot's own string form.
|
||||
slot.values.toSortedMap().forEach { (k, v) -> append("p $k $v\n") }
|
||||
})
|
||||
writeF32(File(out, "$base.f32"), y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Defaults, then two variants that move every listed parameter (enums to
|
||||
* other choices), so each control's code path is exercised. The Mix Tightener
|
||||
* hides its real settings in presets, so it uses two factory presets instead. */
|
||||
private fun scenarios(type: ToolboxType): List<Pair<String, Map<String, String>>> {
|
||||
if (type == ToolboxType.MIX_TIGHTENER) {
|
||||
return listOf("default" to emptyMap<String, String>()) +
|
||||
MixTightenerPresets.FACTORY.take(3).mapIndexed { i, p -> "preset$i" to p.params }
|
||||
}
|
||||
fun variant(frac: Float, choice: (Int) -> Int) = type.params.associate { s ->
|
||||
s.key to if (s.isEnum) s.choices[choice(s.choices.size)]
|
||||
else (s.min + frac * (s.max - s.min)).let { if (s.isInt) it.roundToInt().toFloat() else it }.toString()
|
||||
}
|
||||
return listOf(
|
||||
"default" to emptyMap(),
|
||||
"high" to variant(0.75f) { n -> n - 1 },
|
||||
"low" to variant(0.25f) { n -> minOf(1, n - 1) },
|
||||
)
|
||||
}
|
||||
|
||||
/** 1.5 s: a decaying saw burst, silence, LCG noise, silence, a sine sweep, then
|
||||
* silence for tails. Exercises gates, envelopes, filters and feedback paths. */
|
||||
private fun testSignal(): FloatArray {
|
||||
val n = (SR * 1.5).toInt()
|
||||
var seed = 0x1234567
|
||||
var sweepPhase = 0.0
|
||||
return FloatArray(n) { i ->
|
||||
val t = i.toDouble() / SR
|
||||
when {
|
||||
t < 0.25 -> (0.6 * (2 * ((t * 110) % 1.0) - 1) * exp(-t * 6)).toFloat()
|
||||
t < 0.40 -> 0f
|
||||
t < 0.70 -> { seed = seed * 1103515245 + 12345; ((seed ushr 8) and 0xFFFF) / 65535f * 0.6f - 0.3f }
|
||||
t < 0.90 -> 0f
|
||||
t < 1.20 -> {
|
||||
val f = 100 * Math.pow(50.0, (t - 0.9) / 0.3)
|
||||
sweepPhase += 2 * PI * f / SR
|
||||
(0.5 * sin(sweepPhase)).toFloat()
|
||||
}
|
||||
else -> 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeF32(f: File, x: FloatArray) {
|
||||
val bb = ByteBuffer.allocate(x.size * 4).order(ByteOrder.LITTLE_ENDIAN)
|
||||
x.forEach { bb.putFloat(it) }
|
||||
f.writeBytes(bb.array())
|
||||
}
|
||||
|
||||
private fun cstr(s: String) = "\"" + s.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
|
||||
|
||||
private fun specsHeader(): String = buildString {
|
||||
append("// GENERATED by IosGoldenExport (make -C ios golden). Do not edit.\n")
|
||||
append("// Every Sizzle device's parameters, from ToolboxType in the Android app.\n")
|
||||
append("#pragma once\n#include \"sizzle/Specs.hpp\"\n\nnamespace sizzle::gen {\n\n")
|
||||
for (t in ToolboxType.entries) {
|
||||
t.params.forEachIndexed { i, s ->
|
||||
if (s.isEnum) append("inline const char *const ${t.name}_c$i[] = {${s.choices.joinToString(", ") { cstr(it) }}, nullptr};\n")
|
||||
}
|
||||
if (t.params.isEmpty()) { append("inline const ParamSpec *const ${t.name}_params = nullptr;\n\n"); continue }
|
||||
append("inline const ParamSpec ${t.name}_params[] = {\n")
|
||||
t.params.forEachIndexed { i, s ->
|
||||
append(" {${cstr(s.key)}, ${cstr(s.label)}, ${s.default}f, ${s.min}f, ${s.max}f, ${s.isInt}, ")
|
||||
append(if (s.isEnum) "${t.name}_c$i" else "nullptr").append("},\n")
|
||||
}
|
||||
append("};\n\n")
|
||||
}
|
||||
append("inline const DeviceSpec devices[] = {\n")
|
||||
for (t in ToolboxType.entries) {
|
||||
val kind = if (t.kind == ToolboxKind.INSTRUMENT) "Kind::Instrument" else "Kind::Effect"
|
||||
append(" {${cstr(t.name)}, ${cstr(t.displayName)}, $kind, ${t.name}_params, ${t.params.size}},\n")
|
||||
}
|
||||
append("};\ninline constexpr int deviceCount = ${ToolboxType.entries.size};\n\n")
|
||||
append("// Mix Tightener factory presets: name, then key/value pairs, nullptr-terminated.\n")
|
||||
MixTightenerPresets.FACTORY.forEachIndexed { i, p ->
|
||||
append("inline const char *const mixTightener$i[] = {${cstr(p.name)}, ")
|
||||
p.params.toSortedMap().forEach { (k, v) -> append("${cstr(k)}, ${cstr(v)}, ") }
|
||||
append("nullptr};\n")
|
||||
}
|
||||
append("inline const char *const *const mixTightenerPresets[] = {")
|
||||
append(MixTightenerPresets.FACTORY.indices.joinToString(", ") { "mixTightener$it" })
|
||||
append(", nullptr};\n\n} // namespace sizzle::gen\n")
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SR = 48_000
|
||||
const val TEMPO = 120f
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user