// 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)"};
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
vorbis_comment *vc;
ogg_int64_t len, buff_len;
double peak, gaindb;
+ qboolean want_stream;
#ifndef LINK_TO_LIBVORBIS
if (!vf_dll)
// 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;