]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
reduced memory usage of sound in Nexuiz by about 70MB by using shorter
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 14 Nov 2009 02:08:16 +0000 (02:08 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 14 Nov 2009 02:08:16 +0000 (02:08 +0000)
ogg/modplug buffers

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9487 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.h
snd_mem.c
snd_modplug.c
snd_ogg.c

index 771205ae2e1e56854d514b5f163354c9283570e7..62c5034297058b802394ed65658e2bf905767ac1 100644 (file)
@@ -136,6 +136,15 @@ extern mempool_t *snd_mempool;
 extern qboolean simsound;
 
 
 extern qboolean simsound;
 
 
+#define STREAM_BUFFER_DURATION 0.3f // in seconds
+#define STREAM_BUFFER_FILL 0.2f // in seconds
+#define STREAM_BUFFER_SIZE(format_ptr) ((int)ceil (STREAM_BUFFER_DURATION * (format_ptr)->speed) * (format_ptr)->width * (format_ptr)->channels)
+
+// We work with 1 sec sequences, so this buffer must be able to contain
+// 1 sec of sound of the highest quality (48 KHz, 16 bit samples, stereo)
+extern unsigned char resampling_buffer [48000 * 2 * 2];
+
+
 // ====================================================================
 //         Architecture-independent functions
 // ====================================================================
 // ====================================================================
 //         Architecture-independent functions
 // ====================================================================
index d294b248c7d74c128d52602c8737539dbd4a1093..75f9e829560df539cc84e5a1a543d092da4a410e 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "snd_wav.h"
 #include "snd_modplug.h"
 
 #include "snd_wav.h"
 #include "snd_modplug.h"
 
+unsigned char resampling_buffer [48000 * 2 * 2];
+
 
 /*
 ====================
 
 /*
 ====================
index 54a07909437e40bbbf3c2ad90d1ddde7fac4a186..748d9e45ee009c30f15ed057cf918ba19aa45a61 100644 (file)
@@ -192,13 +192,6 @@ void ModPlug_CloseLibrary (void)
 =================================================================
 */
 
 =================================================================
 */
 
-#define STREAM_BUFFER_DURATION 1.5f    // 1.5 sec
-#define STREAM_BUFFER_SIZE(format_ptr) ((int)(ceil (STREAM_BUFFER_DURATION * ((format_ptr)->speed * (format_ptr)->width * (format_ptr)->channels))))
-// We work with 1 sec sequences, so this buffer must be able to contain
-// 1 sec of sound of the highest quality (48 KHz, 16 bit samples, stereo)
-static unsigned char resampling_buffer [48000 * 2 * 2];
-
-
 // Per-sfx data structure
 typedef struct
 {
 // Per-sfx data structure
 typedef struct
 {
@@ -339,13 +332,13 @@ static const snd_buffer_t* ModPlug_FetchSound (void *sfxfetcher, void **chfetche
        // We add exactly 1 sec of sound to the buffer:
        // 1- to ensure we won't lose any sample during the resampling process
        // 2- to force one call to ModPlug_FetchSound per second to regulate the workload
        // We add exactly 1 sec of sound to the buffer:
        // 1- to ensure we won't lose any sample during the resampling process
        // 2- to force one call to ModPlug_FetchSound per second to regulate the workload
-       if (sb->format.speed + sb->nbframes > sb->maxframes)
+       if ((int)(sb->format.speed * STREAM_BUFFER_FILL) + sb->nbframes > sb->maxframes)
        {
                Con_Printf ("ModPlug_FetchSound: stream buffer overflow (%u sample frames / %u)\n",
                                        sb->format.speed + sb->nbframes, sb->maxframes);
                return NULL;
        }
        {
                Con_Printf ("ModPlug_FetchSound: stream buffer overflow (%u sample frames / %u)\n",
                                        sb->format.speed + sb->nbframes, sb->maxframes);
                return NULL;
        }
-       newlength = per_sfx->format.speed * factor;  // -> 1 sec of sound before resampling
+       newlength = (int)(per_sfx->format.speed*STREAM_BUFFER_FILL) * factor;  // -> 1 sec of sound before resampling
        if(newlength > (int)sizeof(resampling_buffer))
                newlength = sizeof(resampling_buffer);
 
        if(newlength > (int)sizeof(resampling_buffer))
                newlength = sizeof(resampling_buffer);
 
index 17ddc1b833d8537696a36fe26066dc4327bc61dc..5b7bbcba10d8570a42fcadb38f690e0ed3be6780 100644 (file)
--- a/snd_ogg.c
+++ b/snd_ogg.c
@@ -379,14 +379,6 @@ void OGG_CloseLibrary (void)
 =================================================================
 */
 
 =================================================================
 */
 
-#define STREAM_BUFFER_DURATION 1.5f    // 1.5 sec
-#define STREAM_BUFFER_SIZE(format_ptr) ((int)(ceil (STREAM_BUFFER_DURATION * ((format_ptr)->speed * (format_ptr)->width * (format_ptr)->channels))))
-
-// We work with 1 sec sequences, so this buffer must be able to contain
-// 1 sec of sound of the highest quality (48 KHz, 16 bit samples, stereo)
-static unsigned char resampling_buffer [48000 * 2 * 2];
-
-
 // Per-sfx data structure
 typedef struct
 {
 // Per-sfx data structure
 typedef struct
 {
@@ -526,13 +518,13 @@ static const snd_buffer_t* OGG_FetchSound (void *sfxfetcher, void **chfetcherpoi
        // We add exactly 1 sec of sound to the buffer:
        // 1- to ensure we won't lose any sample during the resampling process
        // 2- to force one call to OGG_FetchSound per second to regulate the workload
        // We add exactly 1 sec of sound to the buffer:
        // 1- to ensure we won't lose any sample during the resampling process
        // 2- to force one call to OGG_FetchSound per second to regulate the workload
-       if (sb->format.speed + sb->nbframes > sb->maxframes)
+       if ((int)(sb->format.speed * STREAM_BUFFER_FILL) + sb->nbframes > sb->maxframes)
        {
                Con_Printf ("OGG_FetchSound: stream buffer overflow (%u sample frames / %u)\n",
                                        sb->format.speed + sb->nbframes, sb->maxframes);
                return NULL;
        }
        {
                Con_Printf ("OGG_FetchSound: stream buffer overflow (%u sample frames / %u)\n",
                                        sb->format.speed + sb->nbframes, sb->maxframes);
                return NULL;
        }
-       newlength = per_sfx->format.speed * factor;  // -> 1 sec of sound before resampling
+       newlength = (int)(per_sfx->format.speed*STREAM_BUFFER_FILL) * factor;  // -> 1 sec of sound before resampling
        if(newlength > (int)sizeof(resampling_buffer))
                newlength = sizeof(resampling_buffer);
 
        if(newlength > (int)sizeof(resampling_buffer))
                newlength = sizeof(resampling_buffer);
 
@@ -711,7 +703,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx)
        len = qov_pcm_total (&vf, -1) * vi->channels * 2;  // 16 bits => "* 2"
 
        // Decide if we go for a stream or a simple PCM cache
        len = qov_pcm_total (&vf, -1) * vi->channels * 2;  // 16 bits => "* 2"
 
        // Decide if we go for a stream or a simple PCM cache
-       buff_len = (int)ceil (STREAM_BUFFER_DURATION * (snd_renderbuffer->format.speed * 2 * vi->channels));
+       buff_len = (int)ceil (STREAM_BUFFER_DURATION * snd_renderbuffer->format.speed) * 2 * vi->channels;
        if (snd_streaming.integer && len > (ogg_int64_t)filesize + 3 * buff_len)
        {
                ogg_stream_persfx_t* per_sfx;
        if (snd_streaming.integer && len > (ogg_int64_t)filesize + 3 * buff_len)
        {
                ogg_stream_persfx_t* per_sfx;