aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/mikmod_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-14 02:18:58 +0100
committerMax Kellermann <max@duempel.org>2009-11-14 02:24:42 +0100
commitdd4625ce13bfbd296f69bc9795561cfbfb63c210 (patch)
tree8689520a9d024a0a131e8a9fb2dea0125278ae02 /src/decoder/mikmod_plugin.c
parent1648c7aa5baf86583b057943337e4fade8616022 (diff)
downloadmpd-dd4625ce13bfbd296f69bc9795561cfbfb63c210.tar.gz
mpd-dd4625ce13bfbd296f69bc9795561cfbfb63c210.tar.xz
mpd-dd4625ce13bfbd296f69bc9795561cfbfb63c210.zip
decoder/mikmod: 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 'src/decoder/mikmod_plugin.c')
-rw-r--r--src/decoder/mikmod_plugin.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/decoder/mikmod_plugin.c b/src/decoder/mikmod_plugin.c
index 74eb48ee9..204dd5ce0 100644
--- a/src/decoder/mikmod_plugin.c
+++ b/src/decoder/mikmod_plugin.c
@@ -146,10 +146,9 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs)
char *path2;
MODULE *handle;
struct audio_format audio_format;
- float total_time = 0.0;
int ret;
- float secPerByte;
SBYTE buffer[MIKMOD_FRAME_SIZE];
+ unsigned frame_size, current_frame = 0;
enum decoder_command cmd = DECODE_COMMAND_NONE;
path2 = g_strdup(path_fs);
@@ -167,18 +166,17 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs)
audio_format_init(&audio_format, mikmod_sample_rate, 16, 2);
assert(audio_format_valid(&audio_format));
- secPerByte =
- 1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
- (float)audio_format.sample_rate);
-
decoder_initialized(decoder, &audio_format, false, 0);
+ frame_size = audio_format_frame_size(&audio_format);
+
Player_Start(handle);
while (cmd == DECODE_COMMAND_NONE && Player_Active()) {
ret = VC_WriteBytes(buffer, sizeof(buffer));
- total_time += ret * secPerByte;
+ current_frame += ret / frame_size;
cmd = decoder_data(decoder, NULL, buffer, ret,
- total_time, 0, NULL);
+ (float)current_frame / (float)mikmod_sample_rate,
+ 0, NULL);
}
Player_Stop();