shithub: qk1

Download patch

ref: d40a186cc44a69a1e138e3347298e477b6f8d81f
parent: c2239f90fcf09b0cc54c9ff284ad15784b3fafbf
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Nov 6 22:56:53 EST 2023

make sound less choppy and with less latency

--- a/dat.h
+++ b/dat.h
@@ -30,7 +30,7 @@
 extern int dedicated;
 
 enum{
-	Fpsmin = 10,
+	Fpsmin = 5,
 	Fpsmax = 72
 };
 
--- a/snd.c
+++ b/snd.c
@@ -10,7 +10,6 @@
 	Sch = 2,
 	Sblk = Ssize * Sch,
 	Ssamp = Srate / Fpsmin,
-	Snbuf = Ssamp * Sblk,
 
 	Nchan = 256,
 	Ndyn = 8,
@@ -34,10 +33,11 @@
 static Chan *chans, *che;
 
 static int ainit, mixbufi;
-static uchar mixbufs[2][Snbuf], *mixbuf = mixbufs[0];
+static uchar *mixbufs[2], *mixbuf;
+static int mixbufsz[2];
 static vlong sndt, sampt;
 static int nsamp;
-static int sampbuf[Ssamp*Sch*sizeof(int)];
+static int sampbuf[Ssamp*2];
 static int scalt[32][256];
 
 static Sfx *ambsfx[Namb];
@@ -531,6 +531,11 @@
 	if(nsamp > Ssamp)
 		nsamp = Ssamp;
 	ns = nsamp * Sblk;
+	if(ns > mixbufsz[mixbufi]){
+		mixbufsz[mixbufi] = ns;
+		mixbufs[mixbufi] = realloc(mixbufs[mixbufi], mixbufsz[mixbufi]);
+	}
+	mixbuf = mixbufs[mixbufi];
 	samplesfx();
 	sampt += nsamp;
 	if(ns != 0){