audio/mp3dec: add -s SECONDS option
This commit is contained in:
parent
5fcf2040b4
commit
81dba13271
2 changed files with 28 additions and 1 deletions
|
@ -4,6 +4,9 @@ mp3dec, mp3enc, oggdec, oggenc, flacdec, sundec, wavdec, pcmconv, mixfs \- decod
|
|||
.SH SYNOPSIS
|
||||
.B audio/mp3dec
|
||||
[
|
||||
.B -s
|
||||
.I seconds
|
||||
] [
|
||||
.B -d
|
||||
]
|
||||
.br
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
/* Current input file */
|
||||
vlong offset;
|
||||
double seekto = 0.0, curpos = 0.0;
|
||||
int debug = 0;
|
||||
int ifd = -1;
|
||||
|
||||
|
@ -29,6 +30,22 @@ input(void *, struct mad_stream *stream)
|
|||
return MAD_FLOW_CONTINUE;
|
||||
}
|
||||
|
||||
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;
|
||||
return MAD_FLOW_IGNORE;
|
||||
}
|
||||
fprint(2, "time: %g\n", curpos);
|
||||
seekto = 0;
|
||||
}
|
||||
return MAD_FLOW_CONTINUE;
|
||||
}
|
||||
|
||||
static enum mad_flow
|
||||
output(void *, struct mad_header const* header, struct mad_pcm *pcm)
|
||||
{
|
||||
|
@ -39,6 +56,9 @@ output(void *, struct mad_header const* header, struct mad_pcm *pcm)
|
|||
int i, j, n;
|
||||
uchar *p;
|
||||
|
||||
if(seekto > 0)
|
||||
return MAD_FLOW_CONTINUE;
|
||||
|
||||
/* start converter if format changed */
|
||||
if(rate != pcm->samplerate || chans != pcm->channels){
|
||||
int pid, pfd[2];
|
||||
|
@ -145,11 +165,15 @@ main(int argc, char **argv)
|
|||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
case 's':
|
||||
seekto = atof(EARGF(usage()));
|
||||
if(seekto >= 0.0)
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}ARGEND
|
||||
|
||||
mad_decoder_init(&decoder, nil, input, nil, nil, output, error, nil);
|
||||
mad_decoder_init(&decoder, nil, input, header, nil, output, error, nil);
|
||||
mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
|
||||
mad_decoder_finish(&decoder);
|
||||
|
||||
|
|
Loading…
Reference in a new issue