From 277e5a151fd2011865f3854e8187d3c275b64c55 Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Sat, 11 Jun 2022 09:27:55 -0600 Subject: [PATCH] playback: use more efficient no-op w/replaygain When ReplayGain is not needed, use ByteBuffer.put in favor of a for loop when doing a simple copy. ByteBuffer.put is highly optimized and far more efficient than a for loop. --- .../auxio/playback/replaygain/ReplayGainAudioProcessor.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt index f8d41e69f..4628436c0 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt @@ -226,10 +226,9 @@ class ReplayGainAudioProcessor : BaseAudioProcessor() { val buffer = replaceOutputBuffer(size) if (volume == 1f) { - // Nothing to do, just copy the bytes into the output buffer. - for (i in position until limit) { - buffer.put(inputBuffer[i]) - } + // No need to apply ReplayGain, do a memmove using put instead of + // a for loop (the latter is not efficient) + buffer.put(inputBuffer.slice()) } else { for (i in position until limit step 2) { // Ensure we clamp the values to the minimum and maximum values possible