From d176e15384a9f5a97ecd2aa76fb64bf95a4cc6e8 Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 14 Sep 2011 09:19:08 +0000 Subject: [PATCH] new cvar: snd_streaming_length ("don't stream sound files below this length") git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11349 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_main.c | 3 ++- snd_main.h | 1 + snd_ogg.c | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/snd_main.c b/snd_main.c index 8376007a..5a4cd883 100644 --- a/snd_main.c +++ b/snd_main.c @@ -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)"}; diff --git a/snd_main.h b/snd_main.h index a166aba2..59838ec6 100644 --- a/snd_main.h +++ b/snd_main.h @@ -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 diff --git a/snd_ogg.c b/snd_ogg.c index 0ee16bab..e1bf0959 100644 --- 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; -- 2.39.2