Merge branch 'main' of git.rcmd.space:tiredsysadmin/sizzletracker-android
This commit is contained in:
@@ -7,7 +7,40 @@ one feature set; the iOS side of each version is in `ios/CHANGELOG.md`.
|
|||||||
|
|
||||||
## 0.41.1 (versionCode 77)
|
## 0.41.1 (versionCode 77)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
- No Android change: an iOS redraw fix (see `ios/CHANGELOG.md`).
|
- No Android change: an iOS redraw fix (see `ios/CHANGELOG.md`).
|
||||||
|
=======
|
||||||
|
Housekeeping and speed; nothing you can see changes, except that the app is
|
||||||
|
half the size and lighter on the battery.
|
||||||
|
|
||||||
|
- **The APK is half as big** — 21.5 MB → 10.1 MB. Release builds now go through
|
||||||
|
R8 (shrink, optimise, obfuscate, and drop unused resources), which throws away
|
||||||
|
the Compose and Material icon code the app never calls. Only the two JNI
|
||||||
|
classes are pinned by name (`app/proguard-rules.pro`), because the native
|
||||||
|
library looks them up at runtime; `make dist` keeps the de-obfuscation map next
|
||||||
|
to the APK so a crash report from a published build can still be read.
|
||||||
|
- **Less battery while a song is stopped.** The thread that feeds the transport
|
||||||
|
display polled the engine 100 times a second whatever was happening; it now
|
||||||
|
does that only while the song plays or a recording is armed, and waits 100 ms a
|
||||||
|
turn otherwise. Pressing Play still moves the playhead in the same frame — a
|
||||||
|
transport call wakes it. iOS does the same (30 Hz playing, 10 Hz stopped).
|
||||||
|
- **Smoother editing.** Every edit hands the engine the whole song as text. That
|
||||||
|
text is now built in one pre-sized pass instead of a string per line, and a
|
||||||
|
burst of edits — dragging a note column, sweeping a knob — is collected into
|
||||||
|
one sync instead of one per touch event.
|
||||||
|
- **The mixer costs less per sample.** Channel volume, mute/solo and the effect
|
||||||
|
chain are read once per audio block rather than once per frame, in the shared
|
||||||
|
C++ engine (so iOS gets it too). Bit-for-bit the same audio: all 61 reference
|
||||||
|
scenarios still match the Kotlin DSP.
|
||||||
|
- **Dead code gone.** The Kotlin DSP that `core/` replaced in 0.37.0 was still
|
||||||
|
compiled into every APK although nothing called it; it has moved to the test
|
||||||
|
source set, where it belongs as the reference the C++ is checked against. The
|
||||||
|
golden tests' `TestVoice` wrappers left the shared engine's sources for the
|
||||||
|
same reason, and a handful of unused declarations are gone.
|
||||||
|
- Fix: `make lint` failed on a manifest that asked for `ACCESS_FINE_LOCATION`
|
||||||
|
without `ACCESS_COARSE_LOCATION` (the BLE MIDI scan on Android 8–11). Both are
|
||||||
|
declared and both are requested now, so `make check` passes again.
|
||||||
|
>>>>>>> c1758637df9651f2c6a4ef6296509acb9d774186
|
||||||
|
|
||||||
## 0.41.0 (versionCode 76)
|
## 0.41.0 (versionCode 76)
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ FDROID_METADATA := /var/lib/fdroid/metadata
|
|||||||
# directory expects; app/build.gradle.kts stamps the same name onto the output.
|
# directory expects; app/build.gradle.kts stamps the same name onto the output.
|
||||||
APK_NAME := $(APP_ID)_$(VERSION_CODE).apk
|
APK_NAME := $(APP_ID)_$(VERSION_CODE).apk
|
||||||
RELEASE_APK := app/build/outputs/apk/release/$(APK_NAME)
|
RELEASE_APK := app/build/outputs/apk/release/$(APK_NAME)
|
||||||
|
# R8 renames the release build, so a crash report from it is unreadable without
|
||||||
|
# this. It is staged beside the APK and kept locally — never published.
|
||||||
|
RELEASE_MAP := app/build/outputs/mapping/release/mapping.txt
|
||||||
|
DIST_MAP := dist/$(APP_ID)_$(VERSION_CODE)-mapping.txt
|
||||||
STAGING_APK := app/build/outputs/apk/staging/app-staging.apk
|
STAGING_APK := app/build/outputs/apk/staging/app-staging.apk
|
||||||
METADATA_YML := dist/$(APP_ID).yml
|
METADATA_YML := dist/$(APP_ID).yml
|
||||||
|
|
||||||
@@ -110,12 +114,18 @@ launch:
|
|||||||
# ------------------------------------------------------------------ dist
|
# ------------------------------------------------------------------ dist
|
||||||
# Everything a publish needs, staged locally first so it can be inspected
|
# Everything a publish needs, staged locally first so it can be inspected
|
||||||
# before anything leaves the machine.
|
# before anything leaves the machine.
|
||||||
dist: dist/$(APK_NAME) $(METADATA_YML)
|
dist: dist/$(APK_NAME) $(DIST_MAP) $(METADATA_YML)
|
||||||
|
|
||||||
dist/$(APK_NAME): $(RELEASE_APK)
|
dist/$(APK_NAME): $(RELEASE_APK)
|
||||||
@mkdir -p dist
|
@mkdir -p dist
|
||||||
cp $(RELEASE_APK) $@
|
cp $(RELEASE_APK) $@
|
||||||
|
|
||||||
|
# The de-obfuscation map for this exact versionCode. `publish` does not upload it;
|
||||||
|
# it stays here so a stack trace from the published APK can still be read.
|
||||||
|
$(DIST_MAP): $(RELEASE_APK)
|
||||||
|
@mkdir -p dist
|
||||||
|
cp $(RELEASE_MAP) $@
|
||||||
|
|
||||||
# F-Droid metadata. Regenerated from versions.properties on every dist so the
|
# F-Droid metadata. Regenerated from versions.properties on every dist so the
|
||||||
# CurrentVersion lines can never lag the APK next to them.
|
# CurrentVersion lines can never lag the APK next to them.
|
||||||
$(METADATA_YML): $(VERSIONS) Makefile
|
$(METADATA_YML): $(VERSIONS) Makefile
|
||||||
@@ -153,6 +163,7 @@ publish-metadata: $(METADATA_YML)
|
|||||||
|
|
||||||
publish: publish-apk publish-metadata
|
publish: publish-apk publish-metadata
|
||||||
@echo "published $(APP_ID) $(VERSION_NAME) ($(VERSION_CODE)); sign it on the repo host"
|
@echo "published $(APP_ID) $(VERSION_NAME) ($(VERSION_CODE)); sign it on the repo host"
|
||||||
|
@echo "keep $(DIST_MAP) — it is the only way to read a crash from this build"
|
||||||
|
|
||||||
# ------------------------------------------------------------------ versioning
|
# ------------------------------------------------------------------ versioning
|
||||||
# versionCode always moves by exactly 1: F-Droid and the package manager order
|
# versionCode always moves by exactly 1: F-Droid and the package manager order
|
||||||
|
|||||||
+10
-5
@@ -52,9 +52,13 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
// Shrinking is off by default so newcomers get readable stack traces.
|
// R8: shrink + optimise + obfuscate, and drop unreferenced resources.
|
||||||
// Flip to true once the app stabilises.
|
// Only the JNI entry points need keeping (see proguard-rules.pro); the
|
||||||
isMinifyEnabled = false
|
// app reflects over nothing of its own. A release stack trace is now
|
||||||
|
// obfuscated, so keep app/build/outputs/mapping/release/mapping.txt
|
||||||
|
// beside any APK you publish — `make dist` copies it into dist/.
|
||||||
|
isMinifyEnabled = true
|
||||||
|
isShrinkResources = true
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro",
|
"proguard-rules.pro",
|
||||||
@@ -66,8 +70,9 @@ android {
|
|||||||
// the app un-optimised and makes Compose several times slower — so measuring
|
// the app un-optimised and makes Compose several times slower — so measuring
|
||||||
// UI "snappiness" on a debug build is misleading. This variant flips
|
// UI "snappiness" on a debug build is misleading. This variant flips
|
||||||
// debuggability off (the single biggest perf lever) while reusing the debug
|
// debuggability off (the single biggest perf lever) while reusing the debug
|
||||||
// signing key, so it still installs without a release keystore. R8/shrinking
|
// signing key, so it still installs without a release keystore. R8 stays off
|
||||||
// stays off to avoid needing JNI/Compose keep-rules for now.
|
// here on purpose: staging exists to measure the UI, and un-obfuscated stack
|
||||||
|
// traces are worth more than the last few hundred KB. `release` is minified.
|
||||||
create("staging") {
|
create("staging") {
|
||||||
initWith(getByName("debug"))
|
initWith(getByName("debug"))
|
||||||
isDebuggable = false
|
isDebuggable = false
|
||||||
|
|||||||
Vendored
+19
-3
@@ -1,3 +1,19 @@
|
|||||||
# ProGuard/R8 rules for release builds. Minification is currently disabled in
|
# R8 rules for the release build (isMinifyEnabled = true in build.gradle.kts).
|
||||||
# build.gradle.kts (isMinifyEnabled = false), so this file is intentionally empty.
|
#
|
||||||
# Add keep-rules here if/when you enable shrinking and hit reflection issues.
|
# Keep as little as possible: everything else — Compose, media3, DataStore,
|
||||||
|
# coroutines — ships its own consumer rules inside its AAR, and the app itself
|
||||||
|
# uses no reflection over its own classes (songs, presets, themes and bindings
|
||||||
|
# are all read and written as text by hand-written parsers in io/).
|
||||||
|
|
||||||
|
# JNI. The native library resolves Java_<mangled package>_<class>_<method> by
|
||||||
|
# name at *runtime*, so a renamed class or method is an UnsatisfiedLinkError on
|
||||||
|
# first play — not a build error. Both halves of the bridge must keep their
|
||||||
|
# names: audio/NativeEngine (the engine, src/main/cpp/jni_engine.cpp) and
|
||||||
|
# audio/NativeAudioBridge (the Oboe stream, src/main/cpp/native_audio.cpp).
|
||||||
|
-keepclasseswithmembernames,includedescriptorclasses class * {
|
||||||
|
native <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Kotlin tells R8 what is nullable through these; dropping them makes R8's
|
||||||
|
# warnings about the Kotlin stdlib noisy for no gain.
|
||||||
|
-dontwarn kotlin.Unit
|
||||||
|
|||||||
@@ -10,7 +10,11 @@
|
|||||||
BLUETOOTH_CONNECT : Bluetooth MIDI + gamepad on Android 12+.
|
BLUETOOTH_CONNECT : Bluetooth MIDI + gamepad on Android 12+.
|
||||||
BLUETOOTH_SCAN : finding BLE MIDI controllers (Settings › MIDI inputs) on
|
BLUETOOTH_SCAN : finding BLE MIDI controllers (Settings › MIDI inputs) on
|
||||||
Android 12+; never used to derive location.
|
Android 12+; never used to derive location.
|
||||||
BLUETOOTH / _ADMIN / ACCESS_FINE_LOCATION : the same scan on Android 8-11. -->
|
BLUETOOTH / _ADMIN : the same scan on Android 8-11.
|
||||||
|
ACCESS_FINE_LOCATION + ACCESS_COARSE_LOCATION : a BLE scan on Android 8-11
|
||||||
|
was gated on location permission. Both are declared
|
||||||
|
because the platform (and lint) treat FINE as an
|
||||||
|
upgrade of COARSE, and we only ever scan with them. -->
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||||
@@ -20,6 +24,7 @@
|
|||||||
android:usesPermissionFlags="neverForLocation" />
|
android:usesPermissionFlags="neverForLocation" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
|
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
|
||||||
|
|
||||||
<!-- Hardware we can *use* but do not *require* (so the app still installs on
|
<!-- Hardware we can *use* but do not *require* (so the app still installs on
|
||||||
|
|||||||
@@ -104,10 +104,12 @@ class SizzleApp : Application() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
// The Grain Cloud's built-in sources are synthesised, not shipped: render them
|
// The Grain Cloud's sources and the factory wavetables are synthesised, not
|
||||||
// in the background now so they're ready before anyone plays one.
|
// shipped — but the engine (core/, through EngineHost) renders its own set as
|
||||||
cc.tiredsysadmin.android.sizzle.audio.GrainSources.prewarm()
|
// soon as it is created, and nothing outside the two editors' drawings reads
|
||||||
cc.tiredsysadmin.android.sizzle.wavetable.WaveTables.prewarm()
|
// the Kotlin ones. They are built when those editors open (WavetablePreview /
|
||||||
|
// GrainCloudEditor) instead of here, so launch no longer renders ~6 MB of PCM
|
||||||
|
// twice and no longer holds the second copy for the life of the process.
|
||||||
// Crash recovery: restore the last autosaved project before the engine or
|
// Crash recovery: restore the last autosaved project before the engine or
|
||||||
// UI read it, so a crash / process-death resumes where the user left off.
|
// UI read it, so a crash / process-death resumes where the user left off.
|
||||||
projectStore.restore(project)
|
projectStore.restore(project)
|
||||||
|
|||||||
@@ -49,13 +49,18 @@ class AudioEngine(
|
|||||||
rebuildFxChains()
|
rebuildFxChains()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The Kotlin project changed: bring the engine's copy up to date soon (once per
|
/** The Kotlin project changed: bring the engine's copy up to date soon. Any thread.
|
||||||
* main-loop turn however many edits arrive). Any thread. */
|
*
|
||||||
|
* Coalesced to one sync per [SYNC_COALESCE_MS]. A drag over the pattern grid or a
|
||||||
|
* knob fires an edit per pointer event — each one its own main-loop turn, so a
|
||||||
|
* per-turn flag would still serialise the whole song 60 times a second. The
|
||||||
|
* engine's copy being a frame or two stale is inaudible (nothing has sounded yet
|
||||||
|
* that the edit changes), and every transport or routing call syncs first anyway. */
|
||||||
fun requestSync() {
|
fun requestSync() {
|
||||||
main.post {
|
main.post {
|
||||||
if (syncPending) return@post
|
if (syncPending) return@post
|
||||||
syncPending = true
|
syncPending = true
|
||||||
main.post { syncPending = false; syncNow() }
|
main.postDelayed({ syncPending = false; syncNow() }, SYNC_COALESCE_MS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +95,19 @@ class AudioEngine(
|
|||||||
private val _transport = MutableStateFlow(TransportState())
|
private val _transport = MutableStateFlow(TransportState())
|
||||||
val transport: StateFlow<TransportState> = _transport
|
val transport: StateFlow<TransportState> = _transport
|
||||||
|
|
||||||
|
/** Wakes the transport poller out of its idle wait (see [start]). At most one
|
||||||
|
* permit is outstanding, so a flood of transport calls costs one extra turn. */
|
||||||
|
private val pollWake = java.util.concurrent.Semaphore(0)
|
||||||
|
|
||||||
|
private fun wakePoller() { if (pollWake.availablePermits() == 0) pollWake.release() }
|
||||||
|
|
||||||
/** Start playback, optionally from [startBeat] (see Engine::play). */
|
/** Start playback, optionally from [startBeat] (see Engine::play). */
|
||||||
fun play(startBeat: Int = -1) { syncNow(); if (NativeEngine.created) NativeEngine.nativePlay(startBeat); publish() }
|
fun play(startBeat: Int = -1) { syncNow(); if (NativeEngine.created) NativeEngine.nativePlay(startBeat); publish(); wakePoller() }
|
||||||
fun pause() { if (NativeEngine.created) NativeEngine.nativePause(); publish() }
|
fun pause() { if (NativeEngine.created) NativeEngine.nativePause(); publish(); wakePoller() }
|
||||||
/** MIDI panic: hard-silence every voice and cancel the arpeggiators. */
|
/** MIDI panic: hard-silence every voice and cancel the arpeggiators. */
|
||||||
fun panic() { if (NativeEngine.created) NativeEngine.nativePanic(); publish() }
|
fun panic() { if (NativeEngine.created) NativeEngine.nativePanic(); publish(); wakePoller() }
|
||||||
/** Stop; if already stopped, rewind to the top. */
|
/** Stop; if already stopped, rewind to the top. */
|
||||||
fun stop() { if (NativeEngine.created) NativeEngine.nativeStop(); publish() }
|
fun stop() { if (NativeEngine.created) NativeEngine.nativeStop(); publish(); wakePoller() }
|
||||||
|
|
||||||
private fun publish() {
|
private fun publish() {
|
||||||
if (!NativeEngine.created) return
|
if (!NativeEngine.created) return
|
||||||
@@ -160,6 +171,7 @@ class AudioEngine(
|
|||||||
fun setRecordingArm(armed: Boolean, tailBars: Int) {
|
fun setRecordingArm(armed: Boolean, tailBars: Int) {
|
||||||
recordArmed = armed
|
recordArmed = armed
|
||||||
if (NativeEngine.created) NativeEngine.nativeSetRecordingArm(armed, tailBars.coerceIn(0, 8))
|
if (NativeEngine.created) NativeEngine.nativeSetRecordingArm(armed, tailBars.coerceIn(0, 8))
|
||||||
|
wakePoller()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setRecordTailBars(tailBars: Int) {
|
fun setRecordTailBars(tailBars: Int) {
|
||||||
@@ -167,10 +179,13 @@ class AudioEngine(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** An external MIDI clock's Start: an armed recording starts even with the song stopped. */
|
/** An external MIDI clock's Start: an armed recording starts even with the song stopped. */
|
||||||
fun externalClockStart() { if (NativeEngine.created) NativeEngine.nativeExternalClockStart() }
|
fun externalClockStart() {
|
||||||
|
if (NativeEngine.created) NativeEngine.nativeExternalClockStart()
|
||||||
|
wakePoller()
|
||||||
|
}
|
||||||
fun externalClockStop() { if (NativeEngine.created) NativeEngine.nativeExternalClockStop() }
|
fun externalClockStop() { if (NativeEngine.created) NativeEngine.nativeExternalClockStop() }
|
||||||
|
|
||||||
private var wasRecording = false
|
@Volatile private var wasRecording = false
|
||||||
|
|
||||||
private fun pollRecording() {
|
private fun pollRecording() {
|
||||||
val active = NativeEngine.nativeRecordingActive()
|
val active = NativeEngine.nativeRecordingActive()
|
||||||
@@ -198,11 +213,15 @@ class AudioEngine(
|
|||||||
fun start() {
|
fun start() {
|
||||||
if (running) return
|
if (running) return
|
||||||
running = true
|
running = true
|
||||||
// Transport and recording state for the UI, ~100 times a second.
|
// Transport and recording state for the UI: ~100 times a second while there is
|
||||||
|
// something to watch, 10 times a second when the song is stopped and nothing is
|
||||||
|
// armed (then only an external MIDI clock could start a take). A transport call
|
||||||
|
// wakes the thread through [pollWake], so the playhead still appears at once.
|
||||||
poller = thread(name = "sizzle-transport", isDaemon = true) {
|
poller = thread(name = "sizzle-transport", isDaemon = true) {
|
||||||
while (running) {
|
while (running) {
|
||||||
if (NativeEngine.created) { publish(); pollRecording() }
|
if (NativeEngine.created) { publish(); pollRecording() }
|
||||||
Thread.sleep(10)
|
val busy = _transport.value.isPlaying || recordArmed || wasRecording
|
||||||
|
pollWake.tryAcquire(if (busy) 10L else 100L, java.util.concurrent.TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main.post(safetyNet)
|
main.post(safetyNet)
|
||||||
@@ -268,6 +287,7 @@ class AudioEngine(
|
|||||||
/** Stop the engine entirely (called when the last owner lets go). */
|
/** Stop the engine entirely (called when the last owner lets go). */
|
||||||
fun release() {
|
fun release() {
|
||||||
running = false
|
running = false
|
||||||
|
wakePoller()
|
||||||
main.removeCallbacks(safetyNet)
|
main.removeCallbacks(safetyNet)
|
||||||
if (NativeEngine.created) { NativeEngine.nativeSetRecordingArm(false, 0); NativeEngine.nativeEndCapture() }
|
if (NativeEngine.created) { NativeEngine.nativeSetRecordingArm(false, 0); NativeEngine.nativeEndCapture() }
|
||||||
nativeBridge?.stop()
|
nativeBridge?.stop()
|
||||||
@@ -276,11 +296,13 @@ class AudioEngine(
|
|||||||
renderThread = null
|
renderThread = null
|
||||||
track?.run { stop(); release() }
|
track?.run { stop(); release() }
|
||||||
track = null
|
track = null
|
||||||
poller?.join(100)
|
poller?.join(200)
|
||||||
poller = null
|
poller = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
const val BLOCK_FRAMES = 192 // the engine's block (~4 ms at 48 kHz)
|
const val BLOCK_FRAMES = 192 // the engine's block (~4 ms at 48 kHz)
|
||||||
|
/** How long a burst of edits is collected before one sync (see [requestSync]). */
|
||||||
|
const val SYNC_COALESCE_MS = 33L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ class BleMidi(private val context: Context) {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)
|
arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)
|
||||||
} else {
|
} else {
|
||||||
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
|
// Both, as the manifest declares them: a FINE request without COARSE is
|
||||||
|
// rejected by the platform's permission model (and flagged by lint).
|
||||||
|
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasPermissions(): Boolean = requiredPermissions().all {
|
fun hasPermissions(): Boolean = requiredPermissions().all {
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ class MidiClock(context: Context) {
|
|||||||
override fun onDeviceAdded(device: MidiDeviceInfo) = openDevice(device)
|
override fun onDeviceAdded(device: MidiDeviceInfo) = openDevice(device)
|
||||||
}
|
}
|
||||||
callback = cb
|
callback = cb
|
||||||
mm.devices.forEach(::openDevice)
|
allDevices(mm).forEach(::openDevice)
|
||||||
mm.registerDeviceCallback(cb, handler)
|
registerCallback(mm, cb)
|
||||||
running = true
|
running = true
|
||||||
thread = Thread({ sendLoop() }, "sizzle-midi-clock").apply {
|
thread = Thread({ sendLoop() }, "sizzle-midi-clock").apply {
|
||||||
priority = Thread.MAX_PRIORITY; isDaemon = true; start()
|
priority = Thread.MAX_PRIORITY; isDaemon = true; start()
|
||||||
@@ -90,6 +90,16 @@ class MidiClock(context: Context) {
|
|||||||
outPorts.clear()
|
outPorts.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same two deprecations MidiInput suppresses the same way: getDevices and the
|
||||||
|
// Handler overload of registerDeviceCallback are still the only ones that list
|
||||||
|
// and watch every transport below API 33.
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private fun allDevices(mm: MidiManager): List<MidiDeviceInfo> = mm.devices.toList()
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private fun registerCallback(mm: MidiManager, cb: MidiManager.DeviceCallback) =
|
||||||
|
mm.registerDeviceCallback(cb, handler)
|
||||||
|
|
||||||
private fun openDevice(info: MidiDeviceInfo) {
|
private fun openDevice(info: MidiDeviceInfo) {
|
||||||
if (info.inputPortCount == 0) return // need a port we can send TO
|
if (info.inputPortCount == 0) return // need a port we can send TO
|
||||||
midiManager?.openDevice(info, { device ->
|
midiManager?.openDevice(info, { device ->
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package cc.tiredsysadmin.android.sizzle.io
|
package cc.tiredsysadmin.android.sizzle.io
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Cell
|
import cc.tiredsysadmin.android.sizzle.model.Cell
|
||||||
|
import cc.tiredsysadmin.android.sizzle.model.LoopRegion
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Mixer
|
import cc.tiredsysadmin.android.sizzle.model.Mixer
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
import cc.tiredsysadmin.android.sizzle.model.Pattern
|
||||||
import cc.tiredsysadmin.android.sizzle.model.Project
|
import cc.tiredsysadmin.android.sizzle.model.Project
|
||||||
@@ -27,58 +28,100 @@ import cc.tiredsysadmin.android.sizzle.model.ToolboxType
|
|||||||
object ProjectIo {
|
object ProjectIo {
|
||||||
private const val HEADER = "SIZZLETRACKER-SNG 1"
|
private const val HEADER = "SIZZLETRACKER-SNG 1"
|
||||||
|
|
||||||
|
/** Room for a typical song, so [save]'s buffer never has to grow and copy. */
|
||||||
|
private const val INITIAL_CAPACITY = 32 * 1024
|
||||||
|
|
||||||
// ------------------------------------------------------------------- write
|
// ------------------------------------------------------------------- write
|
||||||
fun save(project: Project): String = buildString {
|
/**
|
||||||
appendLine(HEADER)
|
* The whole project as `.sng` text.
|
||||||
appendLine("NAME=${project.name}")
|
*
|
||||||
appendLine("TEMPO=${project.tempoBpm}")
|
* This is the hot path of the UI → engine bridge, not just the file writer:
|
||||||
appendLine("SIG=${project.timeSignature.name}")
|
* `AudioEngine.syncNow` calls it after every edit and the engine diffs the text
|
||||||
appendLine("SCALE=${project.scale.name}")
|
* (see DEVELOPER_HANDOVER.md §5.4.2). So it builds into one pre-sized buffer and
|
||||||
appendLine("ROOT=${project.rootNote}")
|
* appends numbers straight into it instead of formatting a String per line —
|
||||||
appendLine("ACTIVE=${project.activePatternId}")
|
* byte for byte the same output, a fraction of the garbage.
|
||||||
|
*/
|
||||||
|
fun save(project: Project): String {
|
||||||
|
val sb = StringBuilder(INITIAL_CAPACITY)
|
||||||
|
sb.append(HEADER).append('\n')
|
||||||
|
sb.append("NAME=").append(project.name).append('\n')
|
||||||
|
sb.append("TEMPO=").append(project.tempoBpm).append('\n')
|
||||||
|
sb.append("SIG=").append(project.timeSignature.name).append('\n')
|
||||||
|
sb.append("SCALE=").append(project.scale.name).append('\n')
|
||||||
|
sb.append("ROOT=").append(project.rootNote).append('\n')
|
||||||
|
sb.append("ACTIVE=").append(project.activePatternId).append('\n')
|
||||||
|
|
||||||
project.patterns.forEach { p ->
|
project.patterns.forEach { p ->
|
||||||
appendLine("[PATTERN id=${p.id} name=${encodeName(p.name)} len=${p.length}]")
|
sb.append("[PATTERN id=").append(p.id).append(" name=").append(encodeName(p.name))
|
||||||
|
.append(" len=").append(p.length).append("]\n")
|
||||||
for (t in 0 until Pattern.TRACK_COUNT) {
|
for (t in 0 until Pattern.TRACK_COUNT) {
|
||||||
|
val col = p.tracks[t]
|
||||||
for (line in 0 until p.length) {
|
for (line in 0 until p.length) {
|
||||||
val cell = p.cell(t, line)
|
val cell = col[line]
|
||||||
if (!cell.isEmpty) appendLine("$t,$line,${cell.note},${cell.velocity},${cell.channel}")
|
if (cell.isEmpty) continue
|
||||||
|
sb.append(t).append(',').append(line).append(',').append(cell.note)
|
||||||
|
.append(',').append(cell.velocity).append(',').append(cell.channel).append('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val arr = project.arrangement
|
val arr = project.arrangement
|
||||||
val mutes = arr.laneMuted.joinToString("") { if (it) "1" else "0" }
|
sb.append("[ARRANGEMENT bars=").append(arr.lengthBars)
|
||||||
appendLine("[ARRANGEMENT bars=${arr.lengthBars} loop=${arr.loopEnabled.b()} mutes=$mutes]")
|
.append(" loop=").append(if (arr.loopEnabled) '1' else '0').append(" mutes=")
|
||||||
|
for (muted in arr.laneMuted) sb.append(if (muted) '1' else '0')
|
||||||
|
sb.append("]\n")
|
||||||
val usedBeats = arr.lastFilledBeat() + 1
|
val usedBeats = arr.lastFilledBeat() + 1
|
||||||
for (lane in arr.slots.indices) {
|
for (lane in arr.slots.indices) {
|
||||||
|
val row = arr.slots[lane]
|
||||||
for (beat in 0 until usedBeats) {
|
for (beat in 0 until usedBeats) {
|
||||||
val pid = arr.slots[lane][beat]
|
val pid = row[beat]
|
||||||
// >= 0 is a block id; NOTE_OFF is a marker and must survive too.
|
// >= 0 is a block id; NOTE_OFF is a marker and must survive too.
|
||||||
// Anything else is EMPTY and is simply omitted.
|
// Anything else is EMPTY and is simply omitted.
|
||||||
if (pid >= 0 || pid == cc.tiredsysadmin.android.sizzle.model.Arrangement.NOTE_OFF) appendLine("$lane,$beat,$pid")
|
if (pid < 0 && pid != cc.tiredsysadmin.android.sizzle.model.Arrangement.NOTE_OFF) continue
|
||||||
|
sb.append(lane).append(',').append(beat).append(',').append(pid).append('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
appendLine("[REGION A en=${arr.regionA.enabled.b()} s=${arr.regionA.start} e=${arr.regionA.end} r=${arr.regionA.repeats}]")
|
return sb.appendTail(project).toString()
|
||||||
appendLine("[REGION B en=${arr.regionB.enabled.b()} s=${arr.regionB.start} e=${arr.regionB.end} r=${arr.regionB.repeats}]")
|
}
|
||||||
|
|
||||||
appendLine("[MIXER]")
|
/** The rest of [save]: regions, mixer, toolbox. Split out only to keep each half
|
||||||
|
* readable; the two together produce one buffer. */
|
||||||
|
private fun StringBuilder.appendTail(project: Project): StringBuilder = apply {
|
||||||
|
val arr = project.arrangement
|
||||||
|
appendRegion('A', arr.regionA)
|
||||||
|
appendRegion('B', arr.regionB)
|
||||||
|
|
||||||
|
append("[MIXER]\n")
|
||||||
project.mixer.channels.forEach { ch ->
|
project.mixer.channels.forEach { ch ->
|
||||||
appendLine(
|
append(ch.index).append(',').append(ch.instrumentSlot)
|
||||||
"${ch.index},${ch.instrumentSlot},${ch.fxSlots.joinToString(",")}," +
|
for (fx in ch.fxSlots) append(',').append(fx)
|
||||||
"${ch.midiChannel},${ch.volume},${ch.mute.b()},${ch.solo.b()},${ch.limiter.b()}",
|
append(',').append(ch.midiChannel).append(',').append(ch.volume)
|
||||||
)
|
.append(',').append(if (ch.mute) '1' else '0')
|
||||||
|
.append(',').append(if (ch.solo) '1' else '0')
|
||||||
|
.append(',').append(if (ch.limiter) '1' else '0').append('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
appendLine("[TOOLBOX]")
|
append("[TOOLBOX]\n")
|
||||||
project.toolbox.forEach { slot ->
|
project.toolbox.forEach { slot ->
|
||||||
if (!slot.isEmpty) {
|
if (slot.isEmpty) return@forEach
|
||||||
val params = slot.values.entries.joinToString(",") { "${it.key}=${it.value}" }
|
append(slot.index).append('=').append(slot.type!!.name).append(';').append(slot.name).append(';')
|
||||||
appendLine("${slot.index}=${slot.type!!.name};${slot.name};$params")
|
var first = true
|
||||||
|
for ((k, v) in slot.values) {
|
||||||
|
if (!first) append(',')
|
||||||
|
first = false
|
||||||
|
append(k).append('=').append(v)
|
||||||
}
|
}
|
||||||
|
append('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun StringBuilder.appendRegion(id: Char, r: LoopRegion) {
|
||||||
|
append("[REGION ").append(id)
|
||||||
|
.append(" en=").append(if (r.enabled) '1' else '0')
|
||||||
|
.append(" s=").append(r.start).append(" e=").append(r.end)
|
||||||
|
.append(" r=").append(r.repeats).append("]\n")
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------- read
|
// -------------------------------------------------------------------- read
|
||||||
/**
|
/**
|
||||||
* Parse [text] into the *existing* [project], replacing its contents. Used to
|
* Parse [text] into the *existing* [project], replacing its contents. Used to
|
||||||
@@ -153,8 +196,6 @@ object ProjectIo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----- small helpers -----
|
// ----- small helpers -----
|
||||||
private fun Boolean.b() = if (this) "1" else "0"
|
|
||||||
|
|
||||||
private fun parseAttrs(line: String): Map<String, String> =
|
private fun parseAttrs(line: String): Map<String, String> =
|
||||||
line.trim('[', ']').substringAfter(' ', "").split(' ')
|
line.trim('[', ']').substringAfter(' ', "").split(' ')
|
||||||
.mapNotNull { tok -> tok.split('=', limit = 2).takeIf { it.size == 2 }?.let { it[0] to it[1] } }
|
.mapNotNull { tok -> tok.split('=', limit = 2).takeIf { it.size == 2 }?.let { it[0] to it[1] } }
|
||||||
@@ -195,7 +236,7 @@ object ProjectIo {
|
|||||||
p.arrangement.set(lane, beat, pid)
|
p.arrangement.set(lane, beat, pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyRegion(region: cc.tiredsysadmin.android.sizzle.model.LoopRegion, a: Map<String, String>) {
|
private fun applyRegion(region: LoopRegion, a: Map<String, String>) {
|
||||||
region.enabled = a["en"] == "1"
|
region.enabled = a["en"] == "1"
|
||||||
region.start = a["s"]?.toIntOrNull() ?: 0
|
region.start = a["s"]?.toIntOrNull() ?: 0
|
||||||
region.end = a["e"]?.toIntOrNull() ?: 0
|
region.end = a["e"]?.toIntOrNull() ?: 0
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ enum class ToolboxType(
|
|||||||
// ---------- Instruments ----------
|
// ---------- Instruments ----------
|
||||||
// A classic 3-oscillator subtractive synth (Minimoog-style): oscillators →
|
// A classic 3-oscillator subtractive synth (Minimoog-style): oscillators →
|
||||||
// mixer → resonant filter (own contour) → amp (own envelope), with a tempo-synced
|
// mixer → resonant filter (own contour) → amp (own envelope), with a tempo-synced
|
||||||
// LFO and a small mod matrix. Rendered by [SynthVoice]; edited by NesSynthEditor.
|
// LFO and a small mod matrix. Rendered by core/src/synth/SynthVoice; edited by NesSynthEditor.
|
||||||
// NOTE: the enum name NES_SYNTH is the on-disk/serialized identifier (preset dirs,
|
// NOTE: the enum name NES_SYNTH is the on-disk/serialized identifier (preset dirs,
|
||||||
// .sng type) and must stay stable for backward compatibility; only the user-facing
|
// .sng type) and must stay stable for backward compatibility; only the user-facing
|
||||||
// displayName is generic.
|
// displayName is generic.
|
||||||
@@ -124,17 +124,17 @@ enum class ToolboxType(
|
|||||||
// FRASIL's drone voice (MPL-2.0, see the frasil package): three layers (a detuned
|
// FRASIL's drone voice (MPL-2.0, see the frasil package): three layers (a detuned
|
||||||
// saw choir, drifting additive partials, noise through resonators) that evolve
|
// saw choir, drifting additive partials, noise through resonators) that evolve
|
||||||
// while held, morphing toward one of FRASIL's 36 drone sounds. Rendered by
|
// while held, morphing toward one of FRASIL's 36 drone sounds. Rendered by
|
||||||
// FrasilVoice inside SynthVoice; edited by the paged editor in ToolboxScreen.
|
// core/src/frasil/FrasilVoice inside SynthVoice; edited by the paged editor in ToolboxScreen.
|
||||||
MORPH_PAD(ToolboxKind.INSTRUMENT, "Morph Pad", FrasilDefs.PARAMS),
|
MORPH_PAD(ToolboxKind.INSTRUMENT, "Morph Pad", FrasilDefs.PARAMS),
|
||||||
// ECHOFIELD's granular engine (MIT, see the echofield package): one cloud of up to
|
// ECHOFIELD's granular engine (MIT, see the echofield package): one cloud of up to
|
||||||
// 32 grains per mixer channel, read from a built-in source (audio/GrainSources)
|
// 32 grains per mixer channel, read from a built-in source (audio/GrainSources)
|
||||||
// or your own sample ("sfSample", as the SF2/XI loader keeps it); held notes pitch
|
// or your own sample ("sfSample", as the SF2/XI loader keeps it); held notes pitch
|
||||||
// the grains. Rendered by GrainCloud in AudioEngine; edited by GrainCloudEditor.
|
// the grains. Rendered by core/src/echofield/GrainCloud; edited by GrainCloudEditor.
|
||||||
GRAIN_CLOUD(ToolboxKind.INSTRUMENT, "Grain Cloud", EchofieldDefs.PARAMS),
|
GRAIN_CLOUD(ToolboxKind.INSTRUMENT, "Grain Cloud", EchofieldDefs.PARAMS),
|
||||||
// A two-oscillator wavetable synth (Sizzle's own, see the wavetable package): 12
|
// A two-oscillator wavetable synth (Sizzle's own, see the wavetable package): 12
|
||||||
// generated tables or an imported Serum / WaveEdit WAV ("sfSample"), band-limited
|
// generated tables or an imported Serum / WaveEdit WAV ("sfSample"), band-limited
|
||||||
// per octave, position swept by an envelope and LFO, unison, SVF filter. Rendered
|
// per octave, position swept by an envelope and LFO, unison, SVF filter. Rendered
|
||||||
// by WaveVoice inside SynthVoice; edited by WavetableEditor + the paged list.
|
// by core/src/wavetable/WaveVoice inside SynthVoice; edited by WavetableEditor + the paged list.
|
||||||
WAVETABLE(ToolboxKind.INSTRUMENT, "Wavetable", WaveDefs.PARAMS),
|
WAVETABLE(ToolboxKind.INSTRUMENT, "Wavetable", WaveDefs.PARAMS),
|
||||||
|
|
||||||
// ---------- Effects ----------
|
// ---------- Effects ----------
|
||||||
@@ -221,7 +221,7 @@ enum class ToolboxType(
|
|||||||
ToolboxKind.EFFECT, "Ambience Reverb",
|
ToolboxKind.EFFECT, "Ambience Reverb",
|
||||||
// A mono port of the Ambience 16-channel FDN reverb (OTODESK): 7 algorithms,
|
// A mono port of the Ambience 16-channel FDN reverb (OTODESK): 7 algorithms,
|
||||||
// tempo-independent tunables and 21 factory spaces (seeded into the preset
|
// tempo-independent tunables and 21 factory spaces (seeded into the preset
|
||||||
// library). Rendered by audio/AmbienceReverb.kt.
|
// library). Rendered by core/src/fx/AmbienceReverb.cpp.
|
||||||
listOf(
|
listOf(
|
||||||
ParamSpec("algo", "Algorithm", 0f, 0f, 6f, AmbiencePresets.ALGORITHMS),
|
ParamSpec("algo", "Algorithm", 0f, 0f, 6f, AmbiencePresets.ALGORITHMS),
|
||||||
ParamSpec("predelay", "Pre-Delay", 10f, 0f, 500f),
|
ParamSpec("predelay", "Pre-Delay", 10f, 0f, 500f),
|
||||||
@@ -249,7 +249,7 @@ enum class ToolboxType(
|
|||||||
// morphs the whole chain from transparent (0) to the full preset (1). Every
|
// morphs the whole chain from transparent (0) to the full preset (1). Every
|
||||||
// per-band value is a hidden slot param set by the genre/instrument presets
|
// per-band value is a hidden slot param set by the genre/instrument presets
|
||||||
// (see MixTightenerPresets); only Strength is user-facing. Rendered by
|
// (see MixTightenerPresets); only Strength is user-facing. Rendered by
|
||||||
// MixTightener in Effects.kt, edited by ui/toolbox/MixTightenerEditor.
|
// core/src/fx/MixTightener.cpp, edited by ui/toolbox/MixTightenerEditor.
|
||||||
listOf(ParamSpec("strength", "Strength", 1f, 0f, 1f)),
|
listOf(ParamSpec("strength", "Strength", 1f, 0f, 1f)),
|
||||||
),
|
),
|
||||||
TAPE_ENGINE(
|
TAPE_ENGINE(
|
||||||
@@ -258,7 +258,7 @@ enum class ToolboxType(
|
|||||||
// the pitch dives like a slowing tape (the 'speed' param is driven by that reel
|
// the pitch dives like a slowing tape (the 'speed' param is driven by that reel
|
||||||
// gesture, not a slider). wow/flutter add slow + fast pitch wobble, hiss adds
|
// gesture, not a slider). wow/flutter add slow + fast pitch wobble, hiss adds
|
||||||
// tape noise, and the wow wobble rate is tempo-synced via 'division'. Rendered
|
// tape noise, and the wow wobble rate is tempo-synced via 'division'. Rendered
|
||||||
// by TapeEngine in Effects.kt, edited by ui/toolbox/TapeEngineEditor.
|
// by core/src/fx/TapeEngine.cpp, edited by ui/toolbox/TapeEngineEditor.
|
||||||
listOf(
|
listOf(
|
||||||
ParamSpec("speed", "Speed", 1f, 0.25f, 1f),
|
ParamSpec("speed", "Speed", 1f, 0.25f, 1f),
|
||||||
ParamSpec("wow", "Wow", 0.15f, 0f, 1f),
|
ParamSpec("wow", "Wow", 0.15f, 0f, 1f),
|
||||||
@@ -272,7 +272,7 @@ enum class ToolboxType(
|
|||||||
// Stutters/repeats short grains read from a rolling buffer of the incoming
|
// Stutters/repeats short grains read from a rolling buffer of the incoming
|
||||||
// sound; the read head jumps around, and the editor draws it as a moving
|
// sound; the read head jumps around, and the editor draws it as a moving
|
||||||
// playhead over a dotted scope of the signal. One control: Intensity (how often
|
// playhead over a dotted scope of the signal. One control: Intensity (how often
|
||||||
// it glitches + how mangled). Rendered by GranularGlitch in Effects.kt, edited
|
// it glitches + how mangled). Rendered by core/src/fx/GranularGlitch.cpp, edited
|
||||||
// by ui/toolbox/GranularEditor.
|
// by ui/toolbox/GranularEditor.
|
||||||
listOf(ParamSpec("intensity", "Intensity", 0.3f, 0f, 1f)),
|
listOf(ParamSpec("intensity", "Intensity", 0.3f, 0f, 1f)),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -156,9 +156,6 @@ class AppViewModel(
|
|||||||
* notification's Stop action changes it with no UI around. */
|
* notification's Stop action changes it with no UI around. */
|
||||||
val soundModuleMode: StateFlow<Boolean> get() = sizzleApp.soundModuleEnabled
|
val soundModuleMode: StateFlow<Boolean> get() = sizzleApp.soundModuleEnabled
|
||||||
|
|
||||||
/** MIDI sources currently open (USB, Bluetooth, other apps' virtual ports). */
|
|
||||||
val midiSources: StateFlow<Int> get() = sizzleApp.soundModule.sources
|
|
||||||
|
|
||||||
fun updateSoundModuleMode(enabled: Boolean) = sizzleApp.setSoundModuleEnabled(enabled)
|
fun updateSoundModuleMode(enabled: Boolean) = sizzleApp.setSoundModuleEnabled(enabled)
|
||||||
|
|
||||||
/** Every MIDI source that can send to Sizzle, with whether it is listened to. */
|
/** Every MIDI source that can send to Sizzle, with whether it is listened to. */
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material.icons.filled.ChevronRight
|
import androidx.compose.material.icons.filled.ChevronRight
|
||||||
import androidx.compose.material.icons.filled.Piano
|
import androidx.compose.material.icons.filled.Piano
|
||||||
import androidx.compose.material.icons.filled.ContentCopy
|
import androidx.compose.material.icons.filled.ContentCopy
|
||||||
@@ -170,7 +170,7 @@ fun SettingsScreen(vm: AppViewModel) {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun SubHeader(title: String, onBack: () -> Unit) {
|
private fun SubHeader(title: String, onBack: () -> Unit) {
|
||||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||||
IconButton(onClick = onBack) { Icon(Icons.Filled.ArrowBack, contentDescription = "Back") }
|
IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") }
|
||||||
Text(title, style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
|
Text(title, style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import androidx.compose.material3.AlertDialog
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -58,6 +59,12 @@ fun GrainCloudEditor(vm: AppViewModel, slot: ToolboxSlot) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same as the wavetables: the ten built-in sources are synthesised, the engine
|
||||||
|
// renders its own set in core/, and this Kotlin copy exists only to draw the
|
||||||
|
// waveform below. Built when the editor opens rather than at launch — that is
|
||||||
|
// about 6 MB of PCM an app that never opens one no longer renders or holds.
|
||||||
|
LaunchedEffect(Unit) { GrainSources.prewarm() }
|
||||||
|
|
||||||
val sourceName = slot.string("source", EchofieldDefs.SOURCES[0])
|
val sourceName = slot.string("source", EchofieldDefs.SOURCES[0])
|
||||||
val custom = sourceName == EchofieldDefs.CUSTOM
|
val custom = sourceName == EchofieldDefs.CUSTOM
|
||||||
val sample = if (custom) SampleStore.get(slot.string(EchofieldDefs.SAMPLE_KEY)) else GrainSources.get(sourceName)
|
val sample = if (custom) SampleStore.get(slot.string(EchofieldDefs.SAMPLE_KEY)) else GrainSources.get(sourceName)
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ private fun roundedPoly(v: Array<Offset>, corner: Float): Path {
|
|||||||
val a = curr + toward(curr, prev, corner) // approach point on the incoming edge
|
val a = curr + toward(curr, prev, corner) // approach point on the incoming edge
|
||||||
val b = curr + toward(curr, next, corner) // leave point on the outgoing edge
|
val b = curr + toward(curr, next, corner) // leave point on the outgoing edge
|
||||||
if (i == 0) path.moveTo(a.x, a.y) else path.lineTo(a.x, a.y)
|
if (i == 0) path.moveTo(a.x, a.y) else path.lineTo(a.x, a.y)
|
||||||
path.quadraticBezierTo(curr.x, curr.y, b.x, b.y)
|
path.quadraticTo(curr.x, curr.y, b.x, b.y)
|
||||||
}
|
}
|
||||||
path.close()
|
path.close()
|
||||||
return path
|
return path
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import androidx.compose.material3.AlertDialog
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -45,6 +46,12 @@ import cc.tiredsysadmin.android.sizzle.wavetable.WaveTables
|
|||||||
/** Every frame of oscillator [osc]'s table stacked back to front, the one at its POSITION lit. */
|
/** Every frame of oscillator [osc]'s table stacked back to front, the one at its POSITION lit. */
|
||||||
@Composable
|
@Composable
|
||||||
fun WavetablePreview(slot: ToolboxSlot, osc: Int, tone: Color, rev: Int) {
|
fun WavetablePreview(slot: ToolboxSlot, osc: Int, tone: Color, rev: Int) {
|
||||||
|
// The factory tables are formulas, built on a worker, and only this drawing needs
|
||||||
|
// the Kotlin copy — the engine builds its own in core/. So they are built when a
|
||||||
|
// Wavetable editor is first opened, not at launch: an app that never shows one
|
||||||
|
// pays nothing. Idempotent and non-blocking; `factory` returns null until ready
|
||||||
|
// and the caption says "preparing…".
|
||||||
|
LaunchedEffect(Unit) { WaveTables.prewarm() }
|
||||||
val c = LocalRetro.current
|
val c = LocalRetro.current
|
||||||
val name = slot.string("o${osc}table", WaveDefs.TABLES[0])
|
val name = slot.string("o${osc}table", WaveDefs.TABLES[0])
|
||||||
val frame = slot.string("wtframe", WaveDefs.FRAME_SIZES[0]).toIntOrNull() ?: 0
|
val frame = slot.string("wtframe", WaveDefs.FRAME_SIZES[0]).toIntOrNull() ?: 0
|
||||||
|
|||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/fx/AmbienceReverb.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
import cc.tiredsysadmin.android.sizzle.model.AmbiencePresets
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/fx/.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
import cc.tiredsysadmin.android.sizzle.model.DelayDivisions
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/host/MasterRecorder.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/sampler/SampleVoice.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import kotlin.math.exp
|
import kotlin.math.exp
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/synth/SynthPatch.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilPatch
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilPatch
|
||||||
+6
-1
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/synth/SynthVoice.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.audio
|
package cc.tiredsysadmin.android.sizzle.audio
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilVoice
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilVoice
|
||||||
@@ -80,7 +86,6 @@ class SynthVoice(private val sampleRate: Int) {
|
|||||||
private val pad = FrasilVoice(sampleRate)
|
private val pad = FrasilVoice(sampleRate)
|
||||||
private val wave = WaveVoice(sampleRate)
|
private val wave = WaveVoice(sampleRate)
|
||||||
private var mode = MODE_SYNTH
|
private var mode = MODE_SYNTH
|
||||||
private val padMode get() = mode == MODE_PAD
|
|
||||||
|
|
||||||
val isActive: Boolean get() = when (mode) { MODE_PAD -> pad.isActive; MODE_WAVE -> wave.isActive; else -> ampEnv.active }
|
val isActive: Boolean get() = when (mode) { MODE_PAD -> pad.isActive; MODE_WAVE -> wave.isActive; else -> ampEnv.active }
|
||||||
/** Gate is still open (attack/decay/sustain) — the note is *held*. A voice in its
|
/** Gate is still open (attack/decay/sustain) — the note is *held*. A voice in its
|
||||||
+6
@@ -7,6 +7,12 @@
|
|||||||
// spawn, render_grains_part, schedule, ef_render's gate and source fade, auto_level).
|
// spawn, render_grains_part, schedule, ef_render's gate and source fade, auto_level).
|
||||||
// The MIT licence text is in LICENSES/MIT.txt of this repository.
|
// The MIT licence text is in LICENSES/MIT.txt of this repository.
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/echofield/GrainCloud.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.echofield
|
package cc.tiredsysadmin.android.sizzle.echofield
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.audio.GrainSources
|
import cc.tiredsysadmin.android.sizzle.audio.GrainSources
|
||||||
+6
@@ -6,6 +6,12 @@
|
|||||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
||||||
// https://mozilla.org/MPL/2.0/ (also in LICENSES/MPL-2.0.txt of this repository).
|
// https://mozilla.org/MPL/2.0/ (also in LICENSES/MPL-2.0.txt of this repository).
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/frasil/FrasilVoice.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.frasil
|
package cc.tiredsysadmin.android.sizzle.frasil
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
import cc.tiredsysadmin.android.sizzle.model.ToolboxSlot
|
||||||
+6
@@ -11,6 +11,12 @@
|
|||||||
// ch_svf, ch_lp, blepi, partial_ramp, partials_chunk, souffle_chunk, breath_noise,
|
// ch_svf, ch_lp, blepi, partial_ramp, partials_chunk, souffle_chunk, breath_noise,
|
||||||
// render_part) and the mix's DC blocker, warmth and FULLNESS high-pass.
|
// render_part) and the mix's DC blocker, warmth and FULLNESS high-pass.
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/frasil/FrasilVoice.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.frasil
|
package cc.tiredsysadmin.android.sizzle.frasil
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.AIR
|
import cc.tiredsysadmin.android.sizzle.frasil.FrasilDefs.AIR
|
||||||
+6
@@ -1,6 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// The Kotlin reference the C++ port in core/ is checked against (handover §5.4.2):
|
||||||
|
// the IosGolden* tests render it, and `make -C ios core-test` compares the C++ with
|
||||||
|
// that audio sample by sample. It lives in the TEST source set because both apps
|
||||||
|
// play core/ — in src/main it would only be dead code in the APK. Keep it in step
|
||||||
|
// with core/src/wavetable/WaveVoice.cpp.
|
||||||
|
|
||||||
package cc.tiredsysadmin.android.sizzle.wavetable
|
package cc.tiredsysadmin.android.sizzle.wavetable
|
||||||
|
|
||||||
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
import cc.tiredsysadmin.android.sizzle.model.TimeDivision
|
||||||
@@ -19,7 +19,6 @@ public:
|
|||||||
bool resetOnBar = false;
|
bool resetOnBar = false;
|
||||||
int genStamp = -1;
|
int genStamp = -1;
|
||||||
|
|
||||||
int noteCount() const { return noteCount_; }
|
|
||||||
/** Active while it holds at least one note. */
|
/** Active while it holds at least one note. */
|
||||||
bool active() const { return noteCount_ > 0; }
|
bool active() const { return noteCount_ > 0; }
|
||||||
|
|
||||||
|
|||||||
@@ -605,6 +605,24 @@ void Engine::Impl::fillBlock(float *out, int frames) {
|
|||||||
auditionCloudActive = auditionCloud->isActive();
|
auditionCloudActive = auditionCloud->isActive();
|
||||||
for (int i = 0; i < (int)auditionSampleVoices.size(); ++i) if (auditionSampleVoices[i]->isActive()) actASmp[actASmpN++] = i;
|
for (int i = 0; i < (int)auditionSampleVoices.size(); ++i) if (auditionSampleVoices[i]->isActive()) actASmp[actASmpN++] = i;
|
||||||
|
|
||||||
|
// Per-channel mixer state is read once per block, not once per sample: mute,
|
||||||
|
// solo and volume cannot change inside a block (the UI's edits land through
|
||||||
|
// syncProjectText between blocks), so this is the same audio with 4 loads and
|
||||||
|
// 4 branches lifted out of a 48 000-iteration loop. The FX chain pointers come
|
||||||
|
// out too, so the per-sample inner loop walks a plain pointer range.
|
||||||
|
float chGain[TRACK_COUNT] = {0.f, 0.f, 0.f, 0.f};
|
||||||
|
bool chLimit[TRACK_COUNT] = {false, false, false, false};
|
||||||
|
FxUnit *chFxBegin[TRACK_COUNT] = {nullptr, nullptr, nullptr, nullptr};
|
||||||
|
FxUnit *chFxEnd[TRACK_COUNT] = {nullptr, nullptr, nullptr, nullptr};
|
||||||
|
if (proj) {
|
||||||
|
for (int ch = 0; ch < TRACK_COUNT; ++ch) {
|
||||||
|
const auto &mc = proj->mixer.channels[ch];
|
||||||
|
chGain[ch] = mc.audible(anySolo) ? mc.volume : 0.f;
|
||||||
|
chLimit[ch] = mc.limiter;
|
||||||
|
chFxBegin[ch] = chains->ch[ch].data();
|
||||||
|
chFxEnd[ch] = chFxBegin[ch] + chains->ch[ch].size();
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int i = 0; i < frames; ++i) {
|
for (int i = 0; i < frames; ++i) {
|
||||||
if (playing.load(std::memory_order_relaxed) && proj) advanceSequencer(*proj);
|
if (playing.load(std::memory_order_relaxed) && proj) advanceSequencer(*proj);
|
||||||
|
|
||||||
@@ -618,11 +636,10 @@ void Engine::Impl::fillBlock(float *out, int frames) {
|
|||||||
for (int k = 0; k < actBSmpN; ++k) { const int vi = actBSmp[k]; channelSum[vi / BUS_POLYPHONY] += busSampleVoices[vi]->render(); }
|
for (int k = 0; k < actBSmpN; ++k) { const int vi = actBSmp[k]; channelSum[vi / BUS_POLYPHONY] += busSampleVoices[vi]->render(); }
|
||||||
for (int ch = 0; ch < TRACK_COUNT; ++ch) if (cloudOn[ch]) channelSum[ch] += clouds[ch]->render();
|
for (int ch = 0; ch < TRACK_COUNT; ++ch) if (cloudOn[ch]) channelSum[ch] += clouds[ch]->render();
|
||||||
for (int ch = 0; ch < TRACK_COUNT; ++ch) {
|
for (int ch = 0; ch < TRACK_COUNT; ++ch) {
|
||||||
const auto &mc = proj->mixer.channels[ch];
|
float s = channelSum[ch] * chGain[ch];
|
||||||
float s = mc.audible(anySolo) ? channelSum[ch] * mc.volume : 0.f;
|
for (FxUnit *u = chFxBegin[ch]; u != chFxEnd[ch]; ++u) s = u->effect->process(s);
|
||||||
for (FxUnit &u : chains->ch[ch]) s = u.effect->process(s);
|
|
||||||
if (!std::isfinite(s)) s = 0.f;
|
if (!std::isfinite(s)) s = 0.f;
|
||||||
if (mc.limiter) s = softClip(s);
|
if (chLimit[ch]) s = softClip(s);
|
||||||
const float a = s < 0.f ? -s : s;
|
const float a = s < 0.f ? -s : s;
|
||||||
if (a > chBlockPeak[ch]) chBlockPeak[ch] = a;
|
if (a > chBlockPeak[ch]) chBlockPeak[ch] = a;
|
||||||
mixL += s; mixR += s;
|
mixL += s; mixR += s;
|
||||||
@@ -636,6 +653,8 @@ void Engine::Impl::fillBlock(float *out, int frames) {
|
|||||||
const float oR = limOutR;
|
const float oR = limOutR;
|
||||||
out[2 * i] = oL;
|
out[2 * i] = oL;
|
||||||
out[2 * i + 1] = oR;
|
out[2 * i + 1] = oR;
|
||||||
|
// Checked per sample, not hoisted: recordSample itself clears recCapturing
|
||||||
|
// when a take's FX tail runs out, and must not be called again after that.
|
||||||
if (recCapturing.load(std::memory_order_relaxed) && sink) recordSample(proj, oL, oR);
|
if (recCapturing.load(std::memory_order_relaxed) && sink) recordSample(proj, oL, oR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ public:
|
|||||||
void kill();
|
void kill();
|
||||||
/** Follow edits while sounding: the values glide there over ~25 ms. */
|
/** Follow edits while sounding: the values glide there over ~25 ms. */
|
||||||
void setPatch(const FrasilPatch &p) { patch = p; }
|
void setPatch(const FrasilPatch &p) { patch = p; }
|
||||||
/** A gliding engine value now (a defs index), for tests. */
|
|
||||||
float valueForTest(int i) const { return cur[i]; }
|
|
||||||
float render();
|
float render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -0,0 +1,277 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
// What the insert-FX chain costs. Nothing here asserts; it prints numbers, so a
|
||||||
|
// change to the DSP can be argued about with measurements instead of intuition.
|
||||||
|
// Three parts:
|
||||||
|
//
|
||||||
|
// A a whole engine render (four channels of synth, a note on every line) with
|
||||||
|
// 0, 1, 2 and 4 effects per channel: the share of fillBlock the chains take.
|
||||||
|
// B each effect on its own: ns per sample, and what one instance costs as a
|
||||||
|
// share of one channel's real-time budget.
|
||||||
|
// C the block-rate question from DEVELOPER_HANDOVER.md §9, on a stand-in with
|
||||||
|
// EQ10's shape (ten biquads in series), run three ways: per sample through a
|
||||||
|
// virtual call (what the engine does today), per sample through the concrete
|
||||||
|
// type (the same work with dispatch removed — the difference is what block
|
||||||
|
// dispatch could save), and band-at-a-time over a block with the coefficients
|
||||||
|
// hoisted. All three do the same arithmetic in the same order per band.
|
||||||
|
//
|
||||||
|
// bench [seconds] (default 4; part A renders that much audio per variant)
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "echofield/GrainSources.hpp"
|
||||||
|
#include "sampler/SampleStore.hpp"
|
||||||
|
#include "sizzle/Effect.hpp"
|
||||||
|
#include "sizzle/Engine.hpp"
|
||||||
|
#include "sizzle/Model.hpp"
|
||||||
|
#include "wavetable/WaveTables.hpp"
|
||||||
|
|
||||||
|
using namespace sizzle;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr int SR = 48000;
|
||||||
|
constexpr int BLOCK = engine::Engine::BLOCK_FRAMES;
|
||||||
|
|
||||||
|
double now() {
|
||||||
|
using namespace std::chrono;
|
||||||
|
return duration<double>(steady_clock::now().time_since_epoch()).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** White-ish noise, the same every run so two runs are comparable. */
|
||||||
|
std::vector<float> noise(size_t n) {
|
||||||
|
std::vector<float> v(n);
|
||||||
|
uint32_t seed = 0x1234567u;
|
||||||
|
for (float &x : v) {
|
||||||
|
seed = seed * 1103515245u + 12345u;
|
||||||
|
x = (float)((seed >> 8) & 0xFFFF) / 65535.f - 0.5f;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- part A
|
||||||
|
|
||||||
|
/** Four channels of NES_SYNTH, a note on every line of the active pattern, and
|
||||||
|
* [nfx] shared effect slots on each channel. Slots 0..3 are the instruments and
|
||||||
|
* 4..7 the effects, so four channels of four effects still fit in sixteen. */
|
||||||
|
void buildProject(model::Project &p, int nfx) {
|
||||||
|
static const char *kFx[4] = {"FILTER", "EQ10", "DELAY", "AMBIENCE"};
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
p.toolbox[i].fill("NES_SYNTH");
|
||||||
|
p.toolbox[4 + i].fill(kFx[i]);
|
||||||
|
}
|
||||||
|
for (int ch = 0; ch < 4; ++ch) {
|
||||||
|
auto &mc = p.mixer.channels[ch];
|
||||||
|
mc.midiChannel = ch + 1;
|
||||||
|
mc.instrumentSlot = ch;
|
||||||
|
for (int i = 0; i < model::Mixer::FX_SLOTS; ++i) mc.fxSlots[i] = i < nfx ? 4 + i : -1;
|
||||||
|
}
|
||||||
|
model::Pattern &pat = p.activePattern();
|
||||||
|
for (int t = 0; t < model::Pattern::TRACK_COUNT; ++t)
|
||||||
|
for (int line = 0; line < pat.length; ++line) {
|
||||||
|
model::Cell &c = pat.cell(t, line);
|
||||||
|
c.note = 48 + t * 5 + line % 5;
|
||||||
|
c.velocity = 100;
|
||||||
|
c.channel = t + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Seconds of wall time to render [seconds] of audio with [nfx] effects per channel. */
|
||||||
|
double renderCost(int nfx, double seconds) {
|
||||||
|
sampler::SampleStore store;
|
||||||
|
model::Project project;
|
||||||
|
buildProject(project, nfx);
|
||||||
|
|
||||||
|
engine::Engine eng(SR, &store, engine::EngineGlobals{});
|
||||||
|
eng.setProject(&project);
|
||||||
|
eng.play();
|
||||||
|
|
||||||
|
std::vector<float> buf((size_t)BLOCK * 2);
|
||||||
|
const int warmup = (int)(0.5 * SR) / BLOCK;
|
||||||
|
for (int b = 0; b < warmup; ++b) eng.fillBlock(buf.data(), BLOCK);
|
||||||
|
|
||||||
|
const int blocks = (int)(seconds * SR) / BLOCK;
|
||||||
|
const double t0 = now();
|
||||||
|
for (int b = 0; b < blocks; ++b) eng.fillBlock(buf.data(), BLOCK);
|
||||||
|
return now() - t0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void partA(double seconds) {
|
||||||
|
std::printf("\nA. engine render, 4 channels of synth, %.0f s of %d Hz audio per variant\n", seconds, SR);
|
||||||
|
std::printf(" %-22s %9s %9s %12s\n", "effects per channel", "wall s", "x real", "vs 0 fx");
|
||||||
|
double base = 0;
|
||||||
|
for (int nfx : {0, 1, 2, 4}) {
|
||||||
|
const double t = renderCost(nfx, seconds);
|
||||||
|
if (nfx == 0) base = t;
|
||||||
|
std::printf(" %-22d %9.3f %8.0fx %11s\n", nfx, t, seconds / t,
|
||||||
|
nfx == 0 ? "-" : (std::to_string((long long)std::lround((t / base - 1) * 100)) + "%").c_str());
|
||||||
|
}
|
||||||
|
std::printf(" (the chain's share at 4 fx is 1 - base/total)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- part B
|
||||||
|
|
||||||
|
void partB(double seconds) {
|
||||||
|
static const char *kTypes[] = {"BITCRUSHER", "FILTER", "EQ10", "DELAY",
|
||||||
|
"MIX_TIGHTENER", "TAPE_ENGINE", "GRANULAR", "AMBIENCE"};
|
||||||
|
const size_t n = (size_t)(seconds * SR);
|
||||||
|
const std::vector<float> in = noise(n);
|
||||||
|
|
||||||
|
double ns[8] = {0};
|
||||||
|
double total = 0;
|
||||||
|
for (size_t k = 0; k < sizeof(kTypes) / sizeof(*kTypes); ++k) {
|
||||||
|
model::ToolboxSlot slot;
|
||||||
|
slot.fill(kTypes[k]);
|
||||||
|
std::unique_ptr<Effect> fx = Effect::create(kTypes[k], SR);
|
||||||
|
if (!fx) continue;
|
||||||
|
fx->update(slot.values, 120.f);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n / 8; ++i) fx->process(in[i]); // warm the delay lines
|
||||||
|
double sink = 0;
|
||||||
|
const double t0 = now();
|
||||||
|
for (size_t i = 0; i < n; ++i) sink += fx->process(in[i]);
|
||||||
|
ns[k] = (now() - t0) * 1e9 / (double)n;
|
||||||
|
if (!std::isfinite(sink)) std::printf(" note: %s went non-finite\n", kTypes[k]);
|
||||||
|
total += ns[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::printf("\nB. one effect instance, %.0f s of samples each\n", seconds);
|
||||||
|
std::printf(" %-16s %12s %16s\n", "effect", "ns/sample", "share of all 8");
|
||||||
|
for (size_t k = 0; k < sizeof(kTypes) / sizeof(*kTypes); ++k) {
|
||||||
|
if (ns[k] == 0) { std::printf(" %-16s %12s\n", kTypes[k], "no processor"); continue; }
|
||||||
|
std::printf(" %-16s %12.2f %15.0f%%\n", kTypes[k], ns[k], ns[k] / total * 100);
|
||||||
|
}
|
||||||
|
std::printf(" %-16s %12.2f\n", "all eight", total);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- part C
|
||||||
|
|
||||||
|
/** EQ10's PeakBiquad, copied so the bench can hold it by value and reach inside. */
|
||||||
|
struct Biquad {
|
||||||
|
double b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0;
|
||||||
|
double z1 = 0, z2 = 0;
|
||||||
|
|
||||||
|
void set(int sr, float centerHz, float gainDb) {
|
||||||
|
const double a = std::pow(10.0, gainDb / 40.0);
|
||||||
|
const double w0 = 2.0 * M_PI * centerHz / sr;
|
||||||
|
const double cosW = std::cos(w0);
|
||||||
|
const double alpha = std::sin(w0) / 2.0;
|
||||||
|
const double a0 = 1 + alpha / a;
|
||||||
|
b0 = (1 + alpha * a) / a0;
|
||||||
|
b1 = (-2 * cosW) / a0;
|
||||||
|
b2 = (1 - alpha * a) / a0;
|
||||||
|
a1 = (-2 * cosW) / a0;
|
||||||
|
a2 = (1 - alpha / a) / a0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float process(float x) {
|
||||||
|
const double input = (double)x;
|
||||||
|
const double out = b0 * input + z1;
|
||||||
|
z1 = b1 * input - a1 * out + z2;
|
||||||
|
z2 = b2 * input - a2 * out;
|
||||||
|
return (float)out;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Cascade {
|
||||||
|
Biquad bands[10];
|
||||||
|
Cascade() {
|
||||||
|
static const float centers[10] = {31.f, 63.f, 125.f, 250.f, 500.f, 1000.f, 2000.f, 4000.f, 8000.f, 16000.f};
|
||||||
|
for (int i = 0; i < 10; ++i) bands[i].set(SR, centers[i], (i % 3) * 3.f - 3.f);
|
||||||
|
}
|
||||||
|
void reset() { for (Biquad &b : bands) { b.z1 = 0; b.z2 = 0; } }
|
||||||
|
|
||||||
|
/** Band-at-a-time over a whole block: each band is time-invariant, so this is
|
||||||
|
* the same arithmetic in the same order per band — only the coefficient loads
|
||||||
|
* are hoisted out of the sample loop. This is what an override would do. */
|
||||||
|
void processBlockHoisted(const float *in, float *out, int n) {
|
||||||
|
for (int i = 0; i < n; ++i) out[i] = in[i];
|
||||||
|
for (Biquad &band : bands) {
|
||||||
|
const double b0 = band.b0, b1 = band.b1, b2 = band.b2, a1 = band.a1, a2 = band.a2;
|
||||||
|
double z1 = band.z1, z2 = band.z2;
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
const double input = (double)out[i];
|
||||||
|
const double y = b0 * input + z1;
|
||||||
|
z1 = b1 * input - a1 * y + z2;
|
||||||
|
z2 = b2 * input - a2 * y;
|
||||||
|
out[i] = (float)y;
|
||||||
|
}
|
||||||
|
band.z1 = z1;
|
||||||
|
band.z2 = z2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The engine's shape today: a virtual call per sample through an Effect*. */
|
||||||
|
struct VirtualCascade : Effect {
|
||||||
|
Cascade c;
|
||||||
|
void update(const Params &, float) override {}
|
||||||
|
float process(float x) override {
|
||||||
|
float y = x;
|
||||||
|
for (Biquad &b : c.bands) y = b.process(y);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void partC(double seconds) {
|
||||||
|
const size_t n = (size_t)(seconds * SR) / BLOCK * BLOCK;
|
||||||
|
const std::vector<float> in = noise(n);
|
||||||
|
std::vector<float> outA(n), outB(n);
|
||||||
|
|
||||||
|
std::vector<float> outC(n);
|
||||||
|
|
||||||
|
VirtualCascade vc;
|
||||||
|
Effect *fx = &vc; // through the base class, as the engine does
|
||||||
|
double t0 = now();
|
||||||
|
for (size_t i = 0; i < n; ++i) outA[i] = fx->process(in[i]);
|
||||||
|
const double viaVirtual = now() - t0;
|
||||||
|
|
||||||
|
VirtualCascade dc; // same code, called on the concrete type
|
||||||
|
dc.c.reset();
|
||||||
|
t0 = now();
|
||||||
|
for (size_t i = 0; i < n; ++i) outB[i] = dc.VirtualCascade::process(in[i]);
|
||||||
|
const double viaDirect = now() - t0;
|
||||||
|
|
||||||
|
Cascade block;
|
||||||
|
t0 = now();
|
||||||
|
for (size_t i = 0; i < n; i += BLOCK) block.processBlockHoisted(in.data() + i, outC.data() + i, BLOCK);
|
||||||
|
const double blocked = now() - t0;
|
||||||
|
|
||||||
|
double maxDiff = 0;
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
maxDiff = std::fmax(maxDiff, std::fabs((double)outA[i] - (double)outB[i]));
|
||||||
|
maxDiff = std::fmax(maxDiff, std::fabs((double)outA[i] - (double)outC[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
const double perNs = viaVirtual * 1e9 / (double)n;
|
||||||
|
std::printf("\nC. ten-biquad cascade (EQ10's shape), %.0f s of samples\n", seconds);
|
||||||
|
std::printf(" %-32s %8.2f ns/sample\n", "per sample, virtual (today)", perNs);
|
||||||
|
std::printf(" %-32s %8.2f ns/sample %+.0f%%\n", "per sample, direct call",
|
||||||
|
viaDirect * 1e9 / (double)n, (viaDirect / viaVirtual - 1) * 100);
|
||||||
|
std::printf(" %-32s %8.2f ns/sample %+.0f%%\n", "block, coefficients hoisted",
|
||||||
|
blocked * 1e9 / (double)n, (blocked / viaVirtual - 1) * 100);
|
||||||
|
std::printf(" dispatch is %.2f ns of the %.2f, max diff between the three %.3g\n",
|
||||||
|
(viaVirtual - viaDirect) * 1e9 / (double)n, perNs, maxDiff);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
const double seconds = argc > 1 ? std::strtod(argv[1], nullptr) : 4.0;
|
||||||
|
wavetable::WaveTables::prewarmBlocking();
|
||||||
|
echofield::GrainSources::prewarmBlocking();
|
||||||
|
|
||||||
|
std::printf("sizzle bench: %d Hz, block %d, %.0f s per measurement\n", SR, BLOCK, seconds);
|
||||||
|
partA(seconds);
|
||||||
|
partB(seconds);
|
||||||
|
partC(seconds);
|
||||||
|
std::printf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "sizzle/Effect.hpp"
|
#include "sizzle/Effect.hpp"
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "voices/TestVoice.hpp"
|
||||||
#include "wavetable/WaveTables.hpp"
|
#include "wavetable/WaveTables.hpp"
|
||||||
|
|
||||||
using namespace sizzle;
|
using namespace sizzle;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "frasil/FrasilVoice.hpp"
|
#include "frasil/FrasilVoice.hpp"
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "TestVoice.hpp"
|
||||||
|
|
||||||
namespace sizzle {
|
namespace sizzle {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "GrainCloud.hpp"
|
#include "echofield/GrainCloud.hpp"
|
||||||
#include "GrainSources.hpp"
|
#include "echofield/GrainSources.hpp"
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "TestVoice.hpp"
|
||||||
|
|
||||||
namespace sizzle {
|
namespace sizzle {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "SampleStore.hpp"
|
#include "sampler/SampleStore.hpp"
|
||||||
#include "SampleVoice.hpp"
|
#include "sampler/SampleVoice.hpp"
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "TestVoice.hpp"
|
||||||
|
|
||||||
namespace sizzle {
|
namespace sizzle {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "frasil/FrasilVoice.hpp"
|
#include "frasil/FrasilVoice.hpp"
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "TestVoice.hpp"
|
||||||
#include "synth/SynthVoice.hpp"
|
#include "synth/SynthVoice.hpp"
|
||||||
#include "wavetable/WaveTables.hpp"
|
#include "wavetable/WaveTables.hpp"
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
// definition replaces its placeholder at link time.
|
// definition replaces its placeholder at link time.
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "TestVoice.hpp"
|
||||||
|
|
||||||
#define SIZZLE_TEST_MAKER(fn) \
|
#define SIZZLE_TEST_MAKER(fn) \
|
||||||
__attribute__((weak)) std::unique_ptr<TestVoice> fn(const TestVoiceSetup &) { return nullptr; }
|
__attribute__((weak)) std::unique_ptr<TestVoice> fn(const TestVoiceSetup &) { return nullptr; }
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
// WaveVoice alone, patch from the slot, factory tables built up front.
|
// WaveVoice alone, patch from the slot, factory tables built up front.
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "sizzle/TestVoice.hpp"
|
#include "TestVoice.hpp"
|
||||||
#include "WaveTables.hpp"
|
#include "wavetable/WaveTables.hpp"
|
||||||
#include "WaveVoice.hpp"
|
#include "wavetable/WaveVoice.hpp"
|
||||||
|
|
||||||
namespace sizzle {
|
namespace sizzle {
|
||||||
namespace {
|
namespace {
|
||||||
+116
-53
@@ -38,10 +38,11 @@ in exactly what it needs and nothing else:
|
|||||||
| `make help` | lists every target and prints the current version |
|
| `make help` | lists every target and prints the current version |
|
||||||
| `make deps` | fails loudly if the JDK or the Android SDK is missing |
|
| `make deps` | fails loudly if the JDK or the Android SDK is missing |
|
||||||
| `make check` | unit tests + lint — the gate before a commit |
|
| `make check` | unit tests + lint — the gate before a commit |
|
||||||
|
| `make -C ios bench` | prints what the FX chain and each effect cost; asserts nothing |
|
||||||
| `make staging` | non-debuggable build, release-like performance, debug key |
|
| `make staging` | non-debuggable build, release-like performance, debug key |
|
||||||
| `make install` | `adb install -r` of the staging APK (keeps projects/presets) |
|
| `make install` | `adb install -r` of the staging APK (keeps projects/presets) |
|
||||||
| `make release` | **unsigned** release APK, named for F-Droid |
|
| `make release` | **unsigned** release APK, named for F-Droid |
|
||||||
| `make dist` | stages the release APK + F-Droid metadata under `dist/` |
|
| `make dist` | stages the release APK + its R8 mapping + F-Droid metadata under `dist/` |
|
||||||
| `make publish` | uploads `dist/` to the private F-Droid repo — **manual only** |
|
| `make publish` | uploads `dist/` to the private F-Droid repo — **manual only** |
|
||||||
| `make bump-minor` | feature bump: `x.(y+1).0`, versionCode +1 |
|
| `make bump-minor` | feature bump: `x.(y+1).0`, versionCode +1 |
|
||||||
|
|
||||||
@@ -98,11 +99,11 @@ the numbers by hand is how they drift apart.
|
|||||||
|
|
||||||
### 2.3 Build types
|
### 2.3 Build types
|
||||||
|
|
||||||
| Type | Debuggable | Signing | Use |
|
| Type | Debuggable | R8 | Signing | Use |
|
||||||
|------|-----------|---------|-----|
|
|------|-----------|----|---------|-----|
|
||||||
| `debug` | yes | debug key | breakpoints, instant-run edits |
|
| `debug` | yes | no | debug key | breakpoints, instant-run edits |
|
||||||
| `staging` | **no** | debug key | anything on a real device |
|
| `staging` | **no** | no | debug key | anything on a real device |
|
||||||
| `release` | no | **unsigned** | publishing only |
|
| `release` | no | **yes** | **unsigned** | publishing only |
|
||||||
|
|
||||||
`staging` exists because `debug` is misleading: a debuggable build makes ART run
|
`staging` exists because `debug` is misleading: a debuggable build makes ART run
|
||||||
the app un-optimised and Compose several times slower, so UI "snappiness"
|
the app un-optimised and Compose several times slower, so UI "snappiness"
|
||||||
@@ -114,6 +115,22 @@ installs without a release keystore. **Use `staging` for every on-device test.**
|
|||||||
the private F-Droid repo; `fdroid publish` signs what lands in the unsigned
|
the private F-Droid repo; `fdroid publish` signs what lands in the unsigned
|
||||||
directory. No keystore should ever exist in this checkout.
|
directory. No keystore should ever exist in this checkout.
|
||||||
|
|
||||||
|
`release` is also the only build R8 touches (shrink + optimise + obfuscate, plus
|
||||||
|
unused-resource removal). The app reflects over nothing of its own — songs,
|
||||||
|
presets, themes and bindings are all hand-written text parsers — so
|
||||||
|
`app/proguard-rules.pro` keeps exactly one thing: **native method names**. JNI
|
||||||
|
resolves `Java_cc_tiredsysadmin_android_sizzle_audio_NativeEngine_*` by name at
|
||||||
|
runtime, so a renamed class or method is an `UnsatisfiedLinkError` on first play,
|
||||||
|
not a build error. Everything else (Compose, media3, DataStore, coroutines) ships
|
||||||
|
its own consumer rules inside its AAR.
|
||||||
|
|
||||||
|
A release stack trace is therefore obfuscated. `make dist` copies
|
||||||
|
`app/build/outputs/mapping/release/mapping.txt` to
|
||||||
|
`dist/<application_id>_<versionCode>-mapping.txt`; keep it for every published
|
||||||
|
APK, because it is the only way to read a crash from that build. It is never
|
||||||
|
uploaded. `staging` keeps R8 off on purpose: it exists to measure the UI, and a
|
||||||
|
readable stack trace is worth more there than the last few hundred KB.
|
||||||
|
|
||||||
### 2.4 Publishing
|
### 2.4 Publishing
|
||||||
|
|
||||||
Publishing is **always a manual action, never automatic** — it is not a side
|
Publishing is **always a manual action, never automatic** — it is not a side
|
||||||
@@ -214,35 +231,28 @@ cc.tiredsysadmin.android.sizzle
|
|||||||
│ ├── MidiTrace.kt Optional receive/engine trace (setprop log.tag.SizzleMidiTrace VERBOSE)
|
│ ├── MidiTrace.kt Optional receive/engine trace (setprop log.tag.SizzleMidiTrace VERBOSE)
|
||||||
│ └── MidiInput.kt Lists/opens MIDI sources (USB, BLE, other apps' virtual ports), reconnects dead ones -> MidiSoundModule / CC bindings
|
│ └── MidiInput.kt Lists/opens MIDI sources (USB, BLE, other apps' virtual ports), reconnects dead ones -> MidiSoundModule / CC bindings
|
||||||
│
|
│
|
||||||
├── audio/ The real-time sound engine (own thread)
|
├── audio/ The engine's face (the DSP itself is core/, in C++)
|
||||||
|
│ ├── AudioEngine.kt Drives core/ through NativeEngine: transport, sync, meters, recording
|
||||||
|
│ ├── NativeEngine.kt JNI to core/src/host/EngineHost (src/main/cpp/jni_engine.cpp)
|
||||||
|
│ ├── NativeAudioBridge.kt Starts/stops the Oboe stream (which renders in C++, no JVM call)
|
||||||
│ ├── Transport.kt TransportState snapshot published to the UI
|
│ ├── Transport.kt TransportState snapshot published to the UI
|
||||||
│ ├── SynthVoice.kt One synth note (3-osc subtractive), or a Morph Pad / Wavetable note (FrasilVoice / WaveVoice)
|
│ ├── SampleStore.kt Process-wide decoded-PCM cache + WAV encode/decode (mirrored into core/)
|
||||||
│ ├── GrainSources.kt The Grain Cloud's ten built-in sources, synthesised in the background
|
|
||||||
│ ├── SampleVoice.kt Pitched + sliced playback of a decoded sample
|
|
||||||
│ ├── SampleStore.kt Process-wide decoded-PCM cache + WAV encode/decode
|
|
||||||
│ ├── SampleRecorder.kt Ad-hoc mic/USB capture into a sample
|
│ ├── SampleRecorder.kt Ad-hoc mic/USB capture into a sample
|
||||||
│ ├── SoundFontLoader.kt Extract PCM from an .sf2 / .xi into the SampleStore
|
│ ├── SoundFontLoader.kt Extract PCM from an .sf2 / .xi into the SampleStore
|
||||||
│ ├── Effects.kt Insert DSP: TapeDelay, Filter, Bitcrusher, GraphicEq (+ AudioEffect API)
|
│ └── GrainSources.kt The Grain Cloud's ten built-in sources (the UI draws their peaks)
|
||||||
│ ├── AmbienceReverb.kt FDN reverb processor
|
|
||||||
│ ├── MasterRecorder.kt Renders the master bus (with FX tail) to a WAV
|
|
||||||
│ ├── NativeAudioBridge.kt JNI bridge to the Oboe callback (calls fillBlock)
|
|
||||||
│ └── AudioEngine.kt Oboe/AudioTrack + sample-accurate sequencer + voice/FX mixing
|
|
||||||
│
|
│
|
||||||
├── frasil/ MPL-2.0 (not GPL): the Morph Pad, ported from FRASIL (see §5.7)
|
├── frasil/ MPL-2.0 (not GPL): the Morph Pad, ported from FRASIL (see §5.7)
|
||||||
│ ├── FrasilDefs.kt Its settings, engine-unit mapping, the 36 drone presets
|
│ └── FrasilDefs.kt Its settings, engine-unit mapping, the 36 drone presets
|
||||||
│ ├── FrasilPatch.kt Parsed slot snapshot (+ morph target); FrasilClock (the shared TIDE time)
|
|
||||||
│ └── FrasilVoice.kt One pad note: choir + partials + breath, drift, tide, warmth
|
|
||||||
│
|
│
|
||||||
├── wavetable/ The Wavetable synth (Sizzle's own, GPL; see §5.9)
|
├── wavetable/ The Wavetable synth (Sizzle's own, GPL; see §5.9)
|
||||||
│ ├── WaveTables.kt Band-limited tables: FFT, one mip level per octave, 12 generated tables, WAV import
|
│ ├── WaveTables.kt Band-limited tables: FFT, one mip level per octave (the editor draws them)
|
||||||
│ ├── WaveDefs.kt Its settings, 12 factory presets
|
│ └── WaveDefs.kt Its settings, 12 factory presets
|
||||||
│ └── WaveVoice.kt WavePatch + one note: 2 table oscillators, bend, unison, sub, SVF, 2 envelopes, LFO
|
|
||||||
│
|
│
|
||||||
├── echofield/ MIT: the Grain Cloud, ported from ECHOFIELD (see §5.8)
|
├── echofield/ MIT: the Grain Cloud, ported from ECHOFIELD (see §5.8)
|
||||||
│ ├── EchofieldDefs.kt Its settings, 14 factory presets, the source list
|
│ └── EchofieldDefs.kt Its settings, 14 factory presets, the source list
|
||||||
│ └── GrainCloud.kt GrainPatch + one channel's cloud: modes, scheduler, grains, gate, auto-level
|
|
||||||
│
|
│
|
||||||
├── cpp/native_audio.cpp Low-latency Oboe stream; RT callback pulls audio via JNI
|
├── cpp/native_audio.cpp Low-latency Oboe stream; its RT callback renders core/ directly
|
||||||
|
├── cpp/jni_engine.cpp The JNI surface of core/src/host/EngineHost
|
||||||
│
|
│
|
||||||
├── io/ Human-readable text persistence
|
├── io/ Human-readable text persistence
|
||||||
│ ├── PresetIo.kt Instrument/effect preset <-> KEY=VALUE text
|
│ ├── PresetIo.kt Instrument/effect preset <-> KEY=VALUE text
|
||||||
@@ -409,11 +419,17 @@ playback continues. Samples go across as they enter `SampleStore` (`put` /
|
|||||||
`remove` mirror into the native store). Transport, meters, scope and finished
|
`remove` mirror into the native store). Transport, meters, scope and finished
|
||||||
recordings are polled from a 10 ms thread.
|
recordings are polled from a 10 ms thread.
|
||||||
|
|
||||||
The Kotlin engine (`ReferenceEngine` and the voices and effects under `audio/`,
|
The Kotlin engine is now only a reference, and lives in the **test** source set:
|
||||||
`frasil/`, `echofield/`, `wavetable/`) is now only a reference: the
|
`app/src/test/java/.../audio` (`ReferenceEngine`, `SynthVoice`, `SynthPatch`,
|
||||||
`IosGolden*` unit tests render it so the C++ can be checked bit for bit
|
`Effects`, `AmbienceReverb`, `SampleVoice`, `MasterRecorder`), `.../frasil`
|
||||||
(`make -C ios golden core-test`). The UI still uses a few of those Kotlin classes
|
(`FrasilVoice`, `FrasilPatch`), `.../echofield` (`GrainCloud`) and
|
||||||
to draw (wavetable frames, Grain Cloud source peaks, sample decoding).
|
`.../wavetable` (`WaveVoice`). The `IosGolden*` unit tests render it so the C++
|
||||||
|
can be checked bit for bit (`make -C ios golden core-test`). It is **not** in
|
||||||
|
`src/main`, because nothing in the app calls it any more — there it would only be
|
||||||
|
dead code in every APK. What the UI genuinely still needs to *draw* did stay in
|
||||||
|
`src/main`: `wavetable/WaveTables` (table frames), `audio/GrainSources` (source
|
||||||
|
peaks), `audio/SampleStore` + `SoundFontLoader` (sample decoding), and the three
|
||||||
|
`*Defs` files (parameter and preset data, shared with the editors).
|
||||||
|
|
||||||
**Parity rule:** every feature or fix lands in both apps in the same change, with
|
**Parity rule:** every feature or fix lands in both apps in the same change, with
|
||||||
one shared version bump. Engine and DSP work goes into `core/` only.
|
one shared version bump. Engine and DSP work goes into `core/` only.
|
||||||
@@ -429,7 +445,9 @@ ordinary device callback, so it is listed and played like USB gear. Connected
|
|||||||
addresses are remembered (`SettingsStore.bleMidiDevices`) and reopened by
|
addresses are remembered (`SettingsStore.bleMidiDevices`) and reopened by
|
||||||
address at start, without a scan. Permissions: `BLUETOOTH_SCAN`
|
address at start, without a scan. Permissions: `BLUETOOTH_SCAN`
|
||||||
(`neverForLocation`) + `BLUETOOTH_CONNECT` on Android 12+, `ACCESS_FINE_LOCATION`
|
(`neverForLocation`) + `BLUETOOTH_CONNECT` on Android 12+, `ACCESS_FINE_LOCATION`
|
||||||
(and the legacy `BLUETOOTH` / `BLUETOOTH_ADMIN`) on 8-11, asked for when SCAN is
|
with `ACCESS_COARSE_LOCATION` (the platform treats FINE as an upgrade of COARSE
|
||||||
|
and refuses a FINE-only request; `make lint` enforces it) and the legacy
|
||||||
|
`BLUETOOTH` / `BLUETOOTH_ADMIN` on 8-11, asked for when SCAN is
|
||||||
first tapped. The emulator has no usable Bluetooth radio (its Bluetooth service
|
first tapped. The emulator has no usable Bluetooth radio (its Bluetooth service
|
||||||
crashes on a scan); test on a phone.
|
crashes on a scan); test on a phone.
|
||||||
|
|
||||||
@@ -710,14 +728,20 @@ of real time on a desktop JVM.
|
|||||||
### Add a new instrument or effect
|
### Add a new instrument or effect
|
||||||
1. Add an entry to `ToolboxType` (`model/Toolbox.kt`) with its `ParamSpec` list.
|
1. Add an entry to `ToolboxType` (`model/Toolbox.kt`) with its `ParamSpec` list.
|
||||||
2. Teach the engine how to sound it:
|
2. Teach the engine how to sound it:
|
||||||
|
It all happens in `core/` (C++), which is what both apps play — never in the
|
||||||
|
Kotlin reference, which only follows so the golden comparison still holds:
|
||||||
- **Instrument**: handle its type where the engine picks a voice per channel
|
- **Instrument**: handle its type where the engine picks a voice per channel
|
||||||
(see how `NES_SYNTH`, `SAMPLER`, and `SOUNDFONT` are dispatched in
|
(see how `NES_SYNTH`, `SAMPLER` and `SOUNDFONT` are dispatched in
|
||||||
`AudioEngine`).
|
`core/src/engine/Engine.cpp`).
|
||||||
- **Signal effect**: add a processor in `audio/Effects.kt` implementing
|
- **Signal effect**: add a processor under `core/src/fx/` implementing
|
||||||
`AudioEffect` and register it in `AudioEffect.create(...)`; the per-channel
|
`sizzle::Effect` (`core/include/sizzle/Effect.hpp`) and register its maker in
|
||||||
insert chain picks it up automatically.
|
`core/src/fx/Registry.cpp`; the per-channel insert chain picks it up
|
||||||
|
automatically, and so does the AUv3 wrapper once it is in `ios/app/components.txt`.
|
||||||
- **MIDI effect** (arp/transpose/LFO-style): hook into the sequencer instead
|
- **MIDI effect** (arp/transpose/LFO-style): hook into the sequencer instead
|
||||||
of the signal path (see `advanceArps` / `applyLfos` in `AudioEngine`).
|
of the signal path (see `advanceArps` / `applyLfos` in `Engine.cpp`).
|
||||||
|
- **Keep the reference in step**: mirror the change in the Kotlin file under
|
||||||
|
`app/src/test/.../audio` (or `frasil` / `echofield` / `wavetable`), then
|
||||||
|
`make -C ios golden core-test` to check the two sample for sample.
|
||||||
The Toolbox picker, parameter editor, and preset save/load all work automatically
|
The Toolbox picker, parameter editor, and preset save/load all work automatically
|
||||||
from the `ParamSpec` list (the editor then shows one card with every parameter).
|
from the `ParamSpec` list (the editor then shows one card with every parameter).
|
||||||
3. Group its controls: add a case to `DeviceLayouts.pagesFor` (cards, tones,
|
3. Group its controls: add a case to `DeviceLayouts.pagesFor` (cards, tones,
|
||||||
@@ -740,14 +764,25 @@ the Settings theme picker immediately.
|
|||||||
|
|
||||||
## 7. Threading & performance notes
|
## 7. Threading & performance notes
|
||||||
|
|
||||||
- The audio render loop is in `AudioEngine.renderLoop()` on a `MAX_PRIORITY`
|
- The audio render loop is `Engine::fillBlock` in `core/src/engine/Engine.cpp`,
|
||||||
thread. It **must never allocate or block**. Keep it that way.
|
called from the Oboe real-time callback (`src/main/cpp/native_audio.cpp`) — all
|
||||||
|
C++, with no JVM call on the audio thread, so no GC pause can glitch it. It
|
||||||
|
**must never allocate, lock or block**. Keep it that way: the active-voice index
|
||||||
|
lists are rebuilt once per block, per-channel mixer gains and FX-chain pointers
|
||||||
|
are hoisted out of the per-sample loop, and `EngineHost` only ever *try*-locks.
|
||||||
|
(`AudioEngine.startAudioTrack` keeps a Kotlin `MAX_PRIORITY` loop as the
|
||||||
|
fallback when Oboe cannot start; it calls the same `nativeRender`.)
|
||||||
- Timing is derived from *counting audio samples* (`samplesPerLine`), not from
|
- Timing is derived from *counting audio samples* (`samplesPerLine`), not from
|
||||||
timers, so playback never drifts.
|
timers, so playback never drifts.
|
||||||
- UI ⇄ audio sharing is lock-free by design (audio reads plain fields). This can
|
- UI ⇄ audio sharing crosses through text: `ProjectIo.save` plus
|
||||||
produce a one-frame-stale read during a simultaneous edit — harmless for a
|
`EngineHost::syncProjectText`, which diffs and copies only what changed (§5.4.2).
|
||||||
tracker. If you ever add compound state that must be read atomically, publish it
|
`save` is therefore a hot path, not just the file writer — it builds into one
|
||||||
as an immutable snapshot (like `TransportState`) rather than adding locks.
|
pre-sized buffer, and `AudioEngine.requestSync` coalesces a burst of edits
|
||||||
|
(a drag fires one per pointer event) into one sync per `SYNC_COALESCE_MS`.
|
||||||
|
- The transport poller (`AudioEngine.start`) runs at 100 Hz only while the song
|
||||||
|
plays or a take is armed; stopped and idle it waits 100 ms a turn, and any
|
||||||
|
transport call wakes it through a semaphore so the playhead is never late.
|
||||||
|
`AppModel.pollTransport` does the same on iOS (30 Hz playing, 10 Hz idle).
|
||||||
- Block size is `BLOCK_FRAMES = 192` (~4 ms @ 48 kHz). Lower = tighter latency,
|
- Block size is `BLOCK_FRAMES = 192` (~4 ms @ 48 kHz). Lower = tighter latency,
|
||||||
higher = safer against underruns.
|
higher = safer against underruns.
|
||||||
- **UI rendering**: the pattern grid (`PatternGrid`) and arrangement roll
|
- **UI rendering**: the pattern grid (`PatternGrid`) and arrangement roll
|
||||||
@@ -856,11 +891,11 @@ polish and interchange niceties, not functional gaps.
|
|||||||
empty. Voices are a lane×track matrix so lanes layer polyphonically.
|
empty. Voices are a lane×track matrix so lanes layer polyphonically.
|
||||||
- **Per-channel effect DSP** (milestone 3 ✓): each mixer channel runs an insert
|
- **Per-channel effect DSP** (milestone 3 ✓): each mixer channel runs an insert
|
||||||
chain built from its FX slots — Tape Delay, Digital Reverb, Filter (LP/HP/BP),
|
chain built from its FX slots — Tape Delay, Digital Reverb, Filter (LP/HP/BP),
|
||||||
Bitcrusher, and 10-band EQ are real processors in `audio/Effects.kt`. Effect
|
Bitcrusher, and 10-band EQ are real processors in `core/src/fx/`. Effect
|
||||||
parameters update live per audio block; add/remove rebuilds the chain.
|
parameters update live per audio block; add/remove rebuilds the chain.
|
||||||
- **Sampler instrument** ✓: WAV import (SAF file picker) + ad-hoc mic/USB
|
- **Sampler instrument** ✓: WAV import (SAF file picker) + ad-hoc mic/USB
|
||||||
recorder (`audio/SampleRecorder.kt`), decoded to a mono cache
|
recorder (`audio/SampleRecorder.kt`), decoded to a mono cache
|
||||||
(`audio/SampleStore.kt`), played pitched + sliced by `audio/SampleVoice.kt`.
|
(`audio/SampleStore.kt`), played pitched + sliced by `core/src/sampler/SampleVoice.cpp`.
|
||||||
Its editor (`ui/toolbox/SamplerEditor.kt`) shows a waveform with two draggable
|
Its editor (`ui/toolbox/SamplerEditor.kt`) shows a waveform with two draggable
|
||||||
slice markers, start-octave + volume, and a two-octave audition keyboard. Each
|
slice markers, start-octave + volume, and a two-octave audition keyboard. Each
|
||||||
(lane, track) has both a synth and a sample voice; the channel instrument type
|
(lane, track) has both a synth and a sample voice; the channel instrument type
|
||||||
@@ -893,11 +928,16 @@ polish and interchange niceties, not functional gaps.
|
|||||||
(`version`/`bpm`/`sig`, `block`…`endblock` with `roll`/`track`/steps) — covered
|
(`version`/`bpm`/`sig`, `block`…`endblock` with `roll`/`track`/steps) — covered
|
||||||
by passing JVM unit tests in `app/src/test`.
|
by passing JVM unit tests in `app/src/test`.
|
||||||
- Background playback foreground service with Play/Pause/Stop notification.
|
- Background playback foreground service with Play/Pause/Stop notification.
|
||||||
|
- **Full C++ audio port** ✓ (0.37.0): the whole DSP — sequencer, mixer, every
|
||||||
|
instrument and effect, the master recorder — is `core/`, shared with the iOS app
|
||||||
|
and driven over JNI. The Kotlin DSP it replaced lives on in the **test** source
|
||||||
|
set (`app/src/test/.../audio`, `frasil`, `echofield`, `wavetable`) as the
|
||||||
|
reference the C++ is checked against, so none of it ships in the APK.
|
||||||
- **Oboe / AAudio native output** ✓ (default): `src/main/cpp/native_audio.cpp`
|
- **Oboe / AAudio native output** ✓ (default): `src/main/cpp/native_audio.cpp`
|
||||||
opens a low-latency Oboe stream whose real-time callback pulls audio via JNI
|
opens a low-latency Oboe stream whose real-time callback pulls audio via JNI
|
||||||
(`audio/NativeAudioBridge.kt`) from the SAME `AudioEngine.fillBlock` the
|
(`audio/NativeAudioBridge.kt`) from the SAME `Engine::fillBlock` the AudioTrack
|
||||||
AudioTrack loop uses — so both backends produce identical sound, only the
|
fallback loop reaches through `nativeRender` — so both backends produce
|
||||||
delivery path differs. Oboe is the default engine; it falls back to the
|
identical sound, only the delivery path differs. Oboe is the default engine; it falls back to the
|
||||||
AudioTrack loop only if it fails to initialise (or the native lib is absent),
|
AudioTrack loop only if it fails to initialise (or the native lib is absent),
|
||||||
surfacing a popup with the reason (there is no user toggle).
|
surfacing a popup with the reason (there is no user toggle).
|
||||||
Built via **NDK r27** (`ndkVersion` in `app/build.gradle.kts`) + CMake + the
|
Built via **NDK r27** (`ndkVersion` in `app/build.gradle.kts`) + CMake + the
|
||||||
@@ -909,9 +949,9 @@ polish and interchange niceties, not functional gaps.
|
|||||||
`llvm-readelf -l <lib>.so` → LOAD `Align 0x4000`.)
|
`llvm-readelf -l <lib>.so` → LOAD `Align 0x4000`.)
|
||||||
- **SF2 / XI loader instrument** ✓: `audio/SoundFontLoader.kt` extracts PCM from
|
- **SF2 / XI loader instrument** ✓: `audio/SoundFontLoader.kt` extracts PCM from
|
||||||
an `.sf2` / `.xi` into the `SampleStore`, played back through the same
|
an `.sf2` / `.xi` into the `SampleStore`, played back through the same
|
||||||
`SampleVoice` path as the Sampler; edited via `ui/toolbox/SoundFontEditor.kt`
|
`SampleVoice` path in `core/` as the Sampler; edited via `ui/toolbox/SoundFontEditor.kt`
|
||||||
(root note, volume, ADSR).
|
(root note, volume, ADSR).
|
||||||
- **Master recording** ✓: `audio/MasterRecorder.kt` renders the stereo master bus
|
- **Master recording** ✓: `core/src/host/MasterRecorder.cpp` renders the stereo master bus
|
||||||
(plus a configurable FX tail) to a WAV in a user-chosen folder (SAF).
|
(plus a configurable FX tail) to a WAV in a user-chosen folder (SAF).
|
||||||
- **Stereo output & recording** ✓: `fillBlock` renders interleaved stereo and the
|
- **Stereo output & recording** ✓: `fillBlock` renders interleaved stereo and the
|
||||||
recorder captures two channels (voices/inserts are mono, so both channels carry
|
recorder captures two channels (voices/inserts are mono, so both channels carry
|
||||||
@@ -933,11 +973,34 @@ polish and interchange niceties, not functional gaps.
|
|||||||
- **Byte-exact desktop `.sng` compatibility.** `io/SngFormat.kt` reads/writes the
|
- **Byte-exact desktop `.sng` compatibility.** `io/SngFormat.kt` reads/writes the
|
||||||
reference line format and round-trips musically; a field-for-field byte match
|
reference line format and round-trips musically; a field-for-field byte match
|
||||||
with the CLI project layout is the remaining interchange nicety.
|
with the CLI project layout is the remaining interchange nicety.
|
||||||
- **Full C++ audio port.** The DSP currently runs in Kotlin behind the Oboe
|
|
||||||
callback (via JNI). Porting the hot path to C++ would remove JVM/GC from the
|
|
||||||
real-time thread — a performance hardening step, not a functional gap.
|
|
||||||
- **Route the Oboe backend through the chosen output device** (Oboe
|
- **Route the Oboe backend through the chosen output device** (Oboe
|
||||||
`setDeviceId`), matching the AudioTrack path's device selection.
|
`setDeviceId`), matching the AudioTrack path's device selection.
|
||||||
|
- **Block-rate FX processing — measured, and not worth doing.** Insert effects are
|
||||||
|
`process(float)` per sample, so a four-effect chain on four channels is 16
|
||||||
|
virtual calls per frame. That looks like something to fix; `make -C ios bench`
|
||||||
|
says it is not (M4, `-O2`, part C): on a ten-biquad cascade with EQ10's shape,
|
||||||
|
dispatch costs **0.11 ns of 9.13 ns per sample, about 1 %** — the indirect
|
||||||
|
branch is perfectly predicted and amortises over everything the effect does.
|
||||||
|
The obvious block restructuring is a *large regression*: running band-at-a-time
|
||||||
|
over a block, so each band's coefficients stay in registers, measured **+162 %**,
|
||||||
|
because the running value then makes ten round trips through memory per sample
|
||||||
|
instead of staying in one register across the cascade. Nor is there a SIMD win
|
||||||
|
to chase — serial IIR filters are recurrences, so they do not vectorise across
|
||||||
|
samples, and the chains differ per channel. Don't reopen this on intuition;
|
||||||
|
re-run the bench first.
|
||||||
|
|
||||||
|
Where the cost actually is, if FX headroom is ever needed (part B): **Ambience
|
||||||
|
is 52 % of all eight effects put together** (65.9 ns/sample, 3.5× the next, Tape
|
||||||
|
Delay at 19.1) — an 8-line FDN with four diffusers, early reflections, a
|
||||||
|
Walsh-Hadamard feedback mix and a modulated fractional-delay read per line,
|
||||||
|
every sample. A full chain is about 77 % of render time (part A), and
|
||||||
|
three-quarters of that is Ambience. Nothing is urgent: four channels with four
|
||||||
|
effects each still render at **42× real time**.
|
||||||
|
|
||||||
|
One trap for whoever does touch `src/fx/`: only `AmbienceReverb.cpp` carries
|
||||||
|
`#pragma clang fp contract(off)`. Make that explicit across the directory
|
||||||
|
*first*, as its own commit, or a change in multiply-add contraction is
|
||||||
|
indistinguishable from a real bug in the golden comparison.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,33 @@ same features; the Android side of each version is in `../CHANGELOG.md`.
|
|||||||
|
|
||||||
## 0.41.1 (build 77)
|
## 0.41.1 (build 77)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
- Fix: some controls only showed their new state after something else redrew
|
- Fix: some controls only showed their new state after something else redrew
|
||||||
the screen (rotating the iPad): the Mix tab's ● ARM / TAIL / SHARE bar, the
|
the screen (rotating the iPad): the Mix tab's ● ARM / TAIL / SHARE bar, the
|
||||||
Sampler's slice markers, the LFO's target and the audition keyboards. They now
|
Sampler's slice markers, the LFO's target and the audition keyboards. They now
|
||||||
redraw as soon as the song changes. (SwiftUI skipped them because none of their
|
redraw as soon as the song changes. (SwiftUI skipped them because none of their
|
||||||
own inputs changed.)
|
own inputs changed.)
|
||||||
|
=======
|
||||||
|
Housekeeping and speed; nothing you can see changes.
|
||||||
|
|
||||||
|
- **The DSP core is built at `-O2`.** It was `-Os`, which traded the engine's
|
||||||
|
speed for a little binary size in an app that has to hold a 4 ms deadline. The
|
||||||
|
golden tests measure the core at `-O2`, so the build that ships is now the
|
||||||
|
build that was checked.
|
||||||
|
- **The mixer costs less per sample.** Channel volume, mute/solo and the effect
|
||||||
|
chain are read once per audio block rather than once per frame
|
||||||
|
(`core/src/engine/Engine.cpp`, shared with Android). Bit-for-bit the same
|
||||||
|
audio: all 61 reference scenarios still match.
|
||||||
|
- **Less battery while a song is stopped.** The transport display polled the
|
||||||
|
engine 30 times a second whatever was happening; stopped it now ticks 10 times
|
||||||
|
a second, and any transport call — the PLAY button, a gamepad, a MIDI binding —
|
||||||
|
starts the display-rate ticks in the same turn. The tick also stopped hopping
|
||||||
|
through a task per poll, 30 times a second, for a main-thread timer that was
|
||||||
|
already on the main actor.
|
||||||
|
- **Dead code gone.** The golden tests' `TestVoice` wrappers were compiled into
|
||||||
|
the app and the plugin extension although only `golden_test` calls them; they
|
||||||
|
have moved to `core/tests/voices/`. A couple of unused declarations went too.
|
||||||
|
>>>>>>> c1758637df9651f2c6a4ef6296509acb9d774186
|
||||||
|
|
||||||
## 0.41.0 (build 76)
|
## 0.41.0 (build 76)
|
||||||
|
|
||||||
|
|||||||
+18
-3
@@ -11,6 +11,8 @@
|
|||||||
# Android toolchain; runs IosGoldenExport in ../app)
|
# Android toolchain; runs IosGoldenExport in ../app)
|
||||||
# make core-test build the C++ core and compare it with the reference audio
|
# make core-test build the C++ core and compare it with the reference audio
|
||||||
# (TYPES="FILTER EQ10" limits it to some devices)
|
# (TYPES="FILTER EQ10" limits it to some devices)
|
||||||
|
# make bench print what the insert-FX chain and each effect cost (SECONDS=1
|
||||||
|
# for a quick look); asserts nothing, so it is not part of check
|
||||||
# make au-test macOS check of the AUv3 wrapper: every effect through AVAudioEngine
|
# make au-test macOS check of the AUv3 wrapper: every effect through AVAudioEngine
|
||||||
# must match the core, plus parameters, presets and saved state
|
# must match the core, plus parameters, presets and saved state
|
||||||
# make project generate app/Sizzle.xcodeproj (components + XcodeGen)
|
# make project generate app/Sizzle.xcodeproj (components + XcodeGen)
|
||||||
@@ -36,6 +38,10 @@ IPA := dist/$(APP_ID)_$(BUILD_NO).ipa
|
|||||||
# C++ DSP core: reference audio lives in ../core/golden/ (regenerated, not committed).
|
# C++ DSP core: reference audio lives in ../core/golden/ (regenerated, not committed).
|
||||||
CORE_SRC := $(wildcard ../core/src/*.cpp ../core/src/*/*.cpp)
|
CORE_SRC := $(wildcard ../core/src/*.cpp ../core/src/*/*.cpp)
|
||||||
CORE_HDR := $(wildcard ../core/include/sizzle/*.hpp ../core/src/*/*.hpp)
|
CORE_HDR := $(wildcard ../core/include/sizzle/*.hpp ../core/src/*/*.hpp)
|
||||||
|
# The golden tests' TestVoice wrappers. They live under tests/, not src/, so neither
|
||||||
|
# app compiles them: only golden_test calls makeTestVoice.
|
||||||
|
VOICE_SRC := $(wildcard ../core/tests/voices/*.cpp)
|
||||||
|
VOICE_HDR := ../core/tests/voices/TestVoice.hpp
|
||||||
CXX ?= c++
|
CXX ?= c++
|
||||||
CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -I../core/include -I../core/src -I../core/src/fx -lz
|
CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -I../core/include -I../core/src -I../core/src/fx -lz
|
||||||
GOLDEN := ../core/golden
|
GOLDEN := ../core/golden
|
||||||
@@ -62,9 +68,9 @@ golden:
|
|||||||
./gradlew -q :app:testDebugUnitTest --tests '*IosGolden*' --rerun
|
./gradlew -q :app:testDebugUnitTest --tests '*IosGolden*' --rerun
|
||||||
@ls $(GOLDEN)/*.scn | wc -l | xargs echo "reference scenarios:"
|
@ls $(GOLDEN)/*.scn | wc -l | xargs echo "reference scenarios:"
|
||||||
|
|
||||||
build/core/golden_test: $(CORE_SRC) $(CORE_HDR) ../core/tests/golden_test.cpp
|
build/core/golden_test: $(CORE_SRC) $(CORE_HDR) $(VOICE_SRC) $(VOICE_HDR) ../core/tests/golden_test.cpp
|
||||||
mkdir -p build/core
|
mkdir -p build/core
|
||||||
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) ../core/tests/golden_test.cpp
|
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) $(VOICE_SRC) ../core/tests/golden_test.cpp
|
||||||
|
|
||||||
build/core/sampler_test: $(CORE_SRC) $(CORE_HDR) ../core/tests/sampler_test.cpp
|
build/core/sampler_test: $(CORE_SRC) $(CORE_HDR) ../core/tests/sampler_test.cpp
|
||||||
mkdir -p build/core
|
mkdir -p build/core
|
||||||
@@ -94,6 +100,15 @@ build/core/oneshot_test: $(CORE_SRC) $(CORE_HDR) ../core/tests/oneshot_test.cpp
|
|||||||
mkdir -p build/core
|
mkdir -p build/core
|
||||||
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) ../core/tests/oneshot_test.cpp
|
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) ../core/tests/oneshot_test.cpp
|
||||||
|
|
||||||
|
build/core/bench: $(CORE_SRC) $(CORE_HDR) ../core/tests/bench.cpp
|
||||||
|
mkdir -p build/core
|
||||||
|
$(CXX) $(CXXFLAGS) -o $@ $(CORE_SRC) ../core/tests/bench.cpp
|
||||||
|
|
||||||
|
# Not part of core-test: it asserts nothing, it just prints what the DSP costs, and
|
||||||
|
# the numbers only mean something on a quiet machine. SECONDS=1 for a quick look.
|
||||||
|
bench: build/core/bench
|
||||||
|
build/core/bench $(SECONDS)
|
||||||
|
|
||||||
build/core/midi_test: ../core/include/sizzle/Midi.hpp ../core/tests/midi_test.cpp
|
build/core/midi_test: ../core/include/sizzle/Midi.hpp ../core/tests/midi_test.cpp
|
||||||
mkdir -p build/core
|
mkdir -p build/core
|
||||||
$(CXX) $(CXXFLAGS) -o $@ ../core/tests/midi_test.cpp
|
$(CXX) $(CXXFLAGS) -o $@ ../core/tests/midi_test.cpp
|
||||||
@@ -220,4 +235,4 @@ $(SPIKE_IPA): $(SPIKE_PROJ)/project.pbxproj $(SPIKE_SRC)
|
|||||||
clean:
|
clean:
|
||||||
rm -rf build dist
|
rm -rf build dist
|
||||||
|
|
||||||
.PHONY: help golden core-test zip-test au-test project ipa bump-major bump-minor bump-patch bump spike-ipa clean
|
.PHONY: help golden core-test bench zip-test au-test project ipa bump-major bump-minor bump-patch bump spike-ipa clean
|
||||||
|
|||||||
+14
-4
@@ -10,6 +10,8 @@ Makefile (`make -C ios help`).
|
|||||||
| `../core/` | The shared C++ engine (Android plays through it too): a port of the Android app's Kotlin DSP |
|
| `../core/` | The shared C++ engine (Android plays through it too): a port of the Android app's Kotlin DSP |
|
||||||
| `../core/include/sizzle/DeviceSpecs.gen.hpp` | Every device's parameters, generated from `ToolboxType` (Kotlin) |
|
| `../core/include/sizzle/DeviceSpecs.gen.hpp` | Every device's parameters, generated from `ToolboxType` (Kotlin) |
|
||||||
| `../core/tests/golden_test.cpp` | Compares the core with audio the Kotlin code renders |
|
| `../core/tests/golden_test.cpp` | Compares the core with audio the Kotlin code renders |
|
||||||
|
| `../core/tests/voices/` | The `TestVoice` wrappers `golden_test` drives the instruments through. Under `tests/`, not `src/`, so neither app compiles them |
|
||||||
|
| `../core/tests/bench.cpp` | `make bench`: what the FX chain and each effect cost. Asserts nothing, so it is not part of `core-test` |
|
||||||
| `app/components.txt` | The plugin list (AU type, subtype, device, name) |
|
| `app/components.txt` | The plugin list (AU type, subtype, device, name) |
|
||||||
| `app/FX/` | The plugin extension: `SizzleDeviceAU` (shared: parameters, presets, state), `SizzleEffectAU` (aufx), `SizzleInstrumentAU` (aumu), `SizzleFXViewController` (factory + editor). The app compiles the same classes to host them itself |
|
| `app/FX/` | The plugin extension: `SizzleDeviceAU` (shared: parameters, presets, state), `SizzleEffectAU` (aufx), `SizzleInstrumentAU` (aumu), `SizzleFXViewController` (factory + editor). The app compiles the same classes to host them itself |
|
||||||
| `app/Host/SizzleSession*` | The bridge to the C++ song + engine (audio output, song lock, live-note queue); one category per screen |
|
| `app/Host/SizzleSession*` | The bridge to the C++ song + engine (audio output, song lock, live-note queue); one category per screen |
|
||||||
@@ -27,8 +29,11 @@ listed in `CHANGELOG.md` here.
|
|||||||
|
|
||||||
## How the port is verified
|
## How the port is verified
|
||||||
|
|
||||||
The Kotlin DSP is the reference. `make golden` runs `IosGoldenExport` (a JVM unit
|
The Kotlin DSP is the reference. It lives in the Android app's **test** source set
|
||||||
test in the Android app, skipped by the normal `make check`), which:
|
(`../app/src/test/java/.../audio`, `frasil`, `echofield`, `wavetable`) — both apps
|
||||||
|
play `core/`, so it is no longer part of either one. `make golden` runs
|
||||||
|
`IosGoldenExport` (a JVM unit test in the Android app, skipped by the normal
|
||||||
|
`make check`), which:
|
||||||
|
|
||||||
- writes `DeviceSpecs.gen.hpp`, so iOS uses the same parameter definitions
|
- writes `DeviceSpecs.gen.hpp`, so iOS uses the same parameter definitions
|
||||||
(keys, labels, ranges, defaults, choices) and the Mix Tightener presets;
|
(keys, labels, ranges, defaults, choices) and the Mix Tightener presets;
|
||||||
@@ -38,8 +43,13 @@ test in the Android app, skipped by the normal `make check`), which:
|
|||||||
`../core/golden/` (not committed; regenerate any time).
|
`../core/golden/` (not committed; regenerate any time).
|
||||||
|
|
||||||
`make core-test` renders the same scenarios through the C++ core and requires a
|
`make core-test` renders the same scenarios through the C++ core and requires a
|
||||||
largest difference below 1e-4. Today all 25 pass; most are bit-exact, the rest
|
largest difference below 1e-4. Today all 61 pass; most are bit-exact, the rest
|
||||||
differ by about one float ulp. Porting rules that make this possible:
|
differ by about one float ulp. It compiles the core at `-O2` — and so does Xcode
|
||||||
|
(`GCC_OPTIMIZATION_LEVEL: 2` on the `SizzleCore` target in `app/project.yml`, in
|
||||||
|
every configuration), so the build that ships is the build that was measured. An
|
||||||
|
optimisation level is not a free choice here: it decides FP contraction, and the
|
||||||
|
comparison only holds for the level the tests use. Porting rules that make this
|
||||||
|
possible:
|
||||||
|
|
||||||
- translate line for line, keeping Kotlin's types: `Float` → `float`,
|
- translate line for line, keeping Kotlin's types: `Float` → `float`,
|
||||||
`Double` → `double`, so every expression runs in the same precision;
|
`Double` → `double`, so every expression runs in the same precision;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ final class AppModel: ObservableObject {
|
|||||||
@Published private(set) var revision = 0
|
@Published private(set) var revision = 0
|
||||||
@Published var tab: Tab = .tracker
|
@Published var tab: Tab = .tracker
|
||||||
|
|
||||||
// Transport, polled ~30×/s.
|
// Transport, polled 30×/s while playing (see pollTransport).
|
||||||
@Published private(set) var isPlaying = false
|
@Published private(set) var isPlaying = false
|
||||||
@Published private(set) var currentLine = 0
|
@Published private(set) var currentLine = 0
|
||||||
@Published private(set) var currentBeat = 0
|
@Published private(set) var currentBeat = 0
|
||||||
@@ -45,13 +45,34 @@ final class AppModel: ObservableObject {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
observer = NotificationCenter.default.addObserver(forName: .SizzleSessionDidChange, object: nil, queue: .main) { [weak self] _ in
|
observer = NotificationCenter.default.addObserver(forName: .SizzleSessionDidChange, object: nil, queue: .main) { [weak self] _ in
|
||||||
Task { @MainActor in self?.revision += 1 }
|
// SizzleSession's -edit: announces transport calls too, so this is also
|
||||||
}
|
// where the poll rate catches up: however playback was started — the
|
||||||
timer = Timer.scheduledTimer(withTimeInterval: 1.0 / 30, repeats: true) { [weak self] _ in
|
// tracker's PLAY button, a gamepad, a MIDI binding — the display-rate
|
||||||
Task { @MainActor in self?.pollTransport() }
|
// ticks begin in the same turn, not up to a tick later.
|
||||||
|
Task { @MainActor in self?.revision += 1; self?.pollTransport() }
|
||||||
}
|
}
|
||||||
|
// The timer fires on the main run loop, so the body is already on the main
|
||||||
|
// actor: assumeIsolated instead of `Task { @MainActor in … }`, which hopped
|
||||||
|
// through an allocation and a scheduler turn 30 times a second forever.
|
||||||
|
// Ticks while stopped only watch for isPlaying, so they run at 10×/s.
|
||||||
|
startTimer(hz: Self.idleHz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static let playingHz = 30.0
|
||||||
|
private static let idleHz = 10.0
|
||||||
|
|
||||||
|
private func startTimer(hz: Double) {
|
||||||
|
timer?.invalidate()
|
||||||
|
timerHz = hz
|
||||||
|
let t = Timer(timeInterval: 1.0 / hz, repeats: true) { [weak self] _ in
|
||||||
|
MainActor.assumeIsolated { self?.pollTransport() }
|
||||||
|
}
|
||||||
|
RunLoop.main.add(t, forMode: .common)
|
||||||
|
timer = t
|
||||||
|
}
|
||||||
|
|
||||||
|
private var timerHz = 0.0
|
||||||
|
|
||||||
private func pollTransport() {
|
private func pollTransport() {
|
||||||
let playing = session.isPlaying
|
let playing = session.isPlaying
|
||||||
if playing != isPlaying { isPlaying = playing }
|
if playing != isPlaying { isPlaying = playing }
|
||||||
@@ -60,8 +81,19 @@ final class AppModel: ObservableObject {
|
|||||||
if line != currentLine { currentLine = line }
|
if line != currentLine { currentLine = line }
|
||||||
if beat != currentBeat { currentBeat = beat }
|
if beat != currentBeat { currentBeat = beat }
|
||||||
}
|
}
|
||||||
|
// Follow the playhead at display rate; idle at a third of that, which is what
|
||||||
|
// a stopped song needs to notice someone else starting it.
|
||||||
|
let want = playing ? Self.playingHz : Self.idleHz
|
||||||
|
if want != timerHz { startTimer(hz: want) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func playPause() { session.isPlaying ? session.pause() : session.play() }
|
func playPause() {
|
||||||
func stop() { session.stop() }
|
session.isPlaying ? session.pause() : session.play()
|
||||||
|
pollTransport()
|
||||||
|
}
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
session.stop()
|
||||||
|
pollTransport()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,6 @@ final class PluginCheck: ObservableObject {
|
|||||||
.filter { [kAudioUnitType_Effect, kAudioUnitType_MusicDevice].contains($0.audioComponentDescription.componentType) }
|
.filter { [kAudioUnitType_Effect, kAudioUnitType_MusicDevice].contains($0.audioComponentDescription.componentType) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func listInstalled() {
|
|
||||||
let comps = installed()
|
|
||||||
lines = ["Registered plugins (extension): \(comps.count)"] + comps.map { " \($0.name)" }
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() async {
|
func run() async {
|
||||||
running = true
|
running = true
|
||||||
defer { running = false }
|
defer { running = false }
|
||||||
|
|||||||
@@ -113,31 +113,6 @@ struct SetupRow: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An Android settings section not ported yet: its place in the layout, greyed
|
|
||||||
/// out and marked as coming later.
|
|
||||||
struct ComingLaterRow: View {
|
|
||||||
let title: String
|
|
||||||
let subtitle: String
|
|
||||||
let icon: String
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
HStack(spacing: 12) {
|
|
||||||
Image(systemName: icon).font(.system(size: 16)).foregroundColor(Theme.dim).frame(width: 24)
|
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
|
||||||
Text(title).font(.system(size: 15, weight: .medium)).foregroundColor(Theme.dim)
|
|
||||||
Text(subtitle).font(.system(size: 12)).foregroundColor(Theme.dim.opacity(0.75)).lineLimit(2)
|
|
||||||
}
|
|
||||||
Spacer(minLength: 8)
|
|
||||||
Text("Later").font(.system(size: 11)).foregroundColor(Theme.dim)
|
|
||||||
.padding(.horizontal, 8).padding(.vertical, 3)
|
|
||||||
.overlay(Capsule().stroke(Theme.grid, lineWidth: 1))
|
|
||||||
.fixedSize()
|
|
||||||
}
|
|
||||||
.padding(.vertical, 4)
|
|
||||||
.accessibilityElement(children: .combine)
|
|
||||||
.accessibilityHint("Coming in a later version")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The Setup tab's modal dialogs. iOS 15 alerts can't hold a text field, so the
|
/// The Setup tab's modal dialogs. iOS 15 alerts can't hold a text field, so the
|
||||||
/// save prompt (and with it every dialog here, for one look) is drawn in SwiftUI.
|
/// save prompt (and with it every dialog here, for one look) is drawn in SwiftUI.
|
||||||
|
|||||||
+6
-1
@@ -25,7 +25,12 @@ targets:
|
|||||||
settings:
|
settings:
|
||||||
base:
|
base:
|
||||||
PRODUCT_NAME: SizzleCore
|
PRODUCT_NAME: SizzleCore
|
||||||
GCC_OPTIMIZATION_LEVEL: s
|
# -O2 in every configuration, matching ios/Makefile's CXXFLAGS — the one
|
||||||
|
# build of this code the golden tests actually measure. It was -Os, which
|
||||||
|
# trades the DSP's speed for a few hundred KB in an app that has to hold a
|
||||||
|
# 4 ms deadline; and optimising Debug too is deliberate (the Android
|
||||||
|
# CMakeLists does the same), because an -O0 core cannot render in real time.
|
||||||
|
GCC_OPTIMIZATION_LEVEL: 2
|
||||||
SizzleFX:
|
SizzleFX:
|
||||||
type: app-extension
|
type: app-extension
|
||||||
platform: iOS
|
platform: iOS
|
||||||
|
|||||||
Reference in New Issue
Block a user