]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
new cvar: snd_streaming_length ("don't stream sound files below this length")
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 14 Sep 2011 09:19:08 +0000 (09:19 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 14 Sep 2011 09:19:08 +0000 (09:19 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11349 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.c
snd_main.h
snd_ogg.c

index 8376007a3a23128409bdd69875cbb8c7759c71ce..5a4cd8836df095a93bcbf1b56c197f95b8409cfc 100644 (file)
@@ -177,7 +177,8 @@ cvar_t snd_spatialization_occlusion = {CVAR_SAVE, "snd_spatialization_occlusion"
 
 // Cvars declared in snd_main.h (shared with other snd_*.c files)
 cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.15", "how much sound to mix ahead of time"};
-cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1", "enables keeping compressed ogg sound files compressed, decompressing them only as needed, otherwise they will be decompressed completely at load (may use a lot of memory)"};
+cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1", "enables keeping compressed ogg sound files compressed, decompressing them only as needed, otherwise they will be decompressed completely at load (may use a lot of memory); when set to 2, streaming is performed even if this would waste memory"};
+cvar_t snd_streaming_length = { CVAR_SAVE, "snd_streaming_length", "0", "When set, sound files are only streamed if longer than the given length in seconds"};
 cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0", "swaps left/right speakers for old ISA soundblaster cards"};
 extern cvar_t v_flipped;
 cvar_t snd_channellayout = {0, "snd_channellayout", "0", "channel layout. Can be 0 (auto - snd_restart needed), 1 (standard layout), or 2 (ALSA layout)"};
index a166aba259e38fc336cd058dcd7e965c87310ce3..59838ec63d1baac1a5aad2e9172b98797ab34e9c 100644 (file)
@@ -116,6 +116,7 @@ extern qboolean snd_usethreadedmixing; // if true, the main thread does not mix
 extern cvar_t _snd_mixahead;
 extern cvar_t snd_swapstereo;
 extern cvar_t snd_streaming;
+extern cvar_t snd_streaming_length;
 
 #define SND_CHANNELLAYOUT_AUTO         0
 #define SND_CHANNELLAYOUT_STANDARD     1
index 0ee16bab4bd7f70cfd64d7310b6b9ba8f72001d9..e1bf0959be7f61f8e2c90e99e87a8d3e0fd0b6b0 100644 (file)
--- a/snd_ogg.c
+++ b/snd_ogg.c
@@ -674,6 +674,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx)
        vorbis_comment *vc;
        ogg_int64_t len, buff_len;
        double peak, gaindb;
+       qboolean want_stream;
 
 #ifndef LINK_TO_LIBVORBIS
        if (!vf_dll)
@@ -718,7 +719,25 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *sfx)
 
        // 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;
-       if (snd_streaming.integer && (len > (ogg_int64_t)filesize + 3 * buff_len || snd_streaming.integer >= 2))
+
+       if(snd_streaming.integer)
+       {
+               want_stream = true;
+
+               // don't stream if we would need more RAM when streaming
+               if(snd_streaming.integer < 2)
+                       if(len <= (ogg_int64_t)filesize + 3 * buff_len)
+                               want_stream = false;
+
+               // if streaming length is set, do NOT stream if below the length
+               if(snd_streaming_length.value > 0)
+                       if(len <= snd_streaming_length.value * vi->channels * 2)
+                               want_stream = false;
+       }
+       else
+               want_stream = false;
+       
+       if (want_stream)
        {
                ogg_stream_persfx_t* per_sfx;