shithub: neindaw

Download patch

ref: b63c36f9089a10ddccf6fa22d71fa35363fc7f82
parent: 66fa8ef996ffb3ded8ad1f9b6eb756727e0aa705
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed May 13 14:07:57 EDT 2020

piper: add -r option to record audio

--- a/piper/piper.c
+++ b/piper/piper.c
@@ -30,6 +30,7 @@
 static Group *groups;
 static int numgroups;
 static int audio;
+static int record = -1;
 
 static Synth *synths[] = {
 	&ay_3_8910,
@@ -40,7 +41,7 @@
 static void
 usage(void)
 {
-	print("usage: %s [-m] DIR...\n", argv0);
+	print("usage: %s [-m] [-r FILE] DIR...\n", argv0);
 	threadexitsall("usage");
 }
 
@@ -247,6 +248,8 @@
 		}
 		if (write(audio, pcm, 2*Bufframes*sizeof(*pcm)) < 0)
 			break;
+		if (write(record, pcm, 2*Bufframes*sizeof(*pcm)) < 0)
+			break;
 	}
 
 	threadexits(nil);
@@ -255,16 +258,20 @@
 void
 threadmain(int argc, char **argv)
 {
-	char *s, t[256];
+	char *s, t[256], *to;
 	Synth *synth;
 	Biobuf *b;
 	int i, j, n, nomixer;
 
 	nomixer = 0;
+	to = nil;
 	ARGBEGIN{
 	case 'm':
 		nomixer = 1;
 		break;
+	case 'r':
+		to = EARGF(usage());
+		break;
 	default:
 		usage();
 	}ARGEND;
@@ -273,6 +280,8 @@
 		usage();
 
 	if (!nomixer && (audio = open("/dev/audio", OWRITE)) < 0)
+		sysfatal("%r");
+	if (to != nil && (record = create(to, OWRITE|OTRUNC, 0644)) < 0)
 		sysfatal("%r");
 
 	quotefmtinstall();