Morph Pad instrument: FRASIL's drone voice ported to Kotlin (0.30.0)

A new instrument for evolving pads and drones, ported from FRASIL 3.3
(Styves Goupil, an M-VAVE FM-1 firmware, MPL-2.0): a detuned saw choir,
eight drifting additive partials and noise through resonators, an
Ornstein-Uhlenbeck MOTION walk and a shared TIDE. Morph toward any of
FRASIL's 36 drone sounds by hand, by MIDI LFO or over a set time while a
note is held. Played by SynthVoice (so the tracker, live MIDI and audition
pools all get it); the frasil/ package stays MPL-2.0, LICENSES/MPL-2.0.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-13 09:04:31 +01:00
co-authored by Claude Opus 5.5
parent dae8ac46ac
commit 2d59b0429d
16 changed files with 1641 additions and 21 deletions
@@ -0,0 +1,130 @@
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
package cc.tiredsysadmin.android.sizzle.frasil
import cc.tiredsysadmin.android.sizzle.audio.SynthPatch
import cc.tiredsysadmin.android.sizzle.audio.SynthVoice
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
import cc.tiredsysadmin.android.sizzle.model.ToolboxType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import kotlin.math.abs
import kotlin.math.sqrt
class FrasilVoiceTest {
private val fs = 48_000
private fun slot(preset: String? = null, vararg extra: Pair<String, String>): ToolboxSlot =
ToolboxSlot(0).apply {
fill(ToolboxType.MORPH_PAD)
preset?.let { n -> FrasilDefs.FACTORY.first { it.name == n }.values.forEach { (k, v) -> set(k, v) } }
extra.forEach { (k, v) -> set(k, v) }
}
private class Stats(val rms: Float, val peak: Float, val finite: Boolean)
private fun render(v: FrasilVoice, frames: Int): Stats {
var sum = 0.0; var peak = 0f; var finite = true
repeat(frames) {
val x = v.render()
if (!x.isFinite()) finite = false
sum += x * x; peak = maxOf(peak, abs(x))
}
return Stats(sqrt(sum / frames).toFloat(), peak, finite)
}
@Test fun everyFactorySoundPlaysFiniteBoundedAndFreesAfterRelease() {
assertEquals(36, FrasilDefs.FACTORY.size)
for (p in FrasilDefs.FACTORY) {
val v = FrasilVoice(fs)
v.noteOn(48, 0.8f, FrasilPatch.from(slot(p.name)))
val held = render(v, fs * 3)
assertTrue("${p.name} finite", held.finite)
assertTrue("${p.name} sounds (rms ${held.rms})", held.rms > 0.003f)
// Sparse GRAIN clicks ring the resonators past the steady level (FRASIL's crackle);
// the master limiter takes those. The body of every sound stays well under.
assertTrue("${p.name} peak ${held.peak}", held.peak < 1.5f)
assertTrue("${p.name} rms ${held.rms}", held.rms < 0.5f)
println("${p.name}: rms ${"%.3f".format(held.rms)} peak ${"%.3f".format(held.peak)}")
v.noteOff()
// RELEASE tops out at 60 s (a time constant a third of it): the tail ends well inside 70 s.
var frames = 0
while (v.isActive && frames < fs * 70) { v.render(); frames++ }
assertFalse("${p.name} frees after its release", v.isActive)
}
}
@Test fun pitchFollowsTheNote() {
// STILL: partials alone, darkest tilt: nearly a sine at the note.
val v = FrasilVoice(fs)
v.noteOn(69, 1f, FrasilPatch.from(slot("Still", "motion" to "0.0")))
render(v, fs) // past the attack
var prev = v.render(); var crossings = 0; val n = fs * 2
repeat(n) { val x = v.render(); if (prev < 0f && x >= 0f) crossings++; prev = x }
assertEquals(440.0, crossings / 2.0, 3.0)
}
@Test fun morphTimeCarriesAHeldNoteToTheTarget() {
val glacier = FrasilDefs.factoryEngine("Glacier")!!.first
val v = FrasilVoice(fs)
v.noteOn(60, 1f, FrasilPatch.from(slot("Mist", FrasilDefs.MORPH_TO to "Glacier", FrasilDefs.MORPH_TIME to "1.0")))
render(v, fs / 100)
assertEquals(76 / 127f, v.valueForTest(FrasilDefs.CHOIR), 0.02f) // starts at Mist
render(v, fs + fs / 5)
assertEquals(glacier[FrasilDefs.CHOIR], v.valueForTest(FrasilDefs.CHOIR), 0.01f)
assertEquals(glacier[FrasilDefs.STRETCH], v.valueForTest(FrasilDefs.STRETCH), 0.01f)
}
@Test fun manualMorphSitsBetweenTheTwo() {
val glacier = FrasilDefs.factoryEngine("Glacier")!!.first
val v = FrasilVoice(fs)
v.noteOn(60, 1f, FrasilPatch.from(slot("Mist", FrasilDefs.MORPH_TO to "Glacier", FrasilDefs.MORPH to "0.5")))
render(v, fs / 2)
assertEquals((76 / 127f + glacier[FrasilDefs.CHOIR]) / 2f, v.valueForTest(FrasilDefs.CHOIR), 0.01f)
}
@Test fun aHeldPadIsAboutAsLoudAsASynthNote() {
val pad = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.forPad(FrasilPatch.from(slot("Mist")))) }
val syn = SynthVoice(fs).apply { noteOn(60, 100, SynthPatch.DEFAULT) }
fun rms(v: SynthVoice): Float {
repeat(fs * 2) { v.render() }
var s = 0.0; repeat(fs) { val x = v.render(); s += x * x }
return sqrt(s / fs).toFloat()
}
val ratio = rms(pad) / rms(syn)
println("pad/synth rms ratio $ratio")
assertTrue("pad/synth level ratio $ratio within -6..+6 dB", ratio in 0.5f..2f)
}
@Test fun synthVoicePlaysPadThenSynthAgain() {
val v = SynthVoice(fs)
v.noteOn(57, 100, SynthPatch.forPad(FrasilPatch.from(slot("Organ"))))
assertTrue(v.isActive && v.isGated)
var e = 0.0; repeat(fs) { val x = v.render(); e += x * x }
assertTrue(e > 0.0)
v.noteOff()
assertFalse(v.isGated)
v.noteOn(57, 100, SynthPatch.DEFAULT) // the slot became a synth
var e2 = 0.0; repeat(fs / 4) { val x = v.render(); e2 += x * x }
assertTrue(e2 > 0.0)
v.kill()
assertFalse(v.isActive)
}
@Test fun cpuBudgetForFullPolyphony() {
// 4 channels x 8 voices of the heaviest kind of sound (all three layers, SOFT, BEAT, a resonant filter).
val p = FrasilPatch.from(slot("Prism", "choir" to "1.0", "creso" to "0.5", "soft" to "0.5", "breath" to "0.8"))
val voices = Array(32) { FrasilVoice(fs).also { v -> v.noteOn(36 + it, 0.9f, p) } }
repeat(fs / 2) { for (v in voices) v.render() } // warm up the JIT
val seconds = 2
val t0 = System.nanoTime()
repeat(fs * seconds) { for (v in voices) v.render() }
val load = (System.nanoTime() - t0) / 1e9 / seconds
println("32 Morph Pad voices: ${"%.1f".format(load * 100)} % of real time on this host")
assertTrue("32 voices must render faster than real time on the host ($load)", load < 1.0)
}
}