summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSigrid <ftrvxmtrx@gmail.com>2020-08-12 11:42:00 +0200
committerSigrid <ftrvxmtrx@gmail.com>2020-08-12 11:42:00 +0200
commit601dd126515fef00815eedb163eae2943952394b (patch)
treed77ac8c48fe404c629a59dd8e059fcaee4773d61
parent81dba1327121e0f62fdf42de61402979b7de5da6 (diff)
downloadplan9front-601dd126515fef00815eedb163eae2943952394b.tar.xz
audio/mp3dec: mad timer duration is all wrong, use samples instead
-rw-r--r--sys/src/cmd/audio/mp3dec/main.c19
1 files 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){