aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/flac_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-11 20:18:39 +0100
committerMax Kellermann <max@duempel.org>2009-11-11 20:18:39 +0100
commite0d5ee00451630c83ba1693939aa6c923f41b727 (patch)
tree9f9b6ebe6f492d54ee352384b12c62988b56e8d0 /src/decoder/flac_plugin.c
parentd35efddd65934e5adebe0c01ab7953c9a34082ed (diff)
downloadmpd-e0d5ee00451630c83ba1693939aa6c923f41b727.tar.gz
mpd-e0d5ee00451630c83ba1693939aa6c923f41b727.tar.xz
mpd-e0d5ee00451630c83ba1693939aa6c923f41b727.zip
decoder/flac: calculate time stamp from current frame
Don't update a float timestamp, this will make imprecisions add up after a while. We already have the number of the current frame, let's just calculate the float timestamp from that for every decoder_data() command. For this, we need to add the attribute "first_frame", for CUE sheet songs.
Diffstat (limited to 'src/decoder/flac_plugin.c')
-rw-r--r--src/decoder/flac_plugin.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c
index afc134077..cbb95bf45 100644
--- a/src/decoder/flac_plugin.c
+++ b/src/decoder/flac_plugin.c
@@ -191,14 +191,9 @@ static FLAC__StreamDecoderWriteStatus
flac_write_cb(const FLAC__StreamDecoder *dec, const FLAC__Frame *frame,
const FLAC__int32 *const buf[], void *vdata)
{
- FLAC__uint32 samples = frame->header.blocksize;
struct flac_data *data = (struct flac_data *) vdata;
- float timeChange;
FLAC__uint64 nbytes = 0;
- timeChange = ((float)samples) / frame->header.sample_rate;
- data->time += timeChange;
-
if (FLAC__stream_decoder_get_decode_position(dec, &nbytes)) {
if (data->position > 0 && nbytes > data->position) {
nbytes -= data->position;
@@ -431,6 +426,8 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec,
struct decoder *decoder = data->decoder;
enum decoder_command cmd;
+ data->first_frame = t_start;
+
while (true) {
if (data->tag != NULL && !tag_is_empty(data->tag)) {
cmd = decoder_tag(data->decoder, data->input_stream,
@@ -448,8 +445,6 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec,
(t_end == 0 || seek_sample <= t_end) &&
FLAC__stream_decoder_seek_absolute(flac_dec, seek_sample)) {
data->next_frame = seek_sample;
- data->time = (float)(seek_sample - t_start) /
- data->audio_format.sample_rate;
data->position = 0;
decoder_command_finished(decoder);
} else