aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-21 17:11:48 +0200
committerMax Kellermann <max@duempel.org>2014-08-21 17:15:29 +0200
commit74cdc0005a032c5473027e372eee3a522ccaf750 (patch)
treeae60444899aefdb70baf8a704ba74a74bf5f9e8b
parenta756cd9565b15ed1f4689ee263c95c209db13e2d (diff)
downloadmpd-74cdc0005a032c5473027e372eee3a522ccaf750.tar.gz
mpd-74cdc0005a032c5473027e372eee3a522ccaf750.tar.xz
mpd-74cdc0005a032c5473027e372eee3a522ccaf750.zip
decoder/dsf: eliminate temporary buffer
Convert into a second buffer that gets passed to decoder_data() without copying back to the first buffer.
-rw-r--r--src/decoder/plugins/DsfDecoderPlugin.cxx19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/decoder/plugins/DsfDecoderPlugin.cxx b/src/decoder/plugins/DsfDecoderPlugin.cxx
index 9f10b8dfc..d99550df1 100644
--- a/src/decoder/plugins/DsfDecoderPlugin.cxx
+++ b/src/decoder/plugins/DsfDecoderPlugin.cxx
@@ -39,8 +39,6 @@
#include "tag/TagHandler.hxx"
#include "Log.hxx"
-#include <string.h>
-
static constexpr unsigned DSF_BLOCK_SIZE = 4096;
struct DsfMetaData {
@@ -197,22 +195,17 @@ bit_reverse_buffer(uint8_t *p, uint8_t *end)
* order.
*/
static void
-dsf_to_pcm_order(uint8_t *dest, size_t nrbytes)
+dsf_to_pcm_order(uint8_t *dest, const uint8_t *src, size_t nrbytes)
{
- uint8_t scratch[DSF_BLOCK_SIZE * 2];
- assert(nrbytes <= sizeof(scratch));
-
for (size_t i = 0, j = 0; i < nrbytes; i += 2) {
- scratch[i] = *(dest+j);
+ dest[i] = src[j];
j++;
}
for (size_t i = 1, j = 0; i < nrbytes; i += 2) {
- scratch[i] = *(dest + DSF_BLOCK_SIZE + j);
+ dest[i] = src[DSF_BLOCK_SIZE + j];
j++;
}
-
- memcpy(dest, scratch, nrbytes);
}
/**
@@ -250,9 +243,11 @@ dsf_decode_chunk(Decoder &decoder, InputStream &is,
if (bitreverse)
bit_reverse_buffer(buffer, buffer + nbytes);
- dsf_to_pcm_order(buffer, nbytes);
+ uint8_t interleaved_buffer[DSF_BLOCK_SIZE * 2];
+ dsf_to_pcm_order(interleaved_buffer, buffer, nbytes);
- const auto cmd = decoder_data(decoder, is, buffer, nbytes,
+ const auto cmd = decoder_data(decoder, is,
+ interleaved_buffer, nbytes,
sample_rate / 1000);
switch (cmd) {
case DecoderCommand::NONE: