aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/modplug_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-14 22:30:57 +0100
committerMax Kellermann <max@duempel.org>2009-11-14 22:30:57 +0100
commit1dfadf4815f5a1ca18f235bc839e9e20dd68ecb0 (patch)
tree043fb5d5ab542cd2fe1bf3afa88f49000e333c61 /src/decoder/modplug_plugin.c
parentf5b9e3c064977e29af927caef94538b4aa402464 (diff)
downloadmpd-1dfadf4815f5a1ca18f235bc839e9e20dd68ecb0.tar.gz
mpd-1dfadf4815f5a1ca18f235bc839e9e20dd68ecb0.tar.xz
mpd-1dfadf4815f5a1ca18f235bc839e9e20dd68ecb0.zip
decoder/modplug: count frame position
Don't maintain the current time stamp in a floating point variable, because this is subject to rounding errors.
Diffstat (limited to '')
-rw-r--r--src/decoder/modplug_plugin.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/decoder/modplug_plugin.c b/src/decoder/modplug_plugin.c
index 3a886471a..6c08c2199 100644
--- a/src/decoder/modplug_plugin.c
+++ b/src/decoder/modplug_plugin.c
@@ -94,10 +94,9 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
ModPlug_Settings settings;
GByteArray *bdatas;
struct audio_format audio_format;
- float total_time = 0.0;
- int ret, current;
+ int ret;
char audio_buffer[MODPLUG_FRAME_SIZE];
- float sec_perbyte;
+ unsigned frame_size, current_frame = 0;
enum decoder_command cmd = DECODE_COMMAND_NONE;
bdatas = mod_loadfile(decoder, is);
@@ -126,29 +125,28 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
audio_format_init(&audio_format, 44100, 16, 2);
assert(audio_format_valid(&audio_format));
- sec_perbyte =
- 1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
- (float)audio_format.sample_rate);
-
decoder_initialized(decoder, &audio_format,
is->seekable, ModPlug_GetLength(f) / 1000.0);
- total_time = 0;
+ frame_size = audio_format_frame_size(&audio_format);
do {
ret = ModPlug_Read(f, audio_buffer, MODPLUG_FRAME_SIZE);
if (ret <= 0)
break;
- total_time += ret * sec_perbyte;
+ current_frame += (unsigned)ret / frame_size;
cmd = decoder_data(decoder, NULL,
audio_buffer, ret,
- total_time, 0, NULL);
+ (float)current_frame / (float)audio_format.sample_rate,
+ 0, NULL);
if (cmd == DECODE_COMMAND_SEEK) {
- total_time = decoder_seek_where(decoder);
- current = total_time * 1000;
- ModPlug_Seek(f, current);
+ float where = decoder_seek_where(decoder);
+
+ ModPlug_Seek(f, (int)(where * 1000.0));
+ current_frame = (unsigned)(where * audio_format.sample_rate);
+
decoder_command_finished(decoder);
}