Even volume: a gentle leveller on programme sound, off / overnight / always (off by default)
Android's dynamics processor on the player's own sound session: quiet parts lifted a little, loud parts held back, a limiter on top. Overnight is 23:00-07:00 and starts and stops by itself. Off until Paul has listened to it; set from adb (orbit_even_volume off|overnight|always). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -322,6 +322,18 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
|
||||
}
|
||||
}
|
||||
DisposableEffect(player) { onDispose { watchAudioClock(false) } }
|
||||
// Even volume (9 November 2026; off unless switched on): checked each minute, so "overnight" starts and stops by itself.
|
||||
LaunchedEffect(player) {
|
||||
var leveller: android.media.audiofx.DynamicsProcessing? = null
|
||||
try {
|
||||
while (true) {
|
||||
val want = EvenVolume.activeNow()
|
||||
if (want && leveller == null && player.audioSessionId != C.AUDIO_SESSION_ID_UNSET) leveller = EvenVolume.attach(player.audioSessionId)?.also { it.enabled = true }
|
||||
leveller?.enabled = want
|
||||
delay(60_000)
|
||||
}
|
||||
} finally { runCatching { leveller?.release() } }
|
||||
}
|
||||
// Frame-rate matching (9 November 2026; off unless switched on): the TV's refresh follows the programme's, and goes
|
||||
// back to the TV's own choice when the programme closes. Full screen is a dialog window over the activity, so the
|
||||
// preference is set on both: Android takes it from the window on top.
|
||||
|
||||
@@ -72,6 +72,7 @@ class MainActivity : ComponentActivity() {
|
||||
when (intent?.getStringExtra("orbit_provider_catalogue")) { "on" -> ProviderSwitches.setCatalogue(this, true); "off" -> ProviderSwitches.setCatalogue(this, false) }
|
||||
// Player improvements (9 November 2026): frame-rate matching and AVI, each off until switched on.
|
||||
when (intent?.getStringExtra("orbit_frame_rate")) { "on" -> PlayerSwitches.setFrameRate(this, true); "off" -> PlayerSwitches.setFrameRate(this, false) }
|
||||
intent?.getStringExtra("orbit_even_volume")?.let { PlayerSwitches.setEvenVolume(this, it) }
|
||||
when (intent?.getStringExtra("orbit_avi")) { "on" -> PlayerSwitches.setAvi(this, true); "off" -> PlayerSwitches.setAvi(this, false) }
|
||||
if (intent?.getBooleanExtra("orbit_shadow_catalogue_stop", false) == true) CatalogueShadow.cancel = true
|
||||
if (intent?.hasExtra("orbit_shadow_from") == true) CatalogueShadow.from = intent.getLongExtra("orbit_shadow_from", 0L).coerceAtLeast(0L)
|
||||
|
||||
@@ -16,10 +16,17 @@ import kotlin.math.roundToInt
|
||||
internal object PlayerSwitches {
|
||||
@Volatile var frameRate = false
|
||||
@Volatile var avi = false
|
||||
/** Even volume (9 November 2026): "off", "overnight" (23:00 to 07:00) or "always". Off until Paul has listened to it. */
|
||||
@Volatile var evenVolume = "off"
|
||||
private const val FRAME_RATE = "player_frame_rate"
|
||||
private const val AVI = "player_avi"
|
||||
private const val EVEN_VOLUME = "player_even_volume"
|
||||
private fun prefs(context: Context) = context.getSharedPreferences("orbit_settings", Context.MODE_PRIVATE)
|
||||
fun load(context: Context) { prefs(context).let { frameRate = it.getBoolean(FRAME_RATE, false); avi = it.getBoolean(AVI, false) } }
|
||||
fun load(context: Context) { prefs(context).let { frameRate = it.getBoolean(FRAME_RATE, false); avi = it.getBoolean(AVI, false); evenVolume = it.getString(EVEN_VOLUME, "off") ?: "off" } }
|
||||
fun setEvenVolume(context: Context, mode: String) {
|
||||
if (mode !in setOf("off", "overnight", "always")) return
|
||||
evenVolume = mode; prefs(context).edit().putString(EVEN_VOLUME, mode).apply(); android.util.Log.i("OrbitPlayer", "evenVolume switch=$mode")
|
||||
}
|
||||
fun setFrameRate(context: Context, on: Boolean) { frameRate = on; prefs(context).edit().putBoolean(FRAME_RATE, on).apply(); log("frameRate", on) }
|
||||
fun setAvi(context: Context, on: Boolean) { avi = on; prefs(context).edit().putBoolean(AVI, on).apply(); log("avi", on) }
|
||||
private fun log(name: String, on: Boolean) = android.util.Log.i("OrbitPlayer", "$name switch=${if (on) "on" else "off"}")
|
||||
@@ -96,3 +103,26 @@ internal class FrameRateProbe(private val onRate: (Float) -> Unit) : androidx.me
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Even volume (9 November 2026): a gentle leveller on the programme's sound, so a loud film after a quiet cartoon, or
|
||||
* explosions after whispers, don't make you reach for the remote. Android's own dynamics processor on the player's
|
||||
* sound: quiet parts lifted a little, loud parts held back, and a limiter at the top. Stereo and decoded sound only;
|
||||
* sound sent straight to a soundbar is left alone. Nothing changes when it's off.
|
||||
*/
|
||||
internal object EvenVolume {
|
||||
fun activeAt(mode: String, hour: Int) = mode == "always" || (mode == "overnight" && (hour >= 23 || hour < 7))
|
||||
fun activeNow(mode: String = PlayerSwitches.evenVolume) = activeAt(mode, java.util.Calendar.getInstance().get(java.util.Calendar.HOUR_OF_DAY))
|
||||
|
||||
/** The leveller for a player's sound session, or null where the TV doesn't offer it. */
|
||||
fun attach(audioSessionId: Int): android.media.audiofx.DynamicsProcessing? = if (android.os.Build.VERSION.SDK_INT < 28) null else runCatching {
|
||||
val config = android.media.audiofx.DynamicsProcessing.Config.Builder(android.media.audiofx.DynamicsProcessing.VARIANT_FAVOR_FREQUENCY_RESOLUTION,
|
||||
2, false, 0, true, 1, false, 0, true).build()
|
||||
for (ch in 0 until 2) {
|
||||
config.setMbcBandByChannelIndex(ch, 0, android.media.audiofx.DynamicsProcessing.MbcBand(true, 20_000f,
|
||||
10f, 300f, 3f, -30f, 0f, -90f, 1f, 0f, 6f))
|
||||
config.setLimiterByChannelIndex(ch, android.media.audiofx.DynamicsProcessing.Limiter(true, true, 0, 1f, 60f, 10f, -2f, 0f))
|
||||
}
|
||||
android.media.audiofx.DynamicsProcessing(0, audioSessionId, config)
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package tv.orbit.classic
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Test
|
||||
|
||||
/** Frame-rate matching and AVI (9 November 2026). The modes are the downstairs TV's own, read with dumpsys display. */
|
||||
@@ -77,4 +79,11 @@ class PlayerSwitchesTest {
|
||||
assertNull(streamFrameRate(streams()))
|
||||
assertNull(streamFrameRate(null))
|
||||
}
|
||||
|
||||
@Test fun evenVolumeHours() {
|
||||
assertFalse(EvenVolume.activeAt("off", 23)); assertTrue(EvenVolume.activeAt("always", 14))
|
||||
assertTrue(EvenVolume.activeAt("overnight", 23)); assertTrue(EvenVolume.activeAt("overnight", 3))
|
||||
assertFalse(EvenVolume.activeAt("overnight", 7)); assertFalse(EvenVolume.activeAt("overnight", 22))
|
||||
assertEquals("off", PlayerSwitches.evenVolume) // off until Paul has listened to it
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user