shithub: neindaw

Download patch

ref: f1652d3fffe4457db7bf025bdb4ab1201065d923
parent: 57f49b5ea9632be13d0b695a2932fc7e6ed7ac0b
author: Sigrid Haflínudóttir <[email protected]>
date: Fri Aug 7 13:22:30 EDT 2020

put rate into common.h, one for every program

--- a/ay/ay.c
+++ b/ay/ay.c
@@ -39,7 +39,7 @@
 };
 
 static int tickhz = 1773400;
-static int rate = 44100;
+static int rate = RATE;
 
 static void
 regw(ay38910_t *ay, int reg, int v)
--- a/common.h
+++ b/common.h
@@ -13,3 +13,7 @@
 }UItype;
 
 extern char *uitypenames[UInum];
+
+enum {
+	RATE = 44100,
+};
--- a/dsp/main.c
+++ b/dsp/main.c
@@ -23,7 +23,7 @@
 	int inmax, outmax;
 };
 
-static int rate = 44100;
+static int rate = RATE;
 static DSPf *dspf;
 
 static Auxdsp *
--- a/piper/piper.c
+++ b/piper/piper.c
@@ -2,6 +2,7 @@
 #include <libc.h>
 #include <thread.h>
 #include <bio.h>
+#include "common.h"
 #include "piper.h"
 #include "util.h"
 
@@ -31,6 +32,7 @@
 static int numgroups;
 static int audio;
 static int record = -1;
+static int rate = RATE;
 
 static Synth *synths[] = {
 	&ay_3_8910,
@@ -200,45 +202,42 @@
 	return e;
 }
 
-enum {
-	Bufframes = 44100/100,
-};
-
 static void
 mixer(void *)
 {
-	int i, j, n;
+	int i, j, n, bufframes;
 	s16int *pcm;
 	float *out, *x, f;
 	Inst *inst;
 	Group *g;
 
-	pcm = malloc(2*Bufframes*sizeof(*pcm)); /* stereo */
-	out = malloc(2*Bufframes*sizeof(*out));
-	x = malloc(2*Bufframes*sizeof(*x));
+	bufframes = rate/100;
+	pcm = malloc(2*bufframes*sizeof(*pcm)); /* stereo */
+	out = malloc(2*bufframes*sizeof(*out));
+	x = malloc(2*bufframes*sizeof(*x));
 
 	for (;;) {
-		memset(out, 0, 2*Bufframes*sizeof(*out));
+		memset(out, 0, 2*bufframes*sizeof(*out));
 		qlock(&grouplock);
 		for (i = 0; i < numgroups; i++) {
 			g = &groups[i];
 			for (j = 0; j < g->numinst; j++) {
 				inst = &g->inst[j];
-				if (readn(inst->data, x, inst->numout*Bufframes*sizeof(*x)) < 1)
+				if (readn(inst->data, x, inst->numout*bufframes*sizeof(*x)) < 1)
 					break;
 				if (inst->numout == 1) {
-					for (n = 0; n < Bufframes; n++) {
+					for (n = 0; n < bufframes; n++) {
 						out[n*2+0] += x[n];
 						out[n*2+1] += x[n];
 					}
 				} else {
-					for (n = 0; n < 2*Bufframes; n++)
+					for (n = 0; n < 2*bufframes; n++)
 						out[n] += x[n];
 				}
 			}
 		}
 		qunlock(&grouplock);
-		for (n = 0; n < 2*Bufframes; n++) {
+		for (n = 0; n < 2*bufframes; n++) {
 			f = out[n] * 8192.0 * vol;
 			if (f > 32767.0)
 				f = 32767.0;
@@ -246,11 +245,11 @@
 				f = -32767.0;
 			pcm[n] = f;
 		}
-		if (write(audio, pcm, 2*Bufframes*sizeof(*pcm)) < 0) {
+		if (write(audio, pcm, 2*bufframes*sizeof(*pcm)) < 0) {
 			fprint(2, "audio: %r\n");
 			break;
 		}
-		if (record >= 0 && write(record, pcm, 2*Bufframes*sizeof(*pcm)) < 0) {
+		if (record >= 0 && write(record, pcm, 2*bufframes*sizeof(*pcm)) < 0) {
 			fprint(2, "record: %r\n");
 			break;
 		}