decoder/dsf: use the block count internally
This commit is contained in:
@@ -42,11 +42,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static constexpr unsigned DSF_BLOCK_SIZE = 4096;
|
static constexpr unsigned DSF_BLOCK_SIZE = 4096;
|
||||||
|
static constexpr unsigned DSF_BLOCK_BITS = DSF_BLOCK_SIZE * 8;
|
||||||
|
|
||||||
struct DsfMetaData {
|
struct DsfMetaData {
|
||||||
unsigned sample_rate, channels;
|
unsigned sample_rate, channels;
|
||||||
bool bitreverse;
|
bool bitreverse;
|
||||||
offset_type chunk_size;
|
offset_type n_blocks;
|
||||||
#ifdef HAVE_ID3TAG
|
#ifdef HAVE_ID3TAG
|
||||||
offset_type id3_offset;
|
offset_type id3_offset;
|
||||||
#endif
|
#endif
|
||||||
@@ -170,7 +171,8 @@ dsf_read_metadata(Decoder *decoder, InputStream &is,
|
|||||||
if (data_size > playable_size)
|
if (data_size > playable_size)
|
||||||
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->channels = channels;
|
||||||
metadata->sample_rate = samplefreq;
|
metadata->sample_rate = samplefreq;
|
||||||
#ifdef HAVE_ID3TAG
|
#ifdef HAVE_ID3TAG
|
||||||
@@ -247,7 +249,7 @@ InterleaveDsfBlock(uint8_t *gcc_restrict dest, const uint8_t *gcc_restrict src,
|
|||||||
static bool
|
static bool
|
||||||
dsf_decode_chunk(Decoder &decoder, InputStream &is,
|
dsf_decode_chunk(Decoder &decoder, InputStream &is,
|
||||||
unsigned channels, unsigned sample_rate,
|
unsigned channels, unsigned sample_rate,
|
||||||
offset_type chunk_size,
|
offset_type n_blocks,
|
||||||
bool bitreverse)
|
bool bitreverse)
|
||||||
{
|
{
|
||||||
/* worst-case buffer size */
|
/* 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 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;) {
|
for (offset_type i = 0; i < n_blocks;) {
|
||||||
if (!decoder_read_full(&decoder, is, buffer, block_size))
|
if (!decoder_read_full(&decoder, is, buffer, block_size))
|
||||||
return false;
|
return false;
|
||||||
@@ -306,8 +306,8 @@ dsf_stream_decode(Decoder &decoder, InputStream &is)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Calculate song time from DSD chunk size and sample frequency */
|
/* Calculate song time from DSD chunk size and sample frequency */
|
||||||
offset_type chunk_size = metadata.chunk_size;
|
const auto n_blocks = metadata.n_blocks;
|
||||||
float songtime = ((chunk_size / metadata.channels) * 8) /
|
float songtime = float(n_blocks * DSF_BLOCK_BITS) /
|
||||||
(float) metadata.sample_rate;
|
(float) metadata.sample_rate;
|
||||||
|
|
||||||
/* success: file was recognized */
|
/* success: file was recognized */
|
||||||
@@ -315,7 +315,7 @@ dsf_stream_decode(Decoder &decoder, InputStream &is)
|
|||||||
|
|
||||||
if (!dsf_decode_chunk(decoder, is, metadata.channels,
|
if (!dsf_decode_chunk(decoder, is, metadata.channels,
|
||||||
metadata.sample_rate,
|
metadata.sample_rate,
|
||||||
chunk_size,
|
n_blocks,
|
||||||
metadata.bitreverse))
|
metadata.bitreverse))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -338,8 +338,8 @@ dsf_scan_stream(InputStream &is,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* calculate song time and add as tag */
|
/* calculate song time and add as tag */
|
||||||
unsigned songtime = ((metadata.chunk_size / metadata.channels) * 8) /
|
unsigned songtime = (metadata.n_blocks * DSF_BLOCK_BITS) /
|
||||||
metadata.sample_rate;
|
metadata.sample_rate;
|
||||||
tag_handler_invoke_duration(handler, handler_ctx, songtime);
|
tag_handler_invoke_duration(handler, handler_ctx, songtime);
|
||||||
|
|
||||||
#ifdef HAVE_ID3TAG
|
#ifdef HAVE_ID3TAG
|
||||||
|
Reference in New Issue
Block a user