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.
This commit is contained in:
OxygenCobalt 2022-06-11 09:27:55 -06:00
parent d42f5970f1
commit 277e5a151f
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -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