Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Alter YouTube Music's speed and pitch with the same vocoder as Spotify

Lelonio04779a98688d
diff --git a/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubePlayerFactory.kt b/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubePlayerFactory.kt
index 075bf4f..769917c 100644
--- a/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubePlayerFactory.kt
+++ b/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubePlayerFactory.kt
@@ -255,13 +255,16 @@ object YouTubePlayerFactory {
// processor of this app's, and a chain that does not list it
// does not run it. Before the stretcher, because it works on
// what the two channels share and a stretched pair shares less.
+ //
+ // Speed and pitch by the app's own vocoder, as on Spotify and
+ // for the phone's own files. The default chain left them to
+ // Sonic, which was built for speech: on music it smears the
+ // attacks and adds a metallic edge, and the same effect sounded
+ // plainly worse on a YouTube song. See BungeeAudioProcessor.
.setAudioProcessorChain(
- // Every stream at the mixer's rate, so a 44.1 kHz song and
- // a 48 kHz one can be summed; see MixerRateProcessor.
- androidx.media3.exoplayer.audio.DefaultAudioSink.DefaultAudioProcessorChain(
- dev.lelonio.square.playback.VocalAudioProcessor(),
- MixerRateProcessor(),
- ),
+ // Then every stream at the mixer's rate, so a 44.1 kHz song
+ // and a 48 kHz one can be summed; see MixerRateProcessor.
+ dev.lelonio.square.playback.BungeeProcessorChain(after = arrayOf(MixerRateProcessor())),
)
.build()
}
diff --git a/app/src/main/java/dev/lelonio/square/playback/BungeeAudioProcessor.kt b/app/src/main/java/dev/lelonio/square/playback/BungeeAudioProcessor.kt
index 25851a8..ed921fe 100644
--- a/app/src/main/java/dev/lelonio/square/playback/BungeeAudioProcessor.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/BungeeAudioProcessor.kt
@@ -193,13 +193,15 @@ class VocalAudioProcessor : BaseAudioProcessor() {
@OptIn(UnstableApi::class)
class BungeeProcessorChain(
private val bungee: BungeeAudioProcessor = BungeeAudioProcessor(),
+ /** Run after the vocoder, at speed one: YouTube Music's resampling to its mixer. */
+ private val after: Array<AudioProcessor> = emptyArray(),
) : DefaultAudioSink.AudioProcessorChain {
private var parameters = PlaybackParameters.DEFAULT
private val vocals = VocalAudioProcessor()
- override fun getAudioProcessors(): Array<AudioProcessor> = arrayOf(vocals, bungee)
+ override fun getAudioProcessors(): Array<AudioProcessor> = arrayOf(vocals, bungee, *after)
override fun applyPlaybackParameters(
playbackParameters: PlaybackParameters,