aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/_flac_common.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_common.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 '')
-rw-r--r--src/decoder/_flac_common.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index 0755ef641..b434f31a3 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.c
@@ -36,9 +36,9 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
pcm_buffer_init(&data->buffer);
data->have_stream_info = false;
+ data->first_frame = 0;
data->next_frame = 0;
- data->time = 0;
data->position = 0;
data->decoder = decoder;
data->input_stream = input_stream;
@@ -116,6 +116,7 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
size_t buffer_size = frame->header.blocksize *
audio_format_frame_size(&data->audio_format);
void *buffer;
+ float position;
unsigned bit_rate;
buffer = pcm_buffer_get(&data->buffer, buffer_size);
@@ -124,6 +125,12 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
data->audio_format.bits, buf,
0, frame->header.blocksize);
+ if (data->next_frame >= data->first_frame)
+ position = (float)(data->next_frame - data->first_frame) /
+ data->audio_format.sample_rate;
+ else
+ position = 0;
+
if (nbytes > 0)
bit_rate = nbytes * 8 * frame->header.sample_rate /
(1000 * frame->header.blocksize);
@@ -132,7 +139,7 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
cmd = decoder_data(data->decoder, data->input_stream,
buffer, buffer_size,
- data->time, bit_rate,
+ position, bit_rate,
data->replay_gain_info);
data->next_frame += frame->header.blocksize;
switch (cmd) {