From 601dd126515fef00815eedb163eae2943952394b Mon Sep 17 00:00:00 2001 From: Sigrid Date: Wed, 12 Aug 2020 11:42:00 +0200 Subject: [PATCH] audio/mp3dec: mad timer duration is all wrong, use samples instead --- sys/src/cmd/audio/mp3dec/main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sys/src/cmd/audio/mp3dec/main.c b/sys/src/cmd/audio/mp3dec/main.c index 20d2d0774..4490c4d7b 100644 --- a/sys/src/cmd/audio/mp3dec/main.c +++ b/sys/src/cmd/audio/mp3dec/main.c @@ -7,7 +7,8 @@ /* Current input file */ vlong offset; -double seekto = 0.0, curpos = 0.0; +double seekto = 0.0; +uvlong samples = 0; int debug = 0; int ifd = -1; @@ -33,15 +34,15 @@ input(void *, struct mad_stream *stream) static enum mad_flow header(void *, struct mad_header const* header) { - if(seekto > 0 && (header->duration.seconds > 0 || header->duration.fraction > 0)){ - double dur = header->duration.seconds + (double)header->duration.fraction / MAD_TIMER_RESOLUTION; - seekto -= dur; - if(seekto > 0){ - curpos += dur; + if(seekto > 0){ + uvlong after = samples + 32*MAD_NSBSAMPLES(header); + if((double)after/header->samplerate >= seekto){ + fprint(2, "time: %g\n", (double)samples/header->samplerate); + seekto = 0; + }else{ + samples = after; return MAD_FLOW_IGNORE; } - fprint(2, "time: %g\n", curpos); - seekto = 0; } return MAD_FLOW_CONTINUE; } @@ -57,7 +58,7 @@ output(void *, struct mad_header const* header, struct mad_pcm *pcm) uchar *p; if(seekto > 0) - return MAD_FLOW_CONTINUE; + return MAD_FLOW_IGNORE; /* start converter if format changed */ if(rate != pcm->samplerate || chans != pcm->channels){