Cabbage Logo
Back to Cabbage Site

Eqfil gain factor vs decibels?

I’m making a distance knob for a plugin and did a graph interpolation of the proximity effect.

I’m using eqfil in one of the lines:
http://www.csounds.com/manual/html/eqfil.html

Now my question is: how does the gain factor kgain relate to decibels for compatible mapping?
If my understanding is correct, 1 is 0 decibels up or down, and 0 is -24 or -infinity dB?
I need to go from 0 dB subtracted to - 17-ish dB.

Good question. I’m afraid I don’t have an answer for you. You could convert the amplitude factor using the dbamp opcode, where 0 to 1 is mapped as -40dB to 0dB. But I think this will only give a ball-park figure. Maybe that’s enough? For example, a value of .9 would represent a 1db reduction, whereas .5 is a 6dB reduction.

I’m going to check.
I’ll keep you posted.

1 Like

took this interpolation from this graph

the approximation is already great, the sound starts sounding roomy around 0.5 meter distance.
But I should know exactly the db reduction like a regular eq plugin.

image bounds(0, 0, 1300, 688) channel(“background”), file(“Acoustic-Treatment-for-Home-Studio_Bass-Trap.jpg”)
form caption(“Sampled Drums GUI”) size(1300, 688), colour(“black”), pluginID(“SMo1”)
groupbox bounds(0, 0, 435, 700), , alpha(0.6) channel(“groupbox3”)
groupbox bounds(0, 114, 435, 110), , alpha(0.4) channel(“groupbox4”)
groupbox bounds(0, 322, 435, 276), , alpha(0.4) channel(“groupbox5”)
groupbox bounds(0, 322, 218, 276), , alpha(0.15) channel(“groupbox6”)

rslider bounds(2, 116, 105, 101), channel(“att”), range(0, 1, 0.01, 1, 0.01), text(“Attack”) valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) trackerColour(188, 136, 69, 255)
rslider bounds(108, 116, 105, 101), channel(“dec”), range(0, 1, 0.5, 1, 0.01), text(“Decay”) valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) trackerColour(188, 136, 69, 255)
rslider bounds(214, 116, 105, 101), channel(“sus”), range(0, 1, 0.5, 1, 0.01), text(“Sustain”) valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) trackerColour(188, 136, 69, 255)
rslider bounds(320, 116, 105, 101), channel(“rel”), range(0, 1, 0.5, 1, 0.01), text(“Release”) valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) trackerColour(188, 136, 69, 255)
vslider bounds(220, 317, 87, 271), channel(“room”), range(1, 100, 0, 1, 0.01) valueTextBox(1) text(“room (%)”) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) trackerColour(188, 136, 69, 255)
vslider bounds(10, 316, 89, 272) channel(“distance”) range(0.3, 1e+06, 500000, 1, 1) valueTextBox(1) text(“distance (cm)”) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) trackerColour(188, 136, 69, 255)
rslider bounds(80, 401, 89, 59), channel(“proximitycenter”), range(100, 200, 200, 1, 0.1), valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) popupText(“proximity center”)
rslider bounds(80, 485, 89, 59), channel(“airabsorption”), range(0, 100, 1, 1, 0.01), valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) popupText(“air absorption”)
rslider bounds(134, 444, 89, 59), channel(“proximitywidth”), range(0, 1000, 1000, 1, 0.1), valueTextBox(1) textColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) popupText(“proximitywidth”)

sr = 96000
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1

iAtt chnget “att”
iDec chnget “dec”
iSus chnget “sus”
iRel chnget “rel”
kdist chnget “distance” // kvalue between 2.5-5cm and max
kpc chnget “proximitycenter”
kres chnget “airabsorption”
kwidth chnget “proximitywidth”

kdB = (1.585699 - -17.16343)/(1 + (kdist/5.217269)^0.8339635)
kdB = kdB/17.16343

ain soundin “4mono.wav”

asig eqfil ain, kpc, kwidth, kdB // k-factor is adapter between distance to gain factor (negative) // anti proximity filter ----------- https://mynewmicrophone.com/proximity-effect/

kfco = 1854.15 + (20007.03 - 1854.15)/(1 + (kdist/3336.707)^1.275204)

asig rezzy asig, kfco, kres // mic distance low-pass filter ---- https://www.google.com/url?sa=i&url=https%3A%2F%2Fcodeandsound.wordpress.com%2F2014%2F08%2F21%2Fabsorption-of-sound-by-air-and-its-implementation-as-a-filter-part-1-theory%2F&psig=AOvVaw35gGCliI0F07QB34-iuP4c&ust=1650462530771000&source=images&cd=vfe&ved=0CA0QjhxqFwoTCIjttZ2ioPcCFQAAAAAdAAAAABAD

kEnv madsr iAtt, iDec, iSus, iRel

outs kEnv*asig

endin

;causes Csound to run for about 7000 years... f0 z ;Delay is in ms i 1 0 [60*60*24*7]

e

Is this how to paste the code?

I used the dbamp for a moment, but it’s not really what I’m looking for. More like a console of the spectrum. the values are now from 1 to 0. and I think this is the only value of reduction eqfil wants to take. Under 0 I’m hearing a db increase again. 1 no change being okay, but where between 1 and 0 is that 17.14 db.

To display code correctly paste it in, then select it all and hit the </> button at the top of the text editor.

I can ask Victor, who wrote the opcode. Leave it with me.

1 Like

From Victor:

The kgain control in eqfil is a scaler, so > 1 it amplifies and < 1 attenuates. The dB gain value is then just 20log10(kgain), so 0 = 1, 6 = 2, -6 = 0.5, etc.

So it would seem that you can work out the dB attenuation/boost using ampdb or dbamp?

Thanks for the formula

Slightly transformed the function:

kdB = (1.585699 - -17.16343)/(1 + (kdist/5.217269)^0.8339635)
kdB = (kdB/17.16343*0.86137916837) + 0.13862083163

using:

dB = 20¨*log(kdB)
<=> kdB = 10^(dB/20)
<=> kdB = 10^(dB/20)
<=> kdB = 0.13862083163
1 - 0.13862083163 = 0.86137916837

This will do, I think. Thank you for the input.