Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
slider_decibels.qc File Reference
#include "slider_decibels.qh"
Include dependency graph for slider_decibels.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float fromDecibelOfSquare (float f, float mi)
entity makeXonoticDecibelsSlider (float theValueMin, float theValueMax, float theValueStep, string theCvar)
entity makeXonoticDecibelsSlider_T (float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
 TEST (XonoticDecibelsSlider, SoundTest)
float toDecibelOfSquare (float f, float mi)
void XonoticDecibelsSlider_loadCvars (entity me)
void XonoticDecibelsSlider_saveCvars (entity me)
string XonoticDecibelsSlider_valueToText (entity me, float v)

Variables

float autocvar_menu_snd_sliderscale
bool autocvar_test_XonoticDecibelsSlider = false

Function Documentation

◆ fromDecibelOfSquare()

float fromDecibelOfSquare ( float f,
float mi )

Definition at line 17 of file slider_decibels.qc.

18{
19 float A = log(10) / 20; // note: about 0.115; inverse: about 8.686
20 if(mi != 0)
21 {
22 // linear scale part
23 float t = 1 / A + mi;
24 float u = exp(1 + A * mi);
25 if(f <= t)
26 return u * ((f - mi) / (t - mi));
27 }
28 return exp(A * f);
29}
float log(float f)
float exp(float e)
Definition mathlib.qc:74

References exp(), and log().

Referenced by TEST(), XonoticDecibelsSlider_loadCvars(), XonoticDecibelsSlider_saveCvars(), and XonoticDecibelsSlider_valueToText().

◆ makeXonoticDecibelsSlider()

entity makeXonoticDecibelsSlider ( float theValueMin,
float theValueMax,
float theValueStep,
string theCvar )

Definition at line 37 of file slider_decibels.qc.

38{
39 return makeXonoticDecibelsSlider_T(theValueMin, theValueMax, theValueStep, theCvar, string_null);
40}
string string_null
Definition nil.qh:9
entity makeXonoticDecibelsSlider_T(float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)

References entity(), makeXonoticDecibelsSlider_T(), and string_null.

Referenced by XonoticDecibelsSlider::valueToText().

◆ makeXonoticDecibelsSlider_T()

entity makeXonoticDecibelsSlider_T ( float theValueMin,
float theValueMax,
float theValueStep,
string theCvar,
string theTooltip )

Definition at line 31 of file slider_decibels.qc.

32{
34 me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar, theTooltip);
35 return me;
36}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:117

References entity(), and NEW.

Referenced by makeXonoticDecibelsSlider(), XonoticDecibelsSlider::valueToText(), and XonoticAudioSettingsTab_fill().

◆ TEST()

TEST ( XonoticDecibelsSlider ,
SoundTest  )

Definition at line 85 of file slider_decibels.qc.

86{
88 for (int i = -400; i < 0; ++i)
89 {
90 float db = i * 0.1;
91 float v = fromDecibelOfSquare(db, -40);
92 float dbv = toDecibelOfSquare(v, -40);
93 float d = dbv - db;
94 LOG_INFOF("%f -> %f -> %f (diff: %f)", db, v, dbv, d);
95 EXPECT_LT(fabs(d), 0.02);
96 }
97 SUCCEED();
98}
#define LOG_INFOF(...)
Definition log.qh:66
float fabs(float f)
bool autocvar_test_XonoticDecibelsSlider
float fromDecibelOfSquare(float f, float mi)
float toDecibelOfSquare(float f, float mi)
#define SUCCEED()
Must be present at the end of a test.
Definition test.qh:15
#define EXPECT_LT(val1, val2)
Definition test.qh:55

References autocvar_test_XonoticDecibelsSlider, EXPECT_LT, fabs(), fromDecibelOfSquare(), LOG_INFOF, SUCCEED, and toDecibelOfSquare().

◆ toDecibelOfSquare()

float toDecibelOfSquare ( float f,
float mi )

Definition at line 3 of file slider_decibels.qc.

4{
5 float A = log(10) / 20; // note: about 0.115; inverse: about 8.686
6 if(mi != 0)
7 {
8 // linear scale part
9 float t = 1 / A + mi;
10 float u = exp(1 + A * mi);
11 if(f <= u)
12 return mi + (t - mi) * (f / u);
13 }
14 return log(f) / A;
15}

References exp(), and log().

Referenced by TEST(), XonoticDecibelsSlider_loadCvars(), and XonoticDecibelsSlider_valueToText().

◆ XonoticDecibelsSlider_loadCvars()

void XonoticDecibelsSlider_loadCvars ( entity me)

Definition at line 41 of file slider_decibels.qc.

42{
43 float v;
44
45 if (!me.controlledCvar)
46 return;
47
48 v = cvar(me.controlledCvar);
49
50 // snapping
51 if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin))
52 Slider_setValue(me, me.valueMax, false);
53 else
54 Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep), false);
55}
void Slider_setValue(entity me, float val, bool allowAnim)
Definition slider.qc:40
float cvar(string name)
float floor(float f)

References cvar(), entity(), floor(), fromDecibelOfSquare(), Slider_setValue(), and toDecibelOfSquare().

◆ XonoticDecibelsSlider_saveCvars()

void XonoticDecibelsSlider_saveCvars ( entity me)

Definition at line 56 of file slider_decibels.qc.

57{
58 if (!me.controlledCvar)
59 return;
60
61 if(me.value > me.valueMax - 0.5 * me.valueStep)
62 cvar_set(me.controlledCvar, ftos(fromDecibelOfSquare(me.valueMax, me.valueMin)));
63 else
64 cvar_set(me.controlledCvar, ftos(fromDecibelOfSquare(me.value, me.valueMin)));
65}
void cvar_set(string name, string value)
string ftos(float f)

References cvar_set(), entity(), fromDecibelOfSquare(), and ftos().

◆ XonoticDecibelsSlider_valueToText()

string XonoticDecibelsSlider_valueToText ( entity me,
float v )

Definition at line 68 of file slider_decibels.qc.

69{
70 if(v > me.valueMax - 0.5 * me.valueStep)
71 return CTX(_("VOL^MAX"));
72 else if(v <= me.valueMin)
73 return CTX(_("VOL^OFF"));
74 else if(autocvar_menu_snd_sliderscale == 3) // fake percent scale
75 return ftos_decimals_percentage((v - me.valueMin) / (me.valueMax - me.valueMin), 0);
76 else if(autocvar_menu_snd_sliderscale == 2) // 0..10 scale
77 return sprintf("%.1f", (v - me.valueMin) / (me.valueMax - me.valueMin) * 10);
78 else if(autocvar_menu_snd_sliderscale == 1) // real percent scale
79 return ftos_decimals_percentage(fromDecibelOfSquare(v, me.valueMin), 2);
80 else // decibel scale
81 return sprintf(_("%s dB"), ftos_decimals(toDecibelOfSquare(fromDecibelOfSquare(v, me.valueMin), 0), me.valueDigits));
82}
ERASEABLE string CTX(string s)
Definition i18n.qh:45
float autocvar_menu_snd_sliderscale
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
Definition string.qh:469
ERASEABLE string ftos_decimals_percentage(float number, int decimals)
converts a percentage to a string with the indicated number of decimals
Definition string.qh:480

References autocvar_menu_snd_sliderscale, CTX(), entity(), fromDecibelOfSquare(), ftos_decimals(), ftos_decimals_percentage(), and toDecibelOfSquare().

Variable Documentation

◆ autocvar_menu_snd_sliderscale

float autocvar_menu_snd_sliderscale

Definition at line 67 of file slider_decibels.qc.

Referenced by XonoticDecibelsSlider_valueToText().

◆ autocvar_test_XonoticDecibelsSlider

bool autocvar_test_XonoticDecibelsSlider = false

Definition at line 84 of file slider_decibels.qc.

Referenced by TEST().