Skip to content
Forum Archive

need help ... volume correction

10 posts

HuRriC4nE#

need help ... volume correction

Hello coders,

I'm just stuck here with a little problem.

The preset I'm just working on shall work with classic musik as well. The only problem with classic is the volume. Most recordings are very very quiet.

As all my variables are coming from getspec or getosc those are very small, too. What I need is a way to "correct" those parameters.

I tried this.

volume=volume*0.999+getspec(0.5,1,0)*0.001;

correction=1/(volume+0.001);
//"+0.001" shall avoid zero-division

actually this works well with normal music (since there are still great differences in volume - the new foo fighters album is a good example for VERY VERY LOUD).

but when i tried some piano recordings from Chopin (the "raindrop sonata" nothing really happens. Also Soundtracks are difficult.

The thing is the preset really can work on classic music.
It already works fine with pop music although i don't use the beatdetection in any way.
Classic musik doesn't have a beat actually so this could look good.

Maybe someone here did a volume correction already and can help me. I would be very happy.
jheriko#
you want to normalise the volume somehow... you can't do this instantaneously without simply destroying the signal. Consider the following 3 volume samples:

a b c d e f ...

You want to correct them somehow, so per frame you find 1 / (a + 0.001) for the first one, 1 / (b + 0.001) and 1 / (c + 0.001) etc... for the others as multiplicative corrections, note that too a good approximation, once you multiply them out your samples are now roughly:

1 1 1 1 1 1 ...

i.e. nothing.

What you want is to keep the last n samples, using the example above we take the last 3 as an example the corrections need to be:

3/(a+b+c+0.001), 3/(b+c+d+0.001), 3/(d+e+f+0.001)...

we can't calculate these properly for a or b and have to start at c really... so we get:

3*c/(a+0.001) 3*c/(a+b+0.001) 3*c/(a+b+c+0.001) 3*d/(b+c+d+0.001) 3*e/(c+d+e+0.001)3*e/(d+e+f+0.001) ...

etc...

You get a little mess at the front, and the more samples you use for the moving average the longer the mess lasts... but the actual results inbetween should be usable.
HuRriC4nE#
WOW that sounds really ...sophisticated...

what are the volume samples a b c d e ?
something like

a=getspec(0,0,0);
b=getspec(0.1,0,4,0);
c= ....
?

my correction value shall not be the value that is directly used for the preset. The volume (that very slow interpolated one) shall represent something like the overall volume of a song. The correction shall be a value that every other value
is multiplikated with.
In quiet mixed songs these values than have the same "size" as in loud songs.

why do you use more than one sample for the volume?
is that better?
jheriko#
Originally posted by HuRriC4nE
WOW that sounds really ...sophisticated...

what are the volume samples a b c d e ?
something like

a=getspec(0,0,0);
b=getspec(0.1,0,4,0);
c= ....
?
yes.

Originally posted by HuRriC4nE
why do you use more than one sample for the volume?
is that better?
well, its just a moving average, it adds some temporal smoothing to the value calculated. this way the value is the average volume over so many frames, not just the instantaneous volume, which, if i understand correctly, would ruin the effect you are after.

look up averages and moving averages... its one of those many wheels i reinvented... if ever asked yourself "how do i find the value half way between a and b" you have all the prerequisite knowledge to both understand and independently derive the result.

happy maths. 🙂
HuRriC4nE#
Hm I'm sorry,
but I'm always a little slow in understanding
(GC can tell you... 🙂 ).
I also got a little problems with the english language.

you said "temporal smoothing". Isn't an interpolation of 0.999 to 0.001 giving the volume-value a very big temporal smoothing?

"
3/(a+b+c+0.001), 3/(b+c+d+0.001), 3/(d+e+f+0.001)...
"

are these three terms the correction-values for the different values a,b and c?

...
maybe i give you an example of how i get my values.
I have rotation parameters. ... x,y,z-values.

i show you the process the x value is created:

xrta = xrta*0.99 + getosc(rand(101)*0.01,0,0)*0.05;
xrt = xrt + xrt;

[xrta for "x rotation a"]
[xrt for "x rotation"]
the xsh value is tha final value i need.
but in low-volume songs it is very little.
my aim is to have a correction-value ["cor"] ,that can erase the effect as following:

xrta = xrta*0.99 + getosc( rand(101)*0.01, 0, 0)*0.05*cor;
xsh = xsh*0.95 + xrta;

When i understood you right you have corretion values for every sample you need in your preset.
(maybe one for the bass, one for the more "vocal" frequencies and one for crash-sounds - or maybe much more)
those samples are influencing each others correction-values.

maybe i sould send you the preset.
jheriko#
Originally posted by HuRriC4nE
you said "temporal smoothing". Isn't an interpolation of 0.999 to 0.001 giving the volume-value a very big temporal smoothing?
By temporal smoothing I meant "smoother over time" the +0.001 has nothing to do with that... its just to avoid division by zero. Like motion blur for videos, except with sound... difficult to explain with my poor grasp of technobabble.

Originally posted by HuRriC4nE

"
3/(a+b+c+0.001), 3/(b+c+d+0.001), 3/(d+e+f+0.001)...
"

are these three terms the correction-values for the different values a,b and c?
Yes.

Originally posted by HuRriC4nE
xrta = xrta*0.99 + getosc(rand(101)*0.01,0,0)*0.05;
xrt = xrt + xrt;
This will smooth out the rotation over time, but not very controlledly.

a*(1-t) + b*t is interpolation between a and b by t, in your case the constants don't add to 1 which "leaks" data, either by making the signal over strong or over weak (if they sum to less than one).

Originally posted by HuRriC4nE
my aim is to have a correction-value ["cor"] ,that can erase the effect as following:

xrta = xrta*0.99 + getosc( rand(101)*0.01, 0, 0)*0.05*cor;
xsh = xsh*0.95 + xrta;

This is sort of what I expected. Certainly I am describing "cor" and no other variable here. All I am saying is to make it a moving average so that it is smooth over time. Nothing to do with tonality.

Originally posted by HuRriC4nE
maybe i sould send you the preset.
Most certainly, that would be easiest. 🙂
HuRriC4nE#
jheriko is sent you a private message with a download link.
it took me a while to tidy up the code so that another person can (easier) understand it....
jheriko#
thx. in future use my e-mail address though. i'm more likely to get it... I get a ton of e-mails from the forums and generally ignore them all without noticing whether they are pm's are not. 🙂
HuRriC4nE#
@jheriko
i somehow find out why some classic songs are so bad reacting in this preset.
the output is not very well "distributed" over the spectrum.
a piano song has actually only mids - noc real bass or treble.
so the volume has to be made different.

i guess i will have to find another way to fix this.
so don't worry - i will fix it myself later 🙂

the preset already works very well