shithub: qk1

Download patch

ref: da3a52a4ad18fa6deb154e0e4b71b755699d5b3b
parent: f2f725ccdcee661c2eb432ba7abb0d0f332dbc25
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Nov 2 14:41:01 EDT 2023

snd: stop reallocating channels, just increase the limit

--- a/snd.c
+++ b/snd.c
@@ -17,7 +17,7 @@
 	Ssamp = Srate / Fpsmin,
 	Snbuf = Ssamp * Sblk,
 
-	Nchan = 128,
+	Nchan = 256,
 	Ndyn = 8,
 	Sstat = Ndyn + Namb
 };
@@ -36,7 +36,6 @@
 	int n;
 };
 
-static int nchan;
 static Chan *chans, *che;
 
 static int afd = -1, mixbufi;
@@ -583,7 +582,7 @@
 {
 	if(afd < 0)
 		return;
-	memset(chans, 0, sizeof(*chans)*nchan);
+	memset(chans, 0, sizeof(*chans)*Nchan);
 	che = chans + Sstat;
 }
 
@@ -686,12 +685,8 @@
 	Chan *c;
 	sfxcache_t *sc;
 
-	if(sfx == nil)
+	if(sfx == nil || che >= chans+Nchan)
 		return;
-	if(che >= chans + nchan){
-		nchan *= 2;
-		chans = realloc(chans, nchan*sizeof(*chans));
-	}
 	c = che++;
 	if(sc = loadsfx(sfx), sc == nil)
 		return;
@@ -868,8 +863,7 @@
 	Cvar_RegisterVariable(&ambient_level);
 	Cvar_RegisterVariable(&ambient_fade);
 
-	nchan = Nchan;
-	chans = calloc(nchan, sizeof(*chans));
+	chans = calloc(Nchan, sizeof(*chans));
 	known_sfx = Hunk_Alloc(MAX_SOUNDS * sizeof *known_sfx);
 	num_sfx = 0;