aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJurgen Kramer <gtmkramer@xs4all.nl>2012-07-12 19:40:56 +0200
committerMax Kellermann <max@duempel.org>2012-07-13 10:14:17 +0200
commitd4d92ac1a70203b6f686e66ca43e0c0817ba28e3 (patch)
treea59b5cb686f46fb79edd402db98eab1a765a1a7f
parent5385d1fa80b08752bd99d14bd826438310e10b3e (diff)
downloadmpd-d4d92ac1a70203b6f686e66ca43e0c0817ba28e3.tar.gz
mpd-d4d92ac1a70203b6f686e66ca43e0c0817ba28e3.tar.xz
mpd-d4d92ac1a70203b6f686e66ca43e0c0817ba28e3.zip
Add song duration to DSF and DSDIFF DSD decoders.
-rw-r--r--src/decoder/dsdiff_decoder_plugin.c15
-rw-r--r--src/decoder/dsf_decoder_plugin.c12
2 files changed, 24 insertions, 3 deletions
diff --git a/src/decoder/dsdiff_decoder_plugin.c b/src/decoder/dsdiff_decoder_plugin.c
index 2c9ff3833..84471fb3a 100644
--- a/src/decoder/dsdiff_decoder_plugin.c
+++ b/src/decoder/dsdiff_decoder_plugin.c
@@ -33,6 +33,7 @@
#include "util/bit_reverse.h"
#include "tag_handler.h"
#include "dsdlib.h"
+#include "tag_handler.h"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
@@ -313,14 +314,19 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
return;
}
+ /* calculate song time from DSD chunk size and sample frequency */
+ uint64_t chunk_size = metadata.chunk_size;
+ float songtime = ((chunk_size / metadata.channels) * 8) /
+ (float) metadata.sample_rate;
+
/* success: file was recognized */
- decoder_initialized(decoder, &audio_format, false, -1);
+ decoder_initialized(decoder, &audio_format, false, songtime);
/* every iteration of the following loop decodes one "DSD"
chunk from a DFF file */
while (true) {
- uint64_t chunk_size = dsdiff_chunk_size(&chunk_header);
+ chunk_size = dsdiff_chunk_size(&chunk_header);
if (dsdlib_id_equals(&chunk_header.id, "DSD ")) {
if (!dsdiff_decode_chunk(decoder, is,
@@ -363,6 +369,11 @@ dsdiff_scan_stream(struct input_stream *is,
/* refuse to parse files which we cannot play anyway */
return false;
+ /* calculate song time and add as tag */
+ unsigned songtime = ((metadata.chunk_size / metadata.channels) * 8) /
+ metadata.sample_rate;
+ tag_handler_invoke_duration(handler, handler_ctx, songtime);
+
return true;
}
diff --git a/src/decoder/dsf_decoder_plugin.c b/src/decoder/dsf_decoder_plugin.c
index b66ed75e9..c0107eb30 100644
--- a/src/decoder/dsf_decoder_plugin.c
+++ b/src/decoder/dsf_decoder_plugin.c
@@ -33,6 +33,7 @@
#include "audio_check.h"
#include "util/bit_reverse.h"
#include "dsdlib.h"
+#include "tag_handler.h"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
@@ -275,9 +276,13 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
g_error_free(error);
return;
}
+ /* Calculate song time from DSD chunk size and sample frequency */
+ uint64_t chunk_size = metadata.chunk_size;
+ float songtime = ((chunk_size / metadata.channels) * 8) /
+ (float) metadata.sample_rate;
/* success: file was recognized */
- decoder_initialized(decoder, &audio_format, false, -1);
+ decoder_initialized(decoder, &audio_format, false, songtime);
if (!dsf_decode_chunk(decoder, is, metadata.channels,
metadata.chunk_size,
@@ -306,6 +311,11 @@ dsf_scan_stream(struct input_stream *is,
/* refuse to parse files which we cannot play anyway */
return false;
+ /* calculate song time and add as tag */
+ unsigned songtime = ((metadata.chunk_size / metadata.channels) * 8) /
+ metadata.sample_rate;
+ tag_handler_invoke_duration(handler, handler_ctx, songtime);
+
return true;
}