From bf49c9e4e2ad6c43034774b928b8fdab090223e3 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 8 Sep 2019 12:52:02 +0200
Subject: [PATCH] decoder/{dsf,dsdiff}: precalculate bit rate

---
 src/decoder/plugins/DsdiffDecoderPlugin.cxx | 3 ++-
 src/decoder/plugins/DsfDecoderPlugin.cxx    | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/decoder/plugins/DsdiffDecoderPlugin.cxx b/src/decoder/plugins/DsdiffDecoderPlugin.cxx
index 8c76227eb..b1779632a 100644
--- a/src/decoder/plugins/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/plugins/DsdiffDecoderPlugin.cxx
@@ -362,6 +362,7 @@ dsdiff_decode_chunk(DecoderClient &client, InputStream &is,
 		    unsigned channels, unsigned sample_rate,
 		    const offset_type total_bytes)
 {
+	const unsigned kbit_rate = channels * sample_rate / 1000;
 	const offset_type start_offset = is.GetOffset();
 
 	uint8_t buffer[8192];
@@ -408,7 +409,7 @@ dsdiff_decode_chunk(DecoderClient &client, InputStream &is,
 			bit_reverse_buffer(buffer, buffer + nbytes);
 
 		cmd = client.SubmitData(is, buffer, nbytes,
-					channels * sample_rate / 1000);
+					kbit_rate);
 	}
 
 	return true;
diff --git a/src/decoder/plugins/DsfDecoderPlugin.cxx b/src/decoder/plugins/DsfDecoderPlugin.cxx
index a019ee5c3..332f0525c 100644
--- a/src/decoder/plugins/DsfDecoderPlugin.cxx
+++ b/src/decoder/plugins/DsfDecoderPlugin.cxx
@@ -256,6 +256,7 @@ dsf_decode_chunk(DecoderClient &client, InputStream &is,
 		 offset_type n_blocks,
 		 bool bitreverse)
 {
+	const unsigned kbit_rate = channels * sample_rate / 1000;
 	const size_t block_size = channels * DSF_BLOCK_SIZE;
 	const offset_type start_offset = is.GetOffset();
 
@@ -291,7 +292,7 @@ dsf_decode_chunk(DecoderClient &client, InputStream &is,
 
 		cmd = client.SubmitData(is,
 					interleaved_buffer, block_size,
-					channels * sample_rate / 1000);
+					kbit_rate);
 		++i;
 	}