summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSigrid <ftrvxmtrx@gmail.com>2020-08-12 10:43:46 +0200
committerSigrid <ftrvxmtrx@gmail.com>2020-08-12 10:43:46 +0200
commit81dba1327121e0f62fdf42de61402979b7de5da6 (patch)
tree024aba0380fa0d1c42ed59eecaefdcf2c2f69d55
parent5fcf2040b43d13b6410285d45a0510b637d811c3 (diff)
downloadplan9front-81dba1327121e0f62fdf42de61402979b7de5da6.tar.xz
audio/mp3dec: add -s SECONDS option
-rw-r--r--sys/man/1/audio3
-rw-r--r--sys/src/cmd/audio/mp3dec/main.c26
2 files changed, 28 insertions, 1 deletions
diff --git a/sys/man/1/audio b/sys/man/1/audio
index 5bbe072a5..511182c98 100644
--- a/sys/man/1/audio
+++ b/sys/man/1/audio
@@ -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
diff --git a/sys/src/cmd/audio/mp3dec/main.c b/sys/src/cmd/audio/mp3dec/main.c
index ee90ce0bd..20d2d0774 100644
--- a/sys/src/cmd/audio/mp3dec/main.c
+++ b/sys/src/cmd/audio/mp3dec/main.c
@@ -7,6 +7,7 @@
/* Current input file */
vlong offset;
+double seekto = 0.0, curpos = 0.0;
int debug = 0;
int ifd = -1;
@@ -30,6 +31,22 @@ 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;
+ 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)
{
static int rate, chans;
@@ -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);