From: Rudolf Polzer Date: Wed, 12 Jun 2013 09:53:52 +0000 (+0200) Subject: decibel sliders: far left means zero (linear scaled part); menu_snd_sliderscale chang... X-Git-Tag: xonotic-v0.8.0~387^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=664311178a4a786b2d7fa1b7a0eff68e8ae186fc;p=xonotic%2Fxonotic-data.pk3dir.git decibel sliders: far left means zero (linear scaled part); menu_snd_sliderscale changes display of volume values --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 66ac0b20b..31fe29a1a 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1533,6 +1533,7 @@ set snd_soundradius 1200 set snd_softclip 1 set snd_maxchannelvolume 0 set snd_streaming_length 2 +seta menu_snd_sliderscale 0 "0: decibels; 1: linear percent; 2: 0..10 scale" seta menu_snd_attenuation_method 1 "Use exponential instead of linear falloff for sound attenuation" alias snd_attenuation_method_0 "set menu_snd_attenuation_method 0; set snd_soundradius 1200; set snd_attenuation_exponent 1; set snd_attenuation_decibel 0" // Quake default alias snd_attenuation_method_1 "set menu_snd_attenuation_method 1; set snd_soundradius 2400; set snd_attenuation_exponent 4; set snd_attenuation_decibel 0" // nice approximation for method 2 diff --git a/qcsrc/menu/xonotic/dialog_settings_audio.c b/qcsrc/menu/xonotic/dialog_settings_audio.c index 174873fe7..2fe175feb 100644 --- a/qcsrc/menu/xonotic/dialog_settings_audio.c +++ b/qcsrc/menu/xonotic/dialog_settings_audio.c @@ -24,17 +24,13 @@ void XonoticAudioSettingsTab_fill(entity me) me.TR(me); s = makeXonoticDecibelsSlider(-40, 0, 1, "mastervolume"); - me.TD(me, 1, 1, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Master:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Master:"))); me.TD(me, 1, 2, s); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "bgmvolume"); makeMulti(s, "snd_channel8volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Music:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Music:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); @@ -42,63 +38,49 @@ void XonoticAudioSettingsTab_fill(entity me) me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_staticvolume"); makeMulti(s, "snd_channel9volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, ZCTX(_("VOL^Ambient:")))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, ZCTX(_("VOL^Ambient:")))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel0volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Info:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Info:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel3volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Items:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Items:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel6volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Pain:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Pain:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel7volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Player:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Player:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel4volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Shots:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Shots:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); me.TR(me); me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel2volume"); - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Voice:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Voice:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); @@ -106,9 +88,7 @@ void XonoticAudioSettingsTab_fill(entity me) me.TDempty(me, 0.2); s = makeXonoticDecibelsSlider(-40, 0, 1, "snd_channel1volume"); makeMulti(s, "snd_channel5volume"); // @!#%'n Tuba - me.TD(me, 1, 0.8, e = makeXonoticSliderCheckBox(-1000000, 1, s, _("Weapons:"))); - if(s.value != e.savedValue) - e.savedValue = 0; // default + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Weapons:"))); me.TD(me, 1, 2, s); setDependentStringNotEqual(e, "mastervolume", "0"); setDependentStringNotEqual(s, "mastervolume", "0"); diff --git a/qcsrc/menu/xonotic/slider_decibels.c b/qcsrc/menu/xonotic/slider_decibels.c index 729bec006..6068c1c15 100644 --- a/qcsrc/menu/xonotic/slider_decibels.c +++ b/qcsrc/menu/xonotic/slider_decibels.c @@ -9,14 +9,32 @@ entity makeXonoticDecibelsSlider(float, float, float, string); #ifdef IMPLEMENTATION -float toDecibelOfSquare(float f) +float toDecibelOfSquare(float f, float mi) { - return 20.0 * log10(f); + float A = log(10) / 20; // note: about 0.115; inverse: about 8.686 + if(mi != 0) + { + // linear scale part + float t = 1 / A + mi; + float y = exp(1 + A * mi); + if(f <= y) + return mi + (t - mi) * (f / y); + } + return log(f) / A; } -float fromDecibelOfSquare(float f) +float fromDecibelOfSquare(float f, float mi) { - return pow(10, f / 20.0); + float A = log(10) / 20; // note: about 0.115; inverse: about 8.686 + if(mi != 0) + { + // linear scale part + float t = 1 / A + mi; + float y = exp(1 + A * mi); + if(f <= t) + return y * ((f - mi) / (t - mi)); + } + return exp(A * f); } entity makeXonoticDecibelsSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar) @@ -36,12 +54,10 @@ void XonoticDecibelsSlider_loadCvars(entity me) v = cvar(me.cvarName); // snapping - if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep)) + if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin)) Slider_setValue(me, me.valueMax); - else if(v < fromDecibelOfSquare(me.valueMin - 0.5 * me.valueStep)) - Slider_setValue(me, -1000000); // virtually infinite else - Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v) / me.valueStep) ); + Slider_setValue(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep) ); } void XonoticDecibelsSlider_saveCvars(entity me) { @@ -49,20 +65,24 @@ void XonoticDecibelsSlider_saveCvars(entity me) return; if(me.value > me.valueMax - 0.5 * me.valueStep) - cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.valueMax))); - else if(me.value < me.valueMin - 0.5 * me.valueStep) - cvar_set(me.cvarName, "0"); + cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.valueMax, me.valueMin))); else - cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.value))); + cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.value, me.valueMin))); } +float autocvar_menu_snd_sliderscale; string XonoticDecibelsSlider_valueToText(entity me, float v) { if(v > me.valueMax - 0.5 * me.valueStep) return CTX(_("VOL^MAX")); - else if(v < me.valueMin - 0.5 * me.valueStep) + else if(v <= me.valueMin) return CTX(_("VOL^OFF")); - return sprintf(_("%s dB"), SUPER(XonoticDecibelsSlider).valueToText(me, v)); + else if(autocvar_menu_snd_sliderscale == 2) // 0..10 scale + return sprintf(_("%.1f"), (v - me.valueMin) / (me.valueMax - me.valueMin) * 10); + else if(autocvar_menu_snd_sliderscale == 1) // percent scale + return sprintf(_("%.2f %%"), fromDecibelOfSquare(v, me.valueMin)); + else // decibel scale + return sprintf(_("%s dB"), ftos_decimals(toDecibelOfSquare(fromDecibelOfSquare(v, me.valueMin), 0), me.valueDigits)); } #endif