shithub: riscv

Download patch

ref: f4d206737342feec31086a8f3ca6866506a2e0b5
parent: a4c6dc1d3d3a2ef3ec4d4ac49b16ec039c353cd7
author: Sigrid <[email protected]>
date: Mon Nov 2 06:46:50 EST 2020

audio/wavdec: add -s option

--- a/sys/man/1/audio
+++ b/sys/man/1/audio
@@ -23,6 +23,10 @@
 ]
 .br
 .B audio/wavdec
+[
+.B -s
+.I seconds
+]
 .br
 .B audio/sundec
 .PP
--- a/sys/src/cmd/audio/wavdec/wavdec.c
+++ b/sys/src/cmd/audio/wavdec/wavdec.c
@@ -40,13 +40,29 @@
 }
 
 void
-main(int, char *argv[])
+usage(void)
 {
+	fprint(2, "usage: %s [ -s SECONDS ]\n", argv0);
+	exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
 	char buf[1024], fmt[32];
+	double seekto;
 	ulong len, n;
 	Wave wav;
 
-	argv0 = argv[0];
+	seekto = 0.0;
+	ARGBEGIN{
+	case 's':
+		seekto = atof(EARGF(usage()));
+		break;
+	default:
+		usage();
+	}ARGEND
+
 	if(memcmp(getcc(buf), "RIFF", 4) != 0)
 		sysfatal("no riff format");
 	get4();
@@ -95,6 +111,11 @@
 		break;
 	default:
 		sysfatal("wave format (0x%lux) not supported", (ulong)wav.fmt);
+	}
+	if(seekto != 0.0){
+		if(seek(0, (ulong)seekto*wav.rate*wav.framesz & ~wav.framesz, 1) < 1)
+			seekto = 0.0;
+		fprint(2, "time: %g\n", seekto);
 	}
 	snprint(buf, sizeof(buf), "%lud", len);
 	execl("/bin/audio/pcmconv", "pcmconv", "-i", fmt, "-l", buf, nil);