Convolution gain louder at higher sample rates
-
I haven't done exact measurements, but the convolution reverb appears to be way louder at higher sample rates (88.2/96).
The impulse is 44.1
Is there something im supposed to be doing to compensate for this, or is this a bug? -
huh? I haven't noticed that, and I don't know how the gain could correlate with the samplerate - the IRs are resampled to the current samplerate obviously.
How long is your IR? If it's really short for a FIR filter response, it might be possible that the resampling might truncate some samples.
-
@Christoph-Hart I have about 2-3 seconds of tail in the impulse.
I'm gonna do some proper testing today and report back with my findings. -
Working on a project with the Convolution reverb and ran into this problem again.
I made a simple convolution as a test, and here's what I found:file used in convolution =
6789tyhgy67878s1.wavand here are the processed results at different sample rates:
processed files are louder at higher sample rates
-
Wow, that's a weird one. I've tracked it down to something deep inside the convolution library I am using, but I can't fix it inside the library (also I really don't understand what's causing the gain increase on a theoretical DSP level, the convolution algorithm should not be affected by the amount of samples that you feed it into, all it does is basically shifting the signal into lower FFT bins).
My empirical tests show that there is a logarithmic correlation between samplerate and gain across different IRs (the actual gain increase varies a little bit, but these are the average numbers:
44,1kHz: -1dB
48kHz: 0dB (reference)
96kHz: +3.5dB
192kHz: +6.6dBI've tested it with the 4-5 IRs I had on my laptop and the noise generator (this signal might be the best candidate for checking the overall gain on an IR). Can you verify this with a few other IRs? Because my gut feeling tells me that we just need to bake in this gain change of the average IR as constant multiplier based on the resample factor and then live with the small inconsistencies (there will always some kind of inconsistency caused by the IR resampling so it will never be mathematically perfect anyway).
-
Here's what I'm seeing on my end
Reference is White Noise @ -20 -
Also noticing that the AudioWaveform panel is affected by files at different sample rates as well.
Check out these images.
Same IR at different sample rates.44.1k
96k
There also seems to be a center offset for mono files as well?
-
@Christoph-Hart I was going to use Simple Gain to compensate for the level difference, but I'm getting an error.
var SR = Engine.getSampleRate(); const var Label1 = Content.getComponent("Label1"); Label1.set("text", SR);
Within HISE, this code works. But in a DAW, Engine.getSampleRate() returns -1
-
The onInit callback will be executed before the samplerate is known in a plugin so you need to make sure to defer that - you're safest bet would be a script FX and its preparedToPlay callback because this is where you usually setup the processing stuff.
But just out of curiosity because your numbers differ vastly from my ones: what did you measure for the file you've uploaded? I am still not sure if this is a constant gain factor and how much does it depend on the impulse response type.
-
@Christoph-Hart I'll measure those impulses asap
-
for the file I uploaded
44 = -18
48 = -17.6
88 = -14.9
96 = -12.6
174 = -11.7
192 = -11.9 -
I'm just noticing that the first IR I uploaded was a stereo file, and the rest were mono. That appears to make a difference on the output level as well.
-
Yeah sure, let's add that to the number of weird reasons why the gain goes up. What else? The length of the filename? :)
-
-
convolution is producing a distorted digital noise at sample rates 44.1 and 48khz anything above the behave perfect. but with every one tested there is a distortion below 88.2
-
@mwplugs I'm about to add convolution to a project. I'll report what happens on my end.
-
@dustbro ok yeah i cant figure it out for the life of me
-
@Christoph-Hart I could use a little help getting Engine.getSampleRate() to work properly.
I would like to use the sample rate as a variable to compensate for the gain difference with different sample rates.
I've added a global variable with Engine.getSampleRate() to the preparedToPlay callback, which works in HISE, but the exported plugin shows "undefined" for the sample rate.here's a snippit:
HiseSnippet 1224.3oc0X8+SabCE2GvMQRajZq1e.V7SAsD5EZfRWU0nDftnUfnFFqSUnNm6bRrvw9zYGFYUU6Os8ezz9OX6YeG4tKbvXYZnQ9g.98M+487yedF5DI8oJkLB4T53IgTjyCc6NQnG1ZHgIPs2E47DWEYTHmhiHZJVSUZzNSBIJEM.43r3aL14TZIj8ye7M6P3DgOMUDBchj4SeKaDSmJsy1eGiy2mDPOlMJi0M2tsuTzRxkiALsnqGJj3eFY.8PhwrEbQNewdALsLpqFviBrYGYvjtCk+rH19SXJVON0rnApKDnXwnVCY7fNWluJDxYoNoY+hwY+W5d.KfMUdZU3QVE3TOxVCbVHOjVJGjZbcPZeIOvDfqAdNYf2Rwv6wtc8iXg5TMFr8.21BMMpOAJ6YgUrsnE90EcaIAKD50FQNiteDrXpGU2zyqFdCOuUeYkxUJCEekFeNIB20dp+NHidKoGkieE9xfLfpaIGEJEvhpqLicqXhSZTLsGFioBEQyjBHL19KSP1qeepODgYsYkXnLSfWSQAa0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POm
-
You're declaring the global variable in the
prepareCallback
itself (I wasn't aware that this is possible, might have to add a safe check to prevent this at some point).This means that the variable will be initialised long after the interface script has run, so
undefined
is exactly what's happening...BTW, the safest way to use global variables is to define them in the first script (most likely the interface script) and also tuck them behind a condition so that it just gets initialised if it doesn't exist:
if(!isDefined(myGlobalVariable)) { global myVariable = 90; }
If you don't do this, the variable will get reinitialised everytime you compile the interface script which is not a problem in your case, but might lead to annoying issues when using more complex data (because the other scripts might use a reference to the old object).
-
@Christoph-Hart Thanks so much for this! I think I have it (mostly) working.
Any words of advice on how to deal with a user changing sample rates while the plugin is loaded?
I tried this in the preparedToPlay callback with no luckif (HostSampleRate != Engine.getSampleRate()) { ..... some function to update HostSampleRate }