Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
automix: better last levels and voices for songs without lyrics
kota-zo28b139f5ae36
diff --git a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt b/base/app/src/main/java/com/music/spotui/automix/AutoMix.ktindex fda69395..2b2653f3 100644--- a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt+++ b/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt@@ -126,7 +126,7 @@ object AutoMix {)/** The data-plan transitions (the Mix Lab's test of them), in place of the planner; only for the beat blend style. */- var segue by mutableStateOf(Graph.app.getSharedPreferences(PREFS, 0).getBoolean("automix_segue", false))+ var segue by mutableStateOf(Graph.app.getSharedPreferences(PREFS, 0).getBoolean("automix_segue", app.myspoti.engine.BuildConfig.AUTOMIX_LAB))private setfun changeSegue(value: Boolean) { segue = value; Graph.app.getSharedPreferences(PREFS, 0).edit().putBoolean("automix_segue", value).apply(); com.music.spotui.di.LocalPlayer.autoMixSettingsChanged() }val segueActive: Boolean get() = app.myspoti.engine.BuildConfig.AUTOMIX_LAB && segue && style == 0diff --git a/base/app/src/main/java/com/music/spotui/automix/DeckEq.kt b/base/app/src/main/java/com/music/spotui/automix/DeckEq.ktindex 9da87fc8..dd3ec507 100644--- a/base/app/src/main/java/com/music/spotui/automix/DeckEq.kt+++ b/base/app/src/main/java/com/music/spotui/automix/DeckEq.kt@@ -45,7 +45,7 @@ class DeckEq private constructor(private val dp: DynamicsProcessing) {dp.enabled = trueDeckEq(dp)} catch (e: Throwable) {- AutoMix.journal("EQ unavailable on session $sessionId: ${e.javaClass.simpleName}")+ AutoMix.journal("EQ unavailable on session $sessionId: ${e.javaClass.simpleName}: ${e.message}")null}}diff --git a/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt b/base/app/src/main/java/com/music/spotui/di/LocalPlayer.ktindex c0483bca..e48a4019 100644--- a/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt+++ b/base/app/src/main/java/com/music/spotui/di/LocalPlayer.kt@@ -754,13 +754,22 @@ object LocalPlayer {return false}+ /**+ * A plan's speed as player parameters. Keeping the pitch costs artefacts on music; a change this small+ * is below what is heard as out of tune, so it goes by resampling alone.+ */+ private fun mixParameters(plan: app.myspoti.automix.MixPlan, speed: Float): androidx.media3.common.PlaybackParameters {+ val tiny = plan.segue != null && kotlin.math.abs(plan.speedB - 1) <= 0.01+ return if (tiny) androidx.media3.common.PlaybackParameters(speed, speed / rate()) else androidx.media3.common.PlaybackParameters(speed)+ }+/** [analysis] with its voices from the song's timed lyrics, when they are already here. On the plan's thread. */private fun sung(t: LocalTrack, analysis: app.myspoti.automix.TrackAnalysis): app.myspoti.automix.TrackAnalysis {- val lyrics = com.music.spotui.data.api.LyricsApi.known(com.music.spotui.data.api.LyricsApi.Track(spotifyId(t), t.title, t.artist, t.album, t.durationMs)) ?: return analysis+ val lyrics = com.music.spotui.data.api.LyricsApi.known(com.music.spotui.data.api.LyricsApi.Track(spotifyId(t), t.title, t.artist, t.album, t.durationMs)) ?: return analysis.withLearnedVoices()val lines = lyrics.lines.map { l ->app.myspoti.automix.SungSpans.Line(l.timeMs, l.words?.lastOrNull()?.endMs?.takeIf { it > 0 }, l.text.isNotBlank())}- return app.myspoti.automix.SungSpans.of(lines, analysis.duration)?.let(analysis::withSung) ?: analysis+ return app.myspoti.automix.SungSpans.of(lines, analysis.duration)?.let(analysis::withSung) ?: analysis.withLearnedVoices()}/** The plan for two analysed songs, once [segueDecided]. With the data plans on, null means the policy chose plain playback. */@@ -819,7 +828,7 @@ object LocalPlayer {run.plan = planplan.segue?.let { s -> run.eq?.neutral(); segueStages[run.deck]?.arm(s, app.myspoti.automix.segue.LaneSide.INCOMING) }run.startMs = (plan.entryB * 1000 - minOf(plan.entryB * 1000, RUN_UP_MS * plan.speedB)).toLong().coerceAtLeast(0L)- run.deck.playbackParameters = androidx.media3.common.PlaybackParameters((plan.speedB * rate()).toFloat())+ run.deck.playbackParameters = mixParameters(plan, (plan.speedB * rate()).toFloat())run.lastSpeed = run.deck.playbackParameters.speedrun.deck.seekTo(run.startMs)run.state = if (run.deck.playbackState == Player.STATE_READY) MixState.READY else MixState.PREPARING@@ -887,7 +896,7 @@ object LocalPlayer {val deck = build(false, deck = true)deck.volume = 0fdeck.skipSilenceEnabled = false- deck.playbackParameters = androidx.media3.common.PlaybackParameters((plan.speedB * rate()).toFloat())+ deck.playbackParameters = mixParameters(plan, (plan.speedB * rate()).toFloat())val runUpB = minOf(plan.entryB * 1000, (if (skip) SKIP_RUN_UP_MS else RUN_UP_MS) * plan.speedB)val start = (plan.entryB * 1000 - runUpB).toLong().coerceAtLeast(0L)// A data plan's lanes play in the audio chain, on no effect of the player's session.@@ -974,7 +983,7 @@ object LocalPlayer {if (run.lastTickAt > 0 && run.lastSpeed > 0) run.corrected += (run.lastSpeed / base - 1) * (android.os.SystemClock.uptimeMillis() - run.lastTickAt) * plan.speedBrun.lastTickAt = android.os.SystemClock.uptimeMillis()if (kotlin.math.abs(speed - run.lastSpeed) > 0.0005f) {- d.playbackParameters = androidx.media3.common.PlaybackParameters(speed)+ d.playbackParameters = mixParameters(run.plan, speed)run.lastSpeed = speed}// Once a second in the journal: how far the deck is from its place.@@ -1090,7 +1099,7 @@ object LocalPlayer {run.eq?.set(0.0, 0.0)d.volume = plan.gainAfter(tB).toFloat()val speed = (plan.speedAfter(tB) * rate()).toFloat()- if (kotlin.math.abs(speed - run.lastSpeed) > 0.0005f) { d.playbackParameters = androidx.media3.common.PlaybackParameters(speed); run.lastSpeed = speed }+ if (kotlin.math.abs(speed - run.lastSpeed) > 0.0005f) { d.playbackParameters = mixParameters(run.plan, speed); run.lastSpeed = speed }if (plan.speedAfter(tB) == 1.0 && plan.gainAfter(tB) >= 0.999) {mix = nulld.volume = 1fdiff --git a/base/automix/src/main/kotlin/app/myspoti/automix/TrackAnalysis.kt b/base/automix/src/main/kotlin/app/myspoti/automix/TrackAnalysis.ktindex 788dbc03..82a3b61f 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/TrackAnalysis.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/TrackAnalysis.kt@@ -72,6 +72,12 @@ class TrackAnalysis() {val bars get() = barStarts.size+ /** This analysis with its voices judged by [VocalRisk.learned], for a song without timed lyrics. Kept out of the stored analysis so no song is analysed again. */+ fun withLearnedVoices(): TrackAnalysis = TrackAnalysis(duration, contentStart, contentEnd, loudnessDb, key, keyStrength, bpm, steady, head, tail, beats, barStarts,+ barDb, barLowDb, barHighDb, barCentre, barNovelty, phraseOffset, stereo, headDown, tailDown, note,+ VocalRisk.learned(barVocalRisk, barDb, barLowDb, barHighDb, barCentre, barNovelty), audioKey, barBassDb,+ headPhase, tailPhase, headMetre, tailMetre, modelBeats, barDownConfidence)+/** This analysis with its voices taken from [spans], seconds from the song's start where it is known to be sung. */fun withSung(spans: List<Pair<Double, Double>>): TrackAnalysis {val sorted = spans.filter { it.second > it.first }.sortedBy { it.first }diff --git a/base/automix/src/main/kotlin/app/myspoti/automix/VocalRisk.kt b/base/automix/src/main/kotlin/app/myspoti/automix/VocalRisk.ktindex 47a18b45..d0be6f07 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/VocalRisk.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/VocalRisk.kt@@ -1,6 +1,7 @@/* SPDX-License-Identifier: GPL-3.0-only */package app.myspoti.automix+import kotlin.math.expimport kotlin.math.max/**@@ -23,4 +24,35 @@ internal object VocalRisk {}(risk * active).coerceIn(0f, 1f)}++ /**+ * A logistic model over the bar measurements, each but the first against the song's own median.+ * Fitted on bars labelled from timed lyrics over a corpus of mostly rap and pop, and checked on+ * songs left out (ranking 0.86, against 0.71 for [estimate] alone). The result is scaled so that+ * [VOICE_LINE], where the policy calls a bar sung, sits where the model is right about 94 % of the+ * time and still finds about 90 % of the sung bars.+ */+ fun learned(risk: FloatArray, level: FloatArray, low: FloatArray, high: FloatArray, centre: FloatArray, novelty: FloatArray): FloatArray {+ val medLevel = median(level); val medLow = median(low); val medHigh = median(high); val medCentre = median(centre); val medNovelty = median(novelty)+ return FloatArray(risk.size) { i ->+ val x = W_RISK * risk[i] + W_LEVEL * (level[i] - medLevel) + W_LOW * (low.at(i) - medLow) + W_HIGH * (high.at(i) - medHigh) ++ W_CENTRE * (centre.at(i) - medCentre) + W_NOVELTY * (novelty.at(i) - medNovelty) + W_ABSOLUTE * level[i] + W_BIAS+ val p = 1.0 / (1.0 + exp(-x))+ (if (p < P_AT_LINE) p / P_AT_LINE * VOICE_LINE else VOICE_LINE + (p - P_AT_LINE) / (1 - P_AT_LINE) * (1 - VOICE_LINE)).toFloat()+ }+ }++ private fun FloatArray.at(i: Int) = getOrElse(i) { 0f }+ private fun median(x: FloatArray): Float = if (x.isEmpty()) 0f else x.sortedArray()[x.size / 2]++ private const val VOICE_LINE = 0.6+ private const val P_AT_LINE = 0.8+ private const val W_RISK = 1.92184+ private const val W_LEVEL = -0.10513+ private const val W_LOW = -0.01616+ private const val W_HIGH = 0.10098+ private const val W_CENTRE = 0.07179+ private const val W_NOVELTY = -0.09322+ private const val W_ABSOLUTE = 0.20900+ private const val W_BIAS = 2.55669}diff --git a/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueCompiler.kt b/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueCompiler.ktindex 3ac0e195..4325818c 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueCompiler.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueCompiler.kt@@ -55,13 +55,13 @@ internal class SegueCompiler(private val t: SegueTuning) {private fun smooth(x: Double): Double { val u = x.coerceIn(0.0, 1.0); return u * u * (3 - 2 * u) }/** Both level lanes from gains, with the summed squared gains bounded by one. */- private fun levels(positions: List<Double>, gains: (Double) -> Pair<Double, Double>): List<SeguePlan.Lane> {+ private fun levels(positions: List<Double>, reserve: (Double) -> Double = { 0.0 }, gains: (Double) -> Pair<Double, Double>): List<SeguePlan.Lane> {val a = ArrayList<SeguePlan.Knot>(); val b = ArrayList<SeguePlan.Knot>()for (x in positions.distinct().sorted()) {val (ga, gb) = gains(x)val power = ga * ga + gb * gb// Equal power for songs that do not add up, a bound on the sum for the peaks that do: two loud masters land on one beat.- val scale = min(if (power > 1) 1 / sqrt(power) else 1.0, if (ga + gb > t.overlapMaxSum) t.overlapMaxSum / (ga + gb) else 1.0)+ val scale = min(if (power > 1) 1 / sqrt(power) else 1.0, if (ga + gb + reserve(x) > t.overlapMaxSum) t.overlapMaxSum / (ga + gb + reserve(x)) else 1.0)a += knot(x, db(ga * scale)); b += knot(x, db(gb * scale))}return listOf(lane(LaneSide.OUTGOING, Target.LEVEL, a), lane(LaneSide.INCOMING, Target.LEVEL, b))@@ -115,7 +115,9 @@ internal class SegueCompiler(private val t: SegueTuning) {val closed = (1 - beatShare).coerceAtLeast(swap + 0.01)val opens = (closed - 2 * beatShare).coerceAtLeast(swap)val closes = (closed + beatShare).coerceAtMost(1.0)- val out = ArrayList(levels(positions(swap, opens, closed)) { x ->+ // The incoming song makes room for the repeats: a send adds to the sum and no fader can take it back.+ val send = { x: Double -> if (x < opens || x > closes) 0.0 else t.echoSend * (if (x < closed) (x - opens) / (closed - opens) else (closes - x) / (closes - closed)) }+ val out = ArrayList(levels(positions(swap, opens, closed, closes), send) { x ->val after = ((x - swap) / (closed - swap)).coerceIn(0.0, 1.0)val ga = if (x < swap) 1.0 else cos(PI / 2 * after)val gb = if (x < swap) t.incomingBedGain * sin(PI / 2 * (x / swap)) else t.incomingBedGain + (1 - t.incomingBedGain) * ((x - swap) / (1 - swap)).coerceIn(0.0, 1.0)@@ -226,7 +228,8 @@ internal class SegueCompiler(private val t: SegueTuning) {/** The outgoing song loses its low end, then its level, into a room; the incoming one takes the bass at the swap. */private fun washOut(swap: Double, beatShare: Double, matchA: Double, matchB: Double): List<SeguePlan.Lane> {val from = swap * 0.5- val out = ArrayList(levels(positions(swap)) { x ->+ val wet = { x: Double -> if (x < from) 0.0 else t.roomWetShare * t.roomSend * (if (x < 0.9) (x - from) / (0.9 - from) else (1 - x) / 0.1) }+ val out = ArrayList(levels(positions(swap, from), wet) { x ->val ga = cos(PI / 2 * ((x - swap) / (1 - swap)).coerceIn(0.0, 1.0))val gb = sin(PI / 2 * (x / swap).coerceIn(0.0, 1.0))matched(x, swap, matchA, matchB, ga, gb)diff --git a/base/automix/src/main/kotlin/app/myspoti/automix/segue/SeguePolicy.kt b/base/automix/src/main/kotlin/app/myspoti/automix/segue/SeguePolicy.ktindex 30bc89f8..d641a014 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/segue/SeguePolicy.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/segue/SeguePolicy.kt@@ -413,7 +413,9 @@ object SeguePolicy {val tally = Tally()var best: Found? = nullfor (lengthUs in fadeLengths(lengths)) {- val outs = exits(a.barStarts.asSequence(), lengthUs, us(a.contentEnd), phrases = false)+ // A fade need not start on a bar: the one that ends with the music keeps the most of the song.+ val ending = if (a.bars > 0) sequenceOf((us(a.contentEnd) - lengthUs) / 1e6) else emptySequence()+ val outs = exits(a.barStarts.asSequence() + ending, lengthUs, us(a.contentEnd), phrases = false)val ins = entries(gb, lengthUs, phrases = false)for (e in outs) for (n in ins) {tally.seen++@@ -448,7 +450,11 @@ object SeguePolicy {val lanes = compiler.hard()val plan = plan(e.us, n.us, ga, gb, SegueFormat.RATE_NOMINAL, t.microFadeUs, null, PulseState.LOOSE, us60(ga), residual, lanes)val score = score(e, n, t.microFadeUs, t.microFadeUs, null, 0, lanes)- if (best == null || score.total > best.score) best = Found(plan, score.total, 0.0)+ val lost = skipped(e, n, t.microFadeUs)+ // A cut that gives up this much of the songs is worse than a short fade over a voice.+ if (lost * t.lostFullUs > t.hardLostMaxUs) continue+ val pick = score.total - t.lostPickFade * lost+ if (best == null || pick > best.pick) best = Found(plan, score.total, 0.0, pick = pick)}return settle(level, tally, best, t.thresholdHard)}@@ -457,6 +463,8 @@ object SeguePolicy {private fun simple(level: SegueLevel): Found? {val endUs = min(us(sa.musicEnd), us(a.contentEnd))val lengthUs = min(t.simpleFadeUs, endUs - r.earliestExitUs)+ // Over a voice it stays short, at the very end, and is allowed: that is what a crossfade is.+ val short = min(lengthUs, t.simpleVoiceFadeUs)if (lengthUs <= 0 || us(b.contentEnd) - us(b.contentStart) < lengthUs) return fail(level, SegueCause.NO_CANDIDATE)val targetUs = max(r.earliestExitUs, endUs - lengthUs)val bar = a.barStarts.lastOrNull { us(it) in r.earliestExitUs..targetUs && targetUs - us(it) <= t.simpleFadeUs }@@ -465,7 +473,13 @@ object SeguePolicy {val e = Point(exitUs, a.barAt(exitUs / 1e6 + 0.05), 1.0, true)val n = Point(us(entryTime), b.barAt(entryTime + 0.05), 1.0, true)val tally = Tally().also { it.seen = 1 }- if (tally.refused(SegueGuards.crossed(SegueClass.FADE, measures(e, n, lengthUs, lengthUs), t))) return settle(level, tally, null, 0.0)+ if (tally.refused(SegueGuards.crossed(SegueClass.FADE, measures(e, n, lengthUs, lengthUs), t))) {+ if (short <= 0) return settle(level, tally, null, 0.0)+ val late = max(r.earliestExitUs, endUs - short)+ val m = measures(Point(late, a.barAt(late / 1e6 + 0.05), 1.0, false), n, short, short)+ if (SegueGuards.crossed(SegueClass.FADE, m.copy(voiceOverlapUs = 0), t).isNotEmpty()) return settle(level, tally, null, 0.0)+ return Found(plan(late, n.us, ga, gb, SegueFormat.RATE_NOMINAL, short, null, PulseState.FREE, null, null, compiler.fade()), 0.0, 0.5)+ }return Found(plan(exitUs, n.us, ga, gb, SegueFormat.RATE_NOMINAL, lengthUs, null, PulseState.FREE, null, null, compiler.fade()), 0.0, 0.5)}diff --git a/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueTuning.kt b/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueTuning.ktindex 4a0c611c..a39b32cf 100644--- a/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueTuning.kt+++ b/base/automix/src/main/kotlin/app/myspoti/automix/segue/SegueTuning.kt@@ -55,6 +55,10 @@ data class SegueTuning(val lostFullUs: Long = 20_000_000,val lostPickLocked: Double = 0.4,val lostPickFade: Double = 1.0,+ /** A cut skipping more than this, both songs together, is left to the short fade [I]. */+ val hardLostMaxUs: Long = 12_000_000,+ /** The last resort over a voice: a fade this short at the very end [I]. */+ val simpleVoiceFadeUs: Long = 2_500_000,val penaltySobriety: Double = 0.2,// ── Shapes of the score's terms ──@@ -143,6 +147,8 @@ data class SegueTuning(/** Send levels at their height [I]: echo, room. */val echoSend: Double = 0.5,val roomSend: Double = 1.5,+ /** How much of a room send comes back out at its loudest, against the fader's bound [M]. */+ val roomWetShare: Double = 0.25,/** Where in a fade the outgoing song is thrown into the echo [I]: late, so the repeats have the end of the window to themselves. */val echoThrowShare: Double = 0.72,/** An echo's delay stays between these [I]: shorter is a flam, longer loses the pulse. */diff --git a/base/automix/src/test/kotlin/app/myspoti/automix/SungSpansTest.kt b/base/automix/src/test/kotlin/app/myspoti/automix/SungSpansTest.ktindex 8cfded85..620d3dd8 100644--- a/base/automix/src/test/kotlin/app/myspoti/automix/SungSpansTest.kt+++ b/base/automix/src/test/kotlin/app/myspoti/automix/SungSpansTest.kt@@ -31,6 +31,15 @@ class SungSpansTest {assertEquals(6, spans.size)}+ @Test fun theLearnedVoicesStayARiskAndFollowTheVoiceBand() {+ val quiet = FloatArray(8) { -30f }; val zero = FloatArray(8)+ val risk = FloatArray(8) { if (it < 4) 0.9f else 0f }+ val out = VocalRisk.learned(risk, quiet, quiet, quiet, zero, zero)+ assertEquals(8, out.size)+ out.forEach { assert(it in 0f..1f) }+ assert(out[0] > out[7])+ }+@Test fun tooFewLinesOrLinesPastTheEndAreNotTrusted() {assertNull(SungSpans.of(five.take(4), 180.0))assertNull(SungSpans.of(five + line(200_000), 180.0))diff --git a/base/automix/src/test/kotlin/app/myspoti/automix/segue/SegueBench.kt b/base/automix/src/test/kotlin/app/myspoti/automix/segue/SegueBench.ktindex ed9b98d2..d26045a3 100644--- a/base/automix/src/test/kotlin/app/myspoti/automix/segue/SegueBench.kt+++ b/base/automix/src/test/kotlin/app/myspoti/automix/segue/SegueBench.kt@@ -61,7 +61,7 @@ object SegueBench {private var sung = falseprivate fun analysis(dir: File, name: String, fresh: Boolean = false): TrackAnalysis {- val a = BenchCache.analysis(dir, name, fresh).analysis+ val a = BenchCache.analysis(dir, name, fresh).analysis.withLearnedVoices()val spans = File(dir, "sung/$name.tsv").takeIf { sung && it.exists() } ?: return areturn a.withSung(spans.readLines().filter { it.isNotBlank() }.map { l -> l.split('\t').let { it[0].toDouble() to it[1].toDouble() } })}@@ -129,7 +129,8 @@ object SegueBench {private fun voices(dir: File, fold: String?) {val names = names(dir, fold)for ((name, s) in analyses(dir, names, false)) for (i in 0 until s.bars)- println(String.format(L, "%s\t%.3f\t%.3f\t%.3f", name, s.barStarts[i], s.barEnd(i), s.barVocalRisk.getOrElse(i) { 0f }))+ println(String.format(L, "%s\t%.3f\t%.3f\t%.3f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f", name, s.barStarts[i], s.barEnd(i), s.barVocalRisk.getOrElse(i) { 0f },+ s.barDb[i], s.barLowDb[i], s.barHighDb[i], s.barCentre[i], s.barNovelty[i]))}/** Each song's tempo as the grid has it, at both ends. */diff --git a/base/automix/src/test/kotlin/app/myspoti/automix/segue/SeguePolicyTest.kt b/base/automix/src/test/kotlin/app/myspoti/automix/segue/SeguePolicyTest.ktindex 17467d29..a6aa9aeb 100644--- a/base/automix/src/test/kotlin/app/myspoti/automix/segue/SeguePolicyTest.kt+++ b/base/automix/src/test/kotlin/app/myspoti/automix/segue/SeguePolicyTest.kt@@ -164,7 +164,7 @@ class SeguePolicyTest {}@Test fun level5HardWhenAnyOverlapWouldHaveTwoVoices() {- val d = decide(song("a", risk = { 1f }), song("b", risk = { 1f }))+ val d = decide(song("a", risk = { 1f }), song("b", risk = { 1f }), tuning = SegueTuning(hardLostMaxUs = 60_000_000))assertEquals(d.why, SegueLevel.HARD, d.level)assertCause(d, SegueLevel.FILTERED, SegueCause.GUARDS)val p = d.plan!!@@ -173,6 +173,14 @@ class SeguePolicyTest {assertEquals(2, p.lanes.size)}+ @Test fun aCutThatSkipsTooMuchLeavesItToAShortFadeAtTheEnd() {+ val d = decide(song("a", risk = { 1f }), song("b", risk = { 1f }))+ assertEquals(d.why, SegueLevel.SIMPLE_FADE, d.level)+ val p = d.plan!!+ assertEquals(t.simpleVoiceFadeUs, p.span.lengthUs)+ assertEquals(240_000_000 - t.simpleVoiceFadeUs, p.outgoing.anchorUs)+ }+@Test fun hardNeedsCloseLoudness() {val d = decide(song("a", risk = { 1f }, barDb = -10f), song("b", risk = { 1f }, barDb = -20f))assertCause(d, SegueLevel.HARD, SegueCause.GUARDS)@@ -312,7 +320,7 @@ class SeguePolicyTest {assertEquals(120.0 / 118.0, m.speedB, 1e-6)assertTrue(m.restoreSec > 0)assertEquals(p, m.segue)- assertEquals(MixPlan.Style.CUT, SeguePolicy.timing(decide(song("a", risk = { 1f }), song("b", risk = { 1f })))!!.style)+ assertEquals(MixPlan.Style.CUT, SeguePolicy.timing(decide(song("a", risk = { 1f }), song("b", risk = { 1f }), tuning = SegueTuning(hardLostMaxUs = 60_000_000)))!!.style)val filtered = SeguePolicy.timing(decide(song("a"), song("b", bpm = 100.0)))!!assertEquals(MixPlan.Style.FADE, filtered.style); assertTrue(filtered.filtered)}diff --git a/docs/automix/segue-design.md b/docs/automix/segue-design.mdindex 35881a4b..887c8e5f 100644--- a/docs/automix/segue-design.md+++ b/docs/automix/segue-design.md@@ -305,3 +305,13 @@ The level a pair reaches is still judged on `score`, but the candidate within a## Voices from lyricsThe spectral estimate in `barVocalRisk` mostly sees that a bar could hold a voice: on the bench corpus, checked against the songs' timed lyrics, it finds about a third of the sung bars at the threshold the policy uses, and lowering the threshold only approaches "every bar". When a song's timed lyrics are already on the device, `withSung` replaces it for that decision and nothing is fetched for it. On the corpus, with both songs' lyrics known, locked mixes where two voices meet for over 2 s fall from 53 % to under 1 %, windows get shorter by themselves, and the share of pairs reaching a locked level goes from 25 % to 19 %: these are the mixes that could not avoid a clash. The numbers are not an independent test, since the lyrics that judge are also the ones used, and a song without lyrics gets the estimate as before. The journal says which was used.++A song without lyrics gets `VocalRisk.learned` instead of the raw estimate: a small logistic model over the bar measurements, fitted on bars labelled from timed lyrics and checked on songs left out, where it ranks bars at 0.86 against 0.71. Judged on the corpus's lyrics with no lyrics given to the policy, locked mixes where voices meet for over 2 s fall from 53 % to 17 %, and fewer pairs lock. The weights come from the same corpus, mostly rap and pop, so a very different catalogue may do worse; the worst this does is a shorter, plainer transition.++## The last levels++A cut that skips more than `hardLostMaxUs` of music, both songs together, is refused: a short fade costs less. `SIMPLE_FADE` stays at its usual length when it can; over a voice it is `simpleVoiceFadeUs` at the very end, without the voice guard. Nothing falls to plain playback any more on the bench corpus. A fade's candidates include one that ends with the music, not on a bar.++## Small speed changes++Keeping the pitch while changing speed costs artefacts on music. A plan within 1 % goes by resampling alone (`mixParameters`), which moves the pitch by under 17 cents until it returns to the song's own speed.