ref: 601dd126515fef00815eedb163eae2943952394b
parent: 81dba1327121e0f62fdf42de61402979b7de5da6
author: Sigrid <[email protected]>
date: Wed Aug 12 07:42:00 EDT 2020
audio/mp3dec: mad timer duration is all wrong, use samples instead
--- 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 @@
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 @@
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){