Skip to content

Commit b82393a

Browse files
committed
engine: Inline conversion functions for better optimizations
1 parent 997debd commit b82393a

3 files changed

Lines changed: 22 additions & 31 deletions

File tree

engine/audio/private/snd_dma.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,32 +1838,6 @@ ConVar snd_showstart( "snd_showstart", "0", FCVAR_CHEAT ); // showstart always s
18381838

18391839
#define SND_GAIN_PLAYER_WEAPON_DB 2.0F // increase player weapon gain by N dB
18401840

1841-
// dB = 20 log (amplitude/32768) 0 to -90.3dB
1842-
// amplitude = 32768 * 10 ^ (dB/20) 0 to +/- 32768
1843-
// gain = amplitude/32768 0 to 1.0
1844-
1845-
float Gain_To_dB ( float gain )
1846-
{
1847-
float dB = 20 * logf ( gain );
1848-
return dB;
1849-
}
1850-
1851-
float dB_To_Gain ( float dB )
1852-
{
1853-
float gain = powf (10, dB / 20.0F);
1854-
return gain;
1855-
}
1856-
1857-
float Gain_To_Amplitude ( float gain )
1858-
{
1859-
return gain * 32768;
1860-
}
1861-
1862-
float Amplitude_To_Gain ( float amplitude )
1863-
{
1864-
return amplitude / 32768;
1865-
}
1866-
18671841
soundlevel_t SND_GetSndlvl ( channel_t *pchannel )
18681842
{
18691843
return DIST_MULT_TO_SNDLVL( pchannel->dist_mult );

engine/audio/private/snd_dsp.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ extern ConVar das_debug;
4747
void DSP_ReleaseMemory( void );
4848
bool DSP_LoadPresetFile( void );
4949

50-
extern float Gain_To_dB ( float gain );
51-
extern float dB_To_Gain ( float dB );
52-
extern float Gain_To_Amplitude ( float gain );
53-
extern float Amplitude_To_Gain ( float amplitude );
54-
5550
extern bool g_bdas_room_init;
5651
extern bool g_bdas_init_nodes;
5752

engine/audio/private/snd_mix_buf.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,26 @@ constexpr inline short CLIP(T x) noexcept {
120120
return x > 32767 ? 32767 : (x < -32767 ? -32767 : static_cast<short>(x));
121121
}
122122

123+
// dB = 20 log (amplitude/32768) 0 to -90.3dB
124+
// amplitude = 32768 * 10 ^ (dB/20) 0 to +/- 32768
125+
// gain = amplitude/32768 0 to 1.0
126+
[[nodiscard]] inline float Gain_To_dB(float gain) {
127+
float dB = 20.0f * logf ( gain );
128+
return dB;
129+
}
130+
131+
[[nodiscard]] inline float dB_To_Gain(float dB) {
132+
float gain = powf (10.0f, dB / 20.0f);
133+
return gain;
134+
}
135+
136+
[[nodiscard]] constexpr inline float Gain_To_Amplitude(float gain) {
137+
return gain * 32768.0f;
138+
}
139+
140+
[[nodiscard]] constexpr inline float Amplitude_To_Gain(float amplitude) {
141+
return amplitude / 32768.0f;
142+
}
143+
144+
123145
#endif // SND_MIX_BUF_H

0 commit comments

Comments
 (0)