Browse Source

engine: client: sound: move dsp cvars to static allocation

pull/2/head
Alibek Omarov 2 years ago
parent
commit
05579927a5
  1. 186
      engine/client/s_dsp.c
  2. 1
      engine/client/sound.h

186
engine/client/s_dsp.c

@ -78,7 +78,7 @@ typedef struct dly_s @@ -78,7 +78,7 @@ typedef struct dly_s
int *lpdelayline;
} dly_t;
const sx_preset_t rgsxpre[] =
static const sx_preset_t rgsxpre[] =
{
// -------reverb-------- -------delay--------
// lp mod size refl rvblp delay feedback dlylp left
@ -115,7 +115,7 @@ const sx_preset_t rgsxpre[] = @@ -115,7 +115,7 @@ const sx_preset_t rgsxpre[] =
// 0x0045dca8 enginegl.exe
// SHA256: 42383d32cd712e59ee2c1bd78b7ba48814e680e7026c4223e730111f34a60d66
const sx_preset_t rgsxpre_hlalpha052[] =
static const sx_preset_t rgsxpre_hlalpha052[] =
{
// -------reverb-------- -------delay--------
// lp mod size refl rvblp delay feedback dlylp left
@ -150,51 +150,50 @@ const sx_preset_t rgsxpre_hlalpha052[] = @@ -150,51 +150,50 @@ const sx_preset_t rgsxpre_hlalpha052[] =
{ 0.0, 0.0, 0.001, 0.999, 0.0, 0.2, 0.8, 2.0, 0.05 }, // 28
};
const sx_preset_t *ptable = rgsxpre;
static const sx_preset_t *ptable = rgsxpre;
// cvars
convar_t *dsp_off; // disable dsp
convar_t *roomwater_type; // water room_type
convar_t *room_type; // current room type
convar_t *hisound; // DSP quality
static CVAR_DEFINE_AUTO( dsp_off, "0", FCVAR_ARCHIVE, "disable DSP processing" );
static CVAR_DEFINE_AUTO( dsp_coeff_table, "0", FCVAR_ARCHIVE, "select DSP coefficient table: 0 for release or 1 for alpha 0.52" );
static CVAR_DEFINE_AUTO( room_type, "0", 0, "current room type preset" );
static CVAR_DEFINE( roomwater_type, "waterroom_type", "14", 0, "water room type" );
static CVAR_DEFINE( hisound, "room_hires", "2", FCVAR_ARCHIVE, "dsp quality. 1 for 22k, 2 for 44k(recommended) and 3 for 96k" );
// underwater/special fx modulations
convar_t *sxmod_mod;
convar_t *sxmod_lowpass;
static CVAR_DEFINE( sxmod_mod, "room_mod", "0", 0, "stereo amptitude modulation for room" );
static CVAR_DEFINE( sxmod_lowpass, "room_lp", "0", 0, "for water fx, lowpass for entire room" );
// stereo delay(no feedback)
convar_t *sxste_delay; // straight left delay
static CVAR_DEFINE( sxste_delay, "room_left", "0", 0, "left channel delay time" );
// mono reverb
convar_t *sxrvb_lp; // lowpass
convar_t *sxrvb_feedback; // reverb decay. Higher -- longer
convar_t *sxrvb_size; // room size. Higher -- larger
static CVAR_DEFINE( sxrvb_lp, "room_rvblp", "1", 0, "reverb: low pass filtering level" );
static CVAR_DEFINE( sxrvb_feedback, "room_refl", "0", 0, "reverb: decay time" );
static CVAR_DEFINE( sxrvb_size, "room_size", "0", 0, "reverb: initial reflection size" );
// mono delay
convar_t *sxdly_lp; // lowpass
convar_t *sxdly_feedback; // cycles
convar_t *sxdly_delay; // current delay in seconds
convar_t *dsp_room; // for compability
static CVAR_DEFINE( sxdly_lp, "room_dlylp", "1", 0, "mono delay: low pass filtering level" );
static CVAR_DEFINE( sxdly_feedback, "room_feedback", "0.2", 0, "mono delay: decay time" );
static CVAR_DEFINE( sxdly_delay, "room_delay", "0.8", 0, "mono delay: delay time" );
convar_t *dsp_coeff_table; // use release or 0.52 style
int idsp_dma_speed;
static int idsp_dma_speed;
int idsp_room;
int room_typeprev;
static int room_typeprev;
// routines
int sxamodl, sxamodr; // amplitude modulation values
int sxamodlt, sxamodrt; // modulation targets
int sxmod1cur, sxmod2cur;
int sxmod1, sxmod2;
int sxhires;
static int sxamodl, sxamodr; // amplitude modulation values
static int sxamodlt, sxamodrt; // modulation targets
static int sxmod1cur, sxmod2cur;
static int sxmod1, sxmod2;
static int sxhires;
portable_samplepair_t *paintto = NULL;
static portable_samplepair_t *paintto = NULL;
dly_t rgsxdly[MAXDLY]; // stereo is last
int rgsxlp[MAXLP];
static dly_t rgsxdly[MAXDLY]; // stereo is last
static int rgsxlp[MAXLP];
void SX_Profiling_f( void );
static void SX_Profiling_f( void );
/*
============
@ -202,14 +201,12 @@ SX_ReloadRoomFX @@ -202,14 +201,12 @@ SX_ReloadRoomFX
============
*/
void SX_ReloadRoomFX( void )
static void SX_ReloadRoomFX( void )
{
if( !dsp_room ) return; // not initialized
SetBits( sxste_delay->flags, FCVAR_CHANGED );
SetBits( sxrvb_feedback->flags, FCVAR_CHANGED );
SetBits( sxdly_delay->flags, FCVAR_CHANGED );
SetBits( room_type->flags, FCVAR_CHANGED );
SetBits( sxste_delay.flags, FCVAR_CHANGED );
SetBits( sxrvb_feedback.flags, FCVAR_CHANGED );
SetBits( sxdly_delay.flags, FCVAR_CHANGED );
SetBits( room_type.flags, FCVAR_CHANGED );
}
/*
@ -227,36 +224,33 @@ void SX_Init( void ) @@ -227,36 +224,33 @@ void SX_Init( void )
sxamodr = sxamodl = sxamodrt = sxamodlt = 255;
idsp_dma_speed = SOUND_11k;
hisound = Cvar_Get( "room_hires", "2", FCVAR_ARCHIVE, "dsp quality. 1 for 22k, 2 for 44k(recommended) and 3 for 96k" );
Cvar_RegisterVariable( &hisound );
sxhires = 2;
sxmod1cur = sxmod1 = 350 * ( idsp_dma_speed / SOUND_11k );
sxmod2cur = sxmod2 = 450 * ( idsp_dma_speed / SOUND_11k );
dsp_off = Cvar_Get( "dsp_off", "0", FCVAR_ARCHIVE, "disable DSP processing" );
dsp_coeff_table = Cvar_Get( "dsp_coeff_table", "0", FCVAR_ARCHIVE, "select DSP coefficient table: 0 for release or 1 for alpha 0.52" );
Cvar_RegisterVariable( &dsp_off );
Cvar_RegisterVariable( &dsp_coeff_table );
roomwater_type = Cvar_Get( "waterroom_type", "14", 0, "water room type" );
room_type = Cvar_Get( "room_type", "0", 0, "current room type preset" );
Cvar_RegisterVariable( &roomwater_type );
Cvar_RegisterVariable( &room_type );
sxmod_lowpass = Cvar_Get( "room_lp", "0", 0, "for water fx, lowpass for entire room" );
sxmod_mod = Cvar_Get( "room_mod", "0", 0, "stereo amptitude modulation for room" );
Cvar_RegisterVariable( &sxmod_lowpass );
Cvar_RegisterVariable( &sxmod_mod );
sxrvb_size = Cvar_Get( "room_size", "0", 0, "reverb: initial reflection size" );
sxrvb_feedback = Cvar_Get( "room_refl", "0", 0, "reverb: decay time" );
sxrvb_lp = Cvar_Get( "room_rvblp", "1", 0, "reverb: low pass filtering level" );
Cvar_RegisterVariable( &sxrvb_size );
Cvar_RegisterVariable( &sxrvb_feedback );
Cvar_RegisterVariable( &sxrvb_lp );
sxdly_delay = Cvar_Get( "room_delay", "0.8", 0, "mono delay: delay time" );
sxdly_feedback = Cvar_Get( "room_feedback", "0.2", 0, "mono delay: decay time" );
sxdly_lp = Cvar_Get( "room_dlylp", "1", 0, "mono delay: low pass filtering level" );
Cvar_RegisterVariable( &sxdly_delay );
Cvar_RegisterVariable( &sxdly_feedback );
Cvar_RegisterVariable( &sxdly_lp );
sxste_delay = Cvar_Get( "room_left", "0", 0, "left channel delay time" );
Cvar_RegisterVariable( &sxste_delay );
Cmd_AddCommand( "dsp_profile", SX_Profiling_f, "dsp stress-test, first argument is room_type" );
// for compability
dsp_room = room_type;
SX_ReloadRoomFX();
}
@ -267,7 +261,7 @@ DLY_Free @@ -267,7 +261,7 @@ DLY_Free
Free memory allocated for DSP
===========
*/
void DLY_Free( int idelay )
static void DLY_Free( int idelay )
{
Assert( idelay >= 0 && idelay < MAXDLY );
@ -303,7 +297,7 @@ DLY_Init @@ -303,7 +297,7 @@ DLY_Init
Initialize dly
===========
*/
int DLY_Init( int idelay, float delay )
static int DLY_Init( int idelay, float delay )
{
dly_t *cur;
@ -355,12 +349,12 @@ DLY_CheckNewStereoDelayVal @@ -355,12 +349,12 @@ DLY_CheckNewStereoDelayVal
Update stereo processor settings if we are in new room
=============
*/
void DLY_CheckNewStereoDelayVal( void )
static void DLY_CheckNewStereoDelayVal( void )
{
dly_t *const dly = &rgsxdly[STEREODLY];
float delay = sxste_delay->value;
float delay = sxste_delay.value;
if( !FBitSet( sxste_delay->flags, FCVAR_CHANGED ))
if( !FBitSet( sxste_delay.flags, FCVAR_CHANGED ))
return;
if( delay == 0 )
@ -403,7 +397,7 @@ DLY_DoStereoDelay @@ -403,7 +397,7 @@ DLY_DoStereoDelay
Do stereo processing
=============
*/
void DLY_DoStereoDelay( int count )
static void DLY_DoStereoDelay( int count )
{
int delay, samplexf;
dly_t *const dly = &rgsxdly[STEREODLY];
@ -468,12 +462,12 @@ DLY_CheckNewDelayVal @@ -468,12 +462,12 @@ DLY_CheckNewDelayVal
Update delay processor settings if we are in new room
=============
*/
void DLY_CheckNewDelayVal( void )
static void DLY_CheckNewDelayVal( void )
{
float delay = sxdly_delay->value;
float delay = sxdly_delay.value;
dly_t *const dly = &rgsxdly[MONODLY];
if( FBitSet( sxdly_delay->flags, FCVAR_CHANGED ))
if( FBitSet( sxdly_delay.flags, FCVAR_CHANGED ))
{
if( delay == 0 )
{
@ -503,8 +497,8 @@ void DLY_CheckNewDelayVal( void ) @@ -503,8 +497,8 @@ void DLY_CheckNewDelayVal( void )
}
}
dly->lp = sxdly_lp->value;
dly->delayfeedback = 255 * sxdly_feedback->value;
dly->lp = sxdly_lp.value;
dly->delayfeedback = 255 * sxdly_feedback.value;
}
/*
@ -514,7 +508,7 @@ DLY_DoDelay @@ -514,7 +508,7 @@ DLY_DoDelay
Do delay processing
=============
*/
void DLY_DoDelay( int count )
static void DLY_DoDelay( int count )
{
dly_t *const dly = &rgsxdly[MONODLY];
portable_samplepair_t *paint = paintto;
@ -565,7 +559,7 @@ RVB_SetUpDly @@ -565,7 +559,7 @@ RVB_SetUpDly
Set up dly for reverb
===========
*/
void RVB_SetUpDly( int pos, float delay, int kmod )
static void RVB_SetUpDly( int pos, float delay, int kmod )
{
int samples;
@ -601,13 +595,13 @@ RVB_CheckNewReverbVal @@ -601,13 +595,13 @@ RVB_CheckNewReverbVal
Update reverb settings if we are in new room
===========
*/
void RVB_CheckNewReverbVal( void )
static void RVB_CheckNewReverbVal( void )
{
dly_t *const dly1 = &rgsxdly[REVERBPOS];
dly_t *const dly2 = &rgsxdly[REVERBPOS + 1];
float delay = sxrvb_size->value;
float delay = sxrvb_size.value;
if( FBitSet( sxrvb_size->flags, FCVAR_CHANGED ))
if( FBitSet( sxrvb_size.flags, FCVAR_CHANGED ))
{
if( delay == 0.0f )
{
@ -616,13 +610,13 @@ void RVB_CheckNewReverbVal( void ) @@ -616,13 +610,13 @@ void RVB_CheckNewReverbVal( void )
}
else
{
RVB_SetUpDly( REVERBPOS, sxrvb_size->value, 500 );
RVB_SetUpDly( REVERBPOS+1, sxrvb_size->value * 0.71f, 700 );
RVB_SetUpDly( REVERBPOS, sxrvb_size.value, 500 );
RVB_SetUpDly( REVERBPOS+1, sxrvb_size.value * 0.71f, 700 );
}
}
dly1->lp = dly2->lp = sxrvb_lp->value;
dly1->delayfeedback = dly2->delayfeedback = (int)(255 * sxrvb_feedback->value);
dly1->lp = dly2->lp = sxrvb_lp.value;
dly1->delayfeedback = dly2->delayfeedback = (int)(255 * sxrvb_feedback.value);
}
/*
@ -632,7 +626,7 @@ RVB_DoReverbForOneDly @@ -632,7 +626,7 @@ RVB_DoReverbForOneDly
Do reverberation for one dly
===========
*/
int RVB_DoReverbForOneDly( dly_t *dly, const int vlr, const portable_samplepair_t *samplepair )
static int RVB_DoReverbForOneDly( dly_t *dly, const int vlr, const portable_samplepair_t *samplepair )
{
int delay;
int samplexf;
@ -706,7 +700,7 @@ RVB_DoReverb @@ -706,7 +700,7 @@ RVB_DoReverb
Do reverberation processing
===========
*/
void RVB_DoReverb( int count )
static void RVB_DoReverb( int count )
{
dly_t *const dly1 = &rgsxdly[REVERBPOS];
dly_t *const dly2 = &rgsxdly[REVERBPOS+1];
@ -723,7 +717,7 @@ void RVB_DoReverb( int count ) @@ -723,7 +717,7 @@ void RVB_DoReverb( int count )
voutm = RVB_DoReverbForOneDly( dly1, vlr, paint );
voutm += RVB_DoReverbForOneDly( dly2, vlr, paint );
if( dsp_coeff_table->value == 1.0f )
if( dsp_coeff_table.value == 1.0f )
voutm /= 6; // alpha
else voutm = (11 * voutm) >> 6;
@ -739,18 +733,18 @@ RVB_DoAMod @@ -739,18 +733,18 @@ RVB_DoAMod
Do amplification modulation processing
===========
*/
void RVB_DoAMod( int count )
static void RVB_DoAMod( int count )
{
portable_samplepair_t *paint = paintto;
if( !sxmod_lowpass->value && !sxmod_mod->value )
if( !sxmod_lowpass.value && !sxmod_mod.value )
return;
for( ; count; count--, paint++ )
{
portable_samplepair_t res = *paint;
if( sxmod_lowpass->value )
if( sxmod_lowpass.value )
{
res.left = rgsxlp[0] + rgsxlp[1] + rgsxlp[2] + rgsxlp[3] + rgsxlp[4] + res.left;
res.right = rgsxlp[5] + rgsxlp[6] + rgsxlp[7] + rgsxlp[8] + rgsxlp[9] + res.right;
@ -772,7 +766,7 @@ void RVB_DoAMod( int count ) @@ -772,7 +766,7 @@ void RVB_DoAMod( int count )
rgsxlp[8] = rgsxlp[9];
}
if( sxmod_mod->value )
if( sxmod_mod.value )
{
if( --sxmod1cur < 0 )
sxmod1cur = sxmod1;
@ -814,7 +808,7 @@ DSP_Process @@ -814,7 +808,7 @@ DSP_Process
*/
void DSP_Process( int idsp, portable_samplepair_t *pbfront, int sampleCount )
{
if( dsp_off->value )
if( dsp_off.value )
return;
// don't process DSP while in menu
@ -852,12 +846,12 @@ CheckNewDspPresets @@ -852,12 +846,12 @@ CheckNewDspPresets
*/
void CheckNewDspPresets( void )
{
if( dsp_off->value != 0.0f )
if( dsp_off.value != 0.0f )
return;
if( FBitSet( dsp_coeff_table->flags, FCVAR_CHANGED ))
if( FBitSet( dsp_coeff_table.flags, FCVAR_CHANGED ))
{
switch( (int)dsp_coeff_table->value )
switch( (int)dsp_coeff_table.value )
{
case 0: // release
ptable = rgsxpre;
@ -873,20 +867,20 @@ void CheckNewDspPresets( void ) @@ -873,20 +867,20 @@ void CheckNewDspPresets( void )
SX_ReloadRoomFX();
room_typeprev = -1;
ClearBits( dsp_coeff_table->flags, FCVAR_CHANGED );
ClearBits( dsp_coeff_table.flags, FCVAR_CHANGED );
}
if( s_listener.waterlevel > 2 )
idsp_room = roomwater_type->value;
else idsp_room = room_type->value;
idsp_room = roomwater_type.value;
else idsp_room = room_type.value;
// don't pass invalid presets
idsp_room = bound( 0, idsp_room, MAX_ROOM_TYPES );
if( FBitSet( hisound->flags, FCVAR_CHANGED ))
if( FBitSet( hisound.flags, FCVAR_CHANGED ))
{
sxhires = hisound->value;
ClearBits( hisound->flags, FCVAR_CHANGED );
sxhires = hisound.value;
ClearBits( hisound.flags, FCVAR_CHANGED );
}
if( idsp_room == room_typeprev && idsp_room == 0 )
@ -915,15 +909,15 @@ void CheckNewDspPresets( void ) @@ -915,15 +909,15 @@ void CheckNewDspPresets( void )
DLY_CheckNewDelayVal( );
DLY_CheckNewStereoDelayVal();
ClearBits( sxrvb_size->flags, FCVAR_CHANGED );
ClearBits( sxdly_delay->flags, FCVAR_CHANGED );
ClearBits( sxste_delay->flags, FCVAR_CHANGED );
ClearBits( sxrvb_size.flags, FCVAR_CHANGED );
ClearBits( sxdly_delay.flags, FCVAR_CHANGED );
ClearBits( sxste_delay.flags, FCVAR_CHANGED );
}
void SX_Profiling_f( void )
static void SX_Profiling_f( void )
{
portable_samplepair_t testbuffer[512];
float oldroom = room_type->value;
float oldroom = room_type.value;
double start, end;
int i, calls;

1
engine/client/sound.h

@ -219,7 +219,6 @@ extern dma_t dma; @@ -219,7 +219,6 @@ extern dma_t dma;
extern convar_t s_musicvolume;
extern convar_t s_lerping;
extern convar_t *dsp_off;
extern convar_t s_test; // cvar to testify new effects
extern convar_t s_samplecount;
extern convar_t snd_mute_losefocus;

Loading…
Cancel
Save