audio/mp3dec: mad timer duration is all wrong, use samples instead

This commit is contained in:
Sigrid 2020-08-12 11:42:00 +02:00
parent 81dba13271
commit 601dd12651

View file

@ -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;
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){