X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=snd_main.c;h=b61a9d3cee365fc351b42ab298b8d3988c3dce64;hb=26e11a76c1f5cfbe0b7b8987c79ee3ff318979df;hp=6bda6fd0d519eeaa47374c2b853ac1141cd4064f;hpb=9804c2369e4ac79331fc05bf37655bdf76457f2d;p=xonotic%2Fdarkplaces.git diff --git a/snd_main.c b/snd_main.c index 6bda6fd0..b61a9d3c 100644 --- a/snd_main.c +++ b/snd_main.c @@ -49,24 +49,24 @@ static const speakerlayout_t snd_speakerlayouts[] = { "surround71", 8, { - {0, 45, 0.2, 0.2, 0.5}, // front left - {1, 315, 0.2, 0.2, 0.5}, // front right - {2, 135, 0.2, 0.2, 0.5}, // rear left - {3, 225, 0.2, 0.2, 0.5}, // rear right - {4, 0, 0.2, 0.2, 0.5}, // front center + {0, 45, 0.2f, 0.2f, 0.5f}, // front left + {1, 315, 0.2f, 0.2f, 0.5f}, // front right + {2, 135, 0.2f, 0.2f, 0.5f}, // rear left + {3, 225, 0.2f, 0.2f, 0.5f}, // rear right + {4, 0, 0.2f, 0.2f, 0.5f}, // front center {5, 0, 0, 0, 0}, // lfe (we don't have any good lfe sound sources and it would take some filtering work to generate them (and they'd probably still be wrong), so... no lfe) - {6, 90, 0.2, 0.2, 0.5}, // side left - {7, 180, 0.2, 0.2, 0.5}, // side right + {6, 90, 0.2f, 0.2f, 0.5f}, // side left + {7, 180, 0.2f, 0.2f, 0.5f}, // side right } }, { "surround51", 6, { - {0, 45, 0.2, 0.2, 0.5}, // front left - {1, 315, 0.2, 0.2, 0.5}, // front right - {2, 135, 0.2, 0.2, 0.5}, // rear left - {3, 225, 0.2, 0.2, 0.5}, // rear right - {4, 0, 0.2, 0.2, 0.5}, // front center + {0, 45, 0.2f, 0.2f, 0.5f}, // front left + {1, 315, 0.2f, 0.2f, 0.5f}, // front right + {2, 135, 0.2f, 0.2f, 0.5f}, // rear left + {3, 225, 0.2f, 0.2f, 0.5f}, // rear right + {4, 0, 0.2f, 0.2f, 0.5f}, // front center {5, 0, 0, 0, 0}, // lfe (we don't have any good lfe sound sources and it would take some filtering work to generate them (and they'd probably still be wrong), so... no lfe) {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, @@ -77,10 +77,10 @@ static const speakerlayout_t snd_speakerlayouts[] = // channel of its own "surround40", 4, { - {0, 45, 0.3, 0.3, 0.8}, // front left - {1, 315, 0.3, 0.3, 0.8}, // front right - {2, 135, 0.3, 0.3, 0.8}, // rear left - {3, 225, 0.3, 0.3, 0.8}, // rear right + {0, 45, 0.3f, 0.3f, 0.8f}, // front left + {1, 315, 0.3f, 0.3f, 0.8f}, // front right + {2, 135, 0.3f, 0.3f, 0.8f}, // rear left + {3, 225, 0.3f, 0.3f, 0.8f}, // rear right {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, @@ -92,8 +92,8 @@ static const speakerlayout_t snd_speakerlayouts[] = // channel of its own "stereo", 2, { - {0, 90, 0.5, 0.5, 1}, // side left - {1, 270, 0.5, 0.5, 1}, // side right + {0, 90, 0.5f, 0.5f, 1}, // side left + {1, 270, 0.5f, 0.5f, 1}, // side right {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, @@ -237,10 +237,10 @@ static cvar_t ambient_fade = {0, "ambient_fade", "100", "rate of volume fading w static cvar_t snd_noextraupdate = {0, "snd_noextraupdate", "0", "disables extra sound mixer calls that are meant to reduce the chance of sound breakup at very low framerates"}; static cvar_t snd_show = {0, "snd_show", "0", "shows some statistics about sound mixing"}; -// Default sound format is 48KHz, 16-bit, stereo +// Default sound format is 48KHz, 32bit float, stereo // (48KHz because a lot of onboard sound cards sucks at any other speed) static cvar_t snd_speed = {CVAR_SAVE, "snd_speed", "48000", "sound output frequency, in hertz"}; -static cvar_t snd_width = {CVAR_SAVE, "snd_width", "2", "sound output precision, in bytes (1 and 2 supported)"}; +static cvar_t snd_width = {CVAR_SAVE, "snd_width", "4", "sound output precision, in bytes - 1 = 8bit, 2 = 16bit, 4 = 32bit float"}; static cvar_t snd_channels = {CVAR_SAVE, "snd_channels", "2", "number of channels for the sound output (2 for stereo; up to 8 supported for 3D sound)"}; static cvar_t snd_startloopingsounds = {0, "snd_startloopingsounds", "1", "whether to start sounds that would loop (you want this to be 1); existing sounds are not affected"}; @@ -325,7 +325,7 @@ static void S_SoundList_f (void) { unsigned int size; - size = sfx->memsize; + size = (unsigned int)sfx->memsize; Con_Printf ("%c%c%c(%5iHz %2db %6s) %8i : %s\n", (sfx->loopstart < sfx->total_length) ? 'L' : ' ', (sfx->flags & SFXFLAG_STREAMED) ? 'S' : ' ', @@ -371,77 +371,6 @@ int S_GetSoundChannels(void) } -static qboolean S_ChooseCheaperFormat (snd_format_t* format, qboolean fixed_speed, qboolean fixed_width, qboolean fixed_channels) -{ - static const snd_format_t thresholds [] = - { - // speed width channels - { SND_MIN_SPEED, SND_MIN_WIDTH, SND_MIN_CHANNELS }, - { 11025, 1, 2 }, - { 22050, 2, 2 }, - { 44100, 2, 2 }, - { 48000, 2, 6 }, - { 96000, 2, 6 }, - { SND_MAX_SPEED, SND_MAX_WIDTH, SND_MAX_CHANNELS }, - }; - const unsigned int nb_thresholds = sizeof(thresholds) / sizeof(thresholds[0]); - unsigned int speed_level, width_level, channels_level; - - // If we have reached the minimum values, there's nothing more we can do - if ((format->speed == thresholds[0].speed || fixed_speed) && - (format->width == thresholds[0].width || fixed_width) && - (format->channels == thresholds[0].channels || fixed_channels)) - return false; - - // Check the min and max values - #define CHECK_BOUNDARIES(param) \ - if (format->param < thresholds[0].param) \ - { \ - format->param = thresholds[0].param; \ - return true; \ - } \ - if (format->param > thresholds[nb_thresholds - 1].param) \ - { \ - format->param = thresholds[nb_thresholds - 1].param; \ - return true; \ - } - CHECK_BOUNDARIES(speed); - CHECK_BOUNDARIES(width); - CHECK_BOUNDARIES(channels); - #undef CHECK_BOUNDARIES - - // Find the level of each parameter - #define FIND_LEVEL(param) \ - param##_level = 0; \ - while (param##_level < nb_thresholds - 1) \ - { \ - if (format->param <= thresholds[param##_level].param) \ - break; \ - \ - param##_level++; \ - } - FIND_LEVEL(speed); - FIND_LEVEL(width); - FIND_LEVEL(channels); - #undef FIND_LEVEL - - // Decrease the parameter with the highest level to the previous level - if (channels_level >= speed_level && channels_level >= width_level && !fixed_channels) - { - format->channels = thresholds[channels_level - 1].channels; - return true; - } - if (speed_level >= width_level && !fixed_speed) - { - format->speed = thresholds[speed_level - 1].speed; - return true; - } - - format->width = thresholds[width_level - 1].width; - return true; -} - - #define SWAP_LISTENERS(l1, l2, tmpl) { tmpl = (l1); (l1) = (l2); (l2) = tmpl; } static void S_SetChannelLayout (void) @@ -615,7 +544,7 @@ void S_Startup (void) chosen_fmt.speed = atoi (com_argv[i + 1]); fixed_speed = true; } -// COMMANDLINEOPTION: Sound: -sndbits chooses 8 bit or 16 bit sound output +// COMMANDLINEOPTION: Sound: -sndbits chooses 8 bit or 16 bit or 32bit float sound output i = COM_CheckParm ("-sndbits"); if (0 < i && i < com_argc - 1) { @@ -655,6 +584,11 @@ void S_Startup (void) chosen_fmt.width = SND_MIN_WIDTH; fixed_width = false; } + else if (chosen_fmt.width == 3) + { + chosen_fmt.width = 4; + fixed_width = false; + } else if (chosen_fmt.width > SND_MAX_WIDTH) { chosen_fmt.width = SND_MAX_WIDTH; @@ -675,39 +609,12 @@ void S_Startup (void) // create the sound buffer used for sumitting the samples to the plaform-dependent module if (!simsound) { - snd_format_t suggest_fmt; - qboolean accepted; - - accepted = false; - do - { - Con_Printf("S_Startup: initializing sound output format: %dHz, %d bit, %d channels...\n", - chosen_fmt.speed, chosen_fmt.width * 8, - chosen_fmt.channels); - - memset(&suggest_fmt, 0, sizeof(suggest_fmt)); - accepted = SndSys_Init(&chosen_fmt, &suggest_fmt); - - if (!accepted) - { - Con_Printf("S_Startup: sound output initialization FAILED\n"); - - // If the module is suggesting another one - if (suggest_fmt.speed != 0) - { - memcpy(&chosen_fmt, &suggest_fmt, sizeof(chosen_fmt)); - Con_Printf (" Driver has suggested %dHz, %d bit, %d channels. Retrying...\n", - suggest_fmt.speed, suggest_fmt.width * 8, - suggest_fmt.channels); - } - // Else, try to find a less resource-demanding format - else if (!S_ChooseCheaperFormat (&chosen_fmt, fixed_speed, fixed_width, fixed_channels)) - break; - } - } while (!accepted); + Con_Printf("S_Startup: initializing sound output format: %dHz, %d bit, %d channels...\n", + chosen_fmt.speed, + chosen_fmt.width, + chosen_fmt.channels); - // If we haven't found a suitable format - if (!accepted) + if (!SndSys_Init(&chosen_fmt)) { Con_Print("S_Startup: SndSys_Init failed.\n"); sound_spatialized = false; @@ -1491,7 +1398,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) if (snd_spatialization_occlusion.integer) { if(snd_spatialization_occlusion.integer & 1) - if(listener_pvs) + if(listener_pvs && cl.worldmodel) { int cluster = cl.worldmodel->brush.PointInLeaf(cl.worldmodel, ch->origin)->clusterindex; if(cluster >= 0 && cluster < 8 * listener_pvsbytes && !CHECKPVSBIT(listener_pvs, cluster)) @@ -1500,7 +1407,7 @@ static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) if(snd_spatialization_occlusion.integer & 2) if(!occluded) - if(cl.worldmodel && cl.worldmodel->brush.TraceLineOfSight && !cl.worldmodel->brush.TraceLineOfSight(cl.worldmodel, listener_origin, ch->origin)) + if(cl.worldmodel && cl.worldmodel->brush.TraceLineOfSight && !cl.worldmodel->brush.TraceLineOfSight(cl.worldmodel, listener_origin, ch->origin, ch->origin, ch->origin)) occluded = true; } if(occluded)