From f78527d1e38bd9aedcfde4c32757b597d2004b62 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 23 Aug 2014 13:50:14 +0200 Subject: decoder/dsf: use the block count internally --- src/decoder/plugins/DsfDecoderPlugin.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/decoder/plugins/DsfDecoderPlugin.cxx b/src/decoder/plugins/DsfDecoderPlugin.cxx index 5a2ac61e3..0f0739e37 100644 --- a/src/decoder/plugins/DsfDecoderPlugin.cxx +++ b/src/decoder/plugins/DsfDecoderPlugin.cxx @@ -42,11 +42,12 @@ #include static constexpr unsigned DSF_BLOCK_SIZE = 4096; +static constexpr unsigned DSF_BLOCK_BITS = DSF_BLOCK_SIZE * 8; struct DsfMetaData { unsigned sample_rate, channels; bool bitreverse; - offset_type chunk_size; + offset_type n_blocks; #ifdef HAVE_ID3TAG offset_type id3_offset; #endif @@ -170,7 +171,8 @@ dsf_read_metadata(Decoder *decoder, InputStream &is, if (data_size > playable_size) data_size = playable_size; - metadata->chunk_size = data_size; + const size_t block_size = channels * DSF_BLOCK_SIZE; + metadata->n_blocks = data_size / block_size; metadata->channels = channels; metadata->sample_rate = samplefreq; #ifdef HAVE_ID3TAG @@ -247,7 +249,7 @@ InterleaveDsfBlock(uint8_t *gcc_restrict dest, const uint8_t *gcc_restrict src, static bool dsf_decode_chunk(Decoder &decoder, InputStream &is, unsigned channels, unsigned sample_rate, - offset_type chunk_size, + offset_type n_blocks, bool bitreverse) { /* worst-case buffer size */ @@ -255,8 +257,6 @@ dsf_decode_chunk(Decoder &decoder, InputStream &is, const size_t block_size = channels * DSF_BLOCK_SIZE; - const offset_type n_blocks = chunk_size / block_size; - for (offset_type i = 0; i < n_blocks;) { if (!decoder_read_full(&decoder, is, buffer, block_size)) return false; @@ -306,8 +306,8 @@ dsf_stream_decode(Decoder &decoder, InputStream &is) return; } /* Calculate song time from DSD chunk size and sample frequency */ - offset_type chunk_size = metadata.chunk_size; - float songtime = ((chunk_size / metadata.channels) * 8) / + const auto n_blocks = metadata.n_blocks; + float songtime = float(n_blocks * DSF_BLOCK_BITS) / (float) metadata.sample_rate; /* success: file was recognized */ @@ -315,7 +315,7 @@ dsf_stream_decode(Decoder &decoder, InputStream &is) if (!dsf_decode_chunk(decoder, is, metadata.channels, metadata.sample_rate, - chunk_size, + n_blocks, metadata.bitreverse)) return; } @@ -338,8 +338,8 @@ dsf_scan_stream(InputStream &is, return false; /* calculate song time and add as tag */ - unsigned songtime = ((metadata.chunk_size / metadata.channels) * 8) / - metadata.sample_rate; + unsigned songtime = (metadata.n_blocks * DSF_BLOCK_BITS) / + metadata.sample_rate; tag_handler_invoke_duration(handler, handler_ctx, songtime); #ifdef HAVE_ID3TAG -- cgit v1.2.3