Visualizer tweaks

This commit is contained in:
Damontecres 2026-03-15 08:28:02 -04:00
parent 1ee1a855a2
commit 48a933136f
No known key found for this signature in database
2 changed files with 10 additions and 11 deletions

View file

@ -40,7 +40,7 @@ fun BoxScope.BarVisualizer(
data.forEachIndexed { index, data -> data.forEachIndexed { index, data ->
val height by animateDpAsState( val height by animateDpAsState(
targetValue = size.height * data / 128f, targetValue = size.height * data / 256f,
animationSpec = tween(easing = LinearEasing), animationSpec = tween(easing = LinearEasing),
) )
Box( Box(

View file

@ -47,8 +47,6 @@ import org.jellyfin.sdk.model.api.LyricDto
import org.jellyfin.sdk.model.extensions.ticks import org.jellyfin.sdk.model.extensions.ticks
import timber.log.Timber import timber.log.Timber
import java.util.UUID import java.util.UUID
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.time.Duration import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.milliseconds
@ -267,15 +265,16 @@ class NowPlayingViewModel
waveform: ByteArray, waveform: ByteArray,
samplingRate: Int, samplingRate: Int,
) { ) {
val resolution = 64 val resolution = 96
val processed = IntArray(resolution)
val captureSize = val captureSize =
Visualizer.getCaptureSizeRange()[1] Visualizer.getCaptureSizeRange()[1]
val groupSize = captureSize / resolution.toFloat() val groupSize = (captureSize / resolution.toFloat()).toInt()
for (i in 0 until resolution) { val processed =
val v = abs(waveform[ceil(i * groupSize).toInt()].toInt()) waveform
processed[i] = abs(v * v / (128) - 128) .toList()
} .chunked(groupSize)
.map { it.average().toInt() + 128 }
.toIntArray()
viz.update { processed } viz.update { processed }
} }
@ -311,7 +310,7 @@ class NowPlayingViewModel
captureSize = Visualizer.getCaptureSizeRange()[1] captureSize = Visualizer.getCaptureSizeRange()[1]
setDataCaptureListener( setDataCaptureListener(
this@NowPlayingViewModel, this@NowPlayingViewModel,
Visualizer.getMaxCaptureRate() / 2, Visualizer.getMaxCaptureRate() / 3,
true, true,
false, false,
) )