mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
Float output is the one way the audio processor chain is skipped on this build, and it is a flag the renderers factory is handed. Nothing sets it, so nothing happens today; if it is ever turned on, this says so once at sink construction rather than leaving replay gain silently inapplicable to high-resolution tracks. Offload has no equivalent check: it is not a flag this code sets, and AudioSink.setOffloadMode is only reachable by building the audio renderer by hand. The factory comment names it instead.
39 lines
1.4 KiB
Kotlin
39 lines
1.4 KiB
Kotlin
package com.subtracks.playback
|
|
|
|
import android.content.Context
|
|
import androidx.annotation.OptIn
|
|
import androidx.media3.common.util.UnstableApi
|
|
import androidx.media3.exoplayer.DefaultRenderersFactory
|
|
import androidx.media3.exoplayer.audio.AudioSink
|
|
import androidx.media3.exoplayer.audio.DefaultAudioSink
|
|
import com.subtracks.log.Log
|
|
|
|
@OptIn(UnstableApi::class)
|
|
internal class ReplayGainRenderersFactory(
|
|
context: Context,
|
|
private val processor: ReplayGainProcessor,
|
|
) : DefaultRenderersFactory(context) {
|
|
// Mirrors the stock DefaultRenderersFactory.buildAudioSink. setAudioProcessors keeps the default
|
|
// chain and prepends ours; DefaultAudioSink omits the whole chain when float output is enabled,
|
|
// and AudioSink.setOffloadMode bypasses it entirely.
|
|
public override fun buildAudioSink(
|
|
context: Context,
|
|
enableFloatOutput: Boolean,
|
|
enableAudioOutputPlaybackParameters: Boolean,
|
|
): AudioSink {
|
|
if (enableFloatOutput) {
|
|
Log.w(FLOAT_OUTPUT_TAG, "float output is on, so replay gain is not applied to high-resolution tracks")
|
|
}
|
|
return DefaultAudioSink
|
|
.Builder(context)
|
|
.setEnableFloatOutput(enableFloatOutput)
|
|
.setEnableAudioOutputPlaybackParameters(enableAudioOutputPlaybackParameters)
|
|
.setAudioProcessors(arrayOf(processor))
|
|
.build()
|
|
}
|
|
|
|
private companion object {
|
|
const val FLOAT_OUTPUT_TAG = "replaygain"
|
|
}
|
|
}
|