Add mixer rate to the extras menu, and add snd_restart command in order to be able to apply it instantly.

This commit is contained in:
Shpoike 2021-10-14 06:17:25 +01:00
parent 0955d04426
commit f64bd5e9d6
2 changed files with 56 additions and 1 deletions

View File

@ -1639,6 +1639,7 @@ static enum extras_e
EXTRAS_NETEXTENSIONS,
EXTRAS_QCEXTENSIONS,
EXTRAS_CLASSICPARTICLES,
EXTRAS_AUDIORATE,
EXTRAS_ITEMS
} extras_cursor;
@ -1742,6 +1743,10 @@ static void M_Extras_AdjustSliders (int dir)
case EXTRAS_CLASSICPARTICLES:
Cvar_SetValueQuick (&r_particles, (r_particles.value==1)?2:1);
break;
case EXTRAS_AUDIORATE:
Cvar_SetValueQuick (&snd_mixspeed, (snd_mixspeed.value==48000)?44100:48000);
Cbuf_AddText("\nsnd_restart\n");
break;
case EXTRAS_ITEMS: //not a real option
break;
}
@ -1842,6 +1847,16 @@ void M_Extras_Draw (void)
M_Print (220, y, "?!?");
break;
case EXTRAS_AUDIORATE:
M_Print (16, y, " Audio Rate");
if (snd_mixspeed.value == 48000)
M_Print (220, y, "48000 hz (DVD)");
else if (r_particles.value == 1)
M_Print (220, y, "44100 hz (CD)");
else
M_Print (220, y, va("%i hz", (int)snd_mixspeed.value));
break;
case EXTRAS_ITEMS: //unreachable.
break;
}

View File

@ -44,6 +44,7 @@ static void S_Play (void);
static void S_PlayVol (void);
static void S_SoundList (void);
static void S_Update_ (void);
static void GetSoundtime (void);
void S_StopAllSounds (qboolean clear);
static void S_StopAllSoundsC (void);
@ -91,7 +92,7 @@ cvar_t precache = {"precache", "1", CVAR_NONE};
cvar_t loadas8bit = {"loadas8bit", "0", CVAR_NONE};
cvar_t sndspeed = {"sndspeed", "11025", CVAR_NONE};
cvar_t snd_mixspeed = {"snd_mixspeed", "44100", CVAR_NONE};
cvar_t snd_mixspeed = {"snd_mixspeed", "44100", CVAR_ARCHIVE};
#if defined(_WIN32)
#define SND_FILTERQUALITY_DEFAULT "5"
@ -165,8 +166,46 @@ void S_Startup (void)
(shm->channels == 2) ? "stereo" : "mono",
shm->speed);
}
GetSoundtime();
paintedtime = soundtime;
}
/*
snd_restart console command
*/
void S_Restart_f(void)
{
sfx_t *s;
size_t i;
int oldspeed = shm->speed;
if (!snd_initialized)
return;
S_Shutdown();
S_Startup ();
S_CodecInit ();
paintedtime = soundtime;
//we changed the sound time and probably the rates too...
//any timing of sounds will be way off. so lets just kill any currently playing sounds
//(note that this lazy way of killing them will ensure that looping sounds restart)
for (i = 0; i < total_channels; i++)
{
snd_channels[i].pos = 0;
snd_channels[i].end = 0;
}
s_rawend = 0; //clear any music too...
//reload any sounds if their rates changed.
if (shm->speed != oldspeed)
{
for (i = 0; i < num_sfx; i++)
{
s = &known_sfx[i];
if (s->cache.data)
Cache_Free(&s->cache, false);
}
}
}
/*
================
@ -210,6 +249,7 @@ void S_Init (void)
Cmd_AddCommand("stopsound", S_StopAllSoundsC);
Cmd_AddCommand("soundlist", S_SoundList);
Cmd_AddCommand("soundinfo", S_SoundInfo_f);
Cmd_AddCommand("snd_restart", S_Restart_f);
i = COM_CheckParm("-sndspeed");
if (i && i < com_argc-1)