shithub: choc

Download patch

ref: a3e2dbc78825378307509201f904a1de3bf8bab8
parent: 4788fd8387b4206df42a95c3c2f9b848bf4eac20
author: Simon Howard <fraggle@gmail.com>
date: Sat Mar 22 20:07:40 EDT 2014

sound: Add config variable to control buffer size.

Add snd_maxslicetime_ms variable to control the size of the output
sound buffer, and reduce the default from 70ms to 28ms to match Doom's
35fps timer. Thanks to Holering for reporting this (fixes #345).

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -50,7 +50,6 @@
 
 #define LOW_PASS_FILTER
 //#define DEBUG_DUMP_WAVS
-#define MAX_SOUND_SLICE_TIME 70 /* ms */
 #define NUM_CHANNELS 16
 
 typedef struct allocated_sound_s allocated_sound_t;
@@ -961,7 +960,7 @@
     sound_initialized = false;
 }
 
-// Calculate slice size, based on MAX_SOUND_SLICE_TIME.
+// Calculate slice size, based on snd_maxslicetime_ms.
 // The result must be a power of two.
 
 static int GetSliceSize(void)
@@ -969,7 +968,7 @@
     int limit;
     int n;
 
-    limit = (snd_samplerate * MAX_SOUND_SLICE_TIME) / 1000;
+    limit = (snd_samplerate * snd_maxslicetime_ms) / 1000;
 
     // Try all powers of two, not exceeding the limit.
 
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -47,6 +47,11 @@
 
 int snd_cachesize = 64 * 1024 * 1024;
 
+// Config variable that controls the sound buffer size.
+// We default to 28ms (1000 / 35fps = 1 buffer per tic).
+
+int snd_maxslicetime_ms = 28;
+
 // Low-level sound and music modules we are using
 
 static sound_module_t *sound_module;
@@ -434,6 +439,7 @@
     M_BindVariable("snd_sbirq",         &snd_sbirq);
     M_BindVariable("snd_sbdma",         &snd_sbdma);
     M_BindVariable("snd_mport",         &snd_mport);
+    M_BindVariable("snd_maxslicetime_ms", &snd_maxslicetime_ms);
     M_BindVariable("snd_samplerate",    &snd_samplerate);
     M_BindVariable("snd_cachesize",     &snd_cachesize);
     M_BindVariable("opl_io_port",       &opl_io_port);
--- a/src/i_sound.h
+++ b/src/i_sound.h
@@ -233,6 +233,7 @@
 extern int snd_musicdevice;
 extern int snd_samplerate;
 extern int snd_cachesize;
+extern int snd_maxslicetime_ms;
 
 void I_BindSoundVariables(void);
 
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -798,6 +798,15 @@
     CONFIG_VARIABLE_INT(snd_cachesize),
 
     //!
+    // Maximum size of the output sound buffer size in milliseconds.
+    // Sound output is generated periodically in slices. Higher values
+    // might be more efficient but will introduce latency to the
+    // sound output. The default is 28ms (one slice per tic with the
+    // 35fps timer).
+
+    CONFIG_VARIABLE_INT(snd_maxslicetime_ms),
+
+    //!
     // The I/O port to use to access the OPL chip.  Only relevant when
     // using native OPL music playback.
     //