Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] White noise when resampling 48K model to 96K in DAW #398

Closed
2-dor opened this issue Dec 4, 2023 · 11 comments · Fixed by #401
Closed

[BUG] White noise when resampling 48K model to 96K in DAW #398

2-dor opened this issue Dec 4, 2023 · 11 comments · Fixed by #401
Labels
bug Something isn't working priority:high important release-candidate Issue found with a release candidate

Comments

@2-dor
Copy link

2-dor commented Dec 4, 2023

Noticeable increase in apparent noise floor when using a 48k .nam model in a 96k project.

To reproduce:

  • Launch DAW (used Reaper 7.06 in my case) and create 96K project
  • Add a NAM plugin instance to a track, arm for recording
  • Unplug any instrument cable going to the audio interface; lower all input volume sliders to minimum
  • Load a .nam model trained as usual at 48K (don't load any IR after it)
  • Notice the perceived noise volume (higher)
  • Save the project & close the DAW
  • Change the interface sample rate to 48K and relaunch the DAW / project
  • Notice the perceived noise volume (lower than when upsampling to 96K)
@2-dor 2-dor added bug Something isn't working priority:low Low priority issues unread This issue is new and hasn't been seen by the maintainers yet labels Dec 4, 2023
@sdatkinson sdatkinson added release-candidate Issue found with a release candidate and removed unread This issue is new and hasn't been seen by the maintainers yet labels Dec 5, 2023
@sdatkinson
Copy link
Owner

sdatkinson commented Dec 5, 2023

I'm seeing this too.

Looping a DI that's just my guitar with volume knob all the way off, and a super-gainy model (expecting 48k) and the noise gate disabled, I get these integrated LUFS:

44.1 kHz: -44.0 LUFS
48 kHz: -44.0 LUFS
88.2 kHz: -43.7 LUFS
96 kHz: -40.5 LUFS

Interesting that it really takes off with 96k with +3.5 dB.

I also don't see any difference when playing. Looping a DI with some strumming, all 4 sample rates converge to -17.6 LUFS. That's kind of interesting.

Out of curiosity, I benchmarked it against Tonocracy's NAM player running the same model. Theirs also sees the noise floor go up, but less (only +0.7 dB).

With a 20 kHz LPF like this...

image

...the difference disappears.

So it seems to me that the culprit is how the highest-frequency signals are being handled by the resampling algorithm.

There are a few options:

  1. Leave it alone and allow the user to do high-frequency treatment as they'd prefer (maximum flexibility, more user error)
  2. Add that LPF into the code (it "just works" but more modification of the signal than what a "NAM purist" might want? Technically we're already resampling, so that's out the window?)
  3. Perhaps the resampler can be tuned? I looked at the source code for the iPlug2 component I'm using but I don't see the parameters exposed in a way that suggests they were meant to be played with? (No initialization arguments or public methods). cc @olilarkin, lmk if I'm missing something here? e.g. what's up with the magic number A=4? I see its mathematical interpretation [thanks for the Wikipedia link!] but I'm interested by the fact that the article says a=2 or 3 is typical. Without going through the math, I'd guess higher values have better anti-aliasing properties but more latency?

@sdatkinson sdatkinson changed the title [BUG] [release-candidate 0.7.6] White noise when resampling 48K model to 96K in DAW [BUG] White noise when resampling 48K model to 96K in DAW Dec 5, 2023
@sdatkinson sdatkinson added priority:high important and removed priority:low Low priority issues labels Dec 5, 2023
@sdatkinson
Copy link
Owner

A few other observations:

  • This shouldn't affect the noise gate--the resampling only happens around the NAM; the rest of the DSP is done in the external sample rate.
  • Something like the Bertom Denoiser, cutting highs, also makes things work fine...

Another thought: I can already imagine having to answer this question again and again. I'm not very keen on option (1) in my comment above. I certainly could do something like a first-order LPF at the Nyquist before feeding the signal into the resampler (only on the resampling path). Anything to make this less noticeable would probably be good.


I'm also wondering whether I should consider this a must-fix for this release or if it'd be okay to get it out there and patch it in the next one if I can get it tuned up. My bet is that the majority of users will benefit from this because they're using 44.1. For them, this isn't an issue. @2-dor, feel free to weigh in.

@2-dor
Copy link
Author

2-dor commented Dec 5, 2023

A few other observations:

  • This shouldn't affect the noise gate--the resampling only happens around the NAM; the rest of the DSP is done in the external sample rate.
  • Something like the Bertom Denoiser, cutting highs, also makes things work fine...

Another thought: I can already imagine having to answer this question again and again. I'm not very keen on option (1) in my comment above. I certainly could do something like a first-order LPF at the Nyquist before feeding the signal into the resampler (only on the resampling path). Anything to make this less noticeable would probably be good.

I'm also wondering whether I should consider this a must-fix for this release or if it'd be okay to get it out there and patch it in the next one if I can get it tuned up. My bet is that the majority of users will benefit from this because they're using 44.1. For them, this isn't an issue. @2-dor, feel free to weigh in.

I think getting it out is priority so no biggie.

@olilarkin
Copy link
Contributor

olilarkin commented Dec 5, 2023 via email

@sdatkinson
Copy link
Owner

Looking into it a little more, I have the sense that it would be appropriate for the choice of A to depend on what sample rates the Lanczos sampler is resampling between. However, I'm not sure of the details yet.

@olilarkin
Copy link
Contributor

olilarkin commented Dec 5, 2023

I did a test with a sine sweep and i don't see any problems with the noise floor...

sweep.mov

you can do the same with IPlugEffect...

#pragma once

#include "IPlug_include_in_plug_hdr.h"
#include "NonIntegerResampler.h"

const int kNumPresets = 1;

enum EParams
{
  kGain = 0,
  kNumParams
};

using namespace iplug;

class IPlugEffect final : public Plugin
{
public:
  IPlugEffect(const InstanceInfo& info);
  void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
  void OnReset() override;
  NonIntegerResampler<> mNonIntegerResampler;
};
#include "IPlugEffect.h"
#include "IPlug_include_in_plug_src.h"

IPlugEffect::IPlugEffect(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
, mNonIntegerResampler(48000, ESRCMode::kLancsoz)
{
  GetParam(kGain)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%");
}

void IPlugEffect::OnReset()
{
  mNonIntegerResampler.Reset(GetSampleRate(), GetBlockSize());
}

void IPlugEffect::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
  const double gain = GetParam(kGain)->Value() / 100.;
  const int nChans = NOutChansConnected();
  
  mNonIntegerResampler.ProcessBlock(inputs, outputs, nFrames,
  [nChans, gain](sample** inputs, sample** outputs, int nFrames){
    for (int s = 0; s < nFrames; s++) {
      for (int c = 0; c < nChans; c++) {
        outputs[c][s] = inputs[c][s] * gain;
      }
    }
  });

}

@DomMcsweeney
Copy link

@olilarkin - Here's the difference between 48khz and 96khz.
I loaded up NAM and an amp model (any will do) and armed the track.
I recorded the 'output' twice, once at 48khz, next at 96khz.
The noise from the audio interface is being recorded through NAM.... but nothing is plugged into the audio interface.
The input and output controls on the NAM plugin are at maximum to exaggerate.
It's roughly 6db higher at 96khz.

2023-12-06.00-07-48.mp4

@olilarkin
Copy link
Contributor

olilarkin commented Dec 6, 2023

could someone share a .nam where i can easily reproduce the problem? I just tried it with a guitar here and i am not noticing much of a difference in the volume of the noise when i switch the host samplerate between 48 and 96k.

@2-dor
Copy link
Author

2-dor commented Dec 6, 2023

could someone share a .nam where i can easily reproduce the problem? I just tried it with a guitar here and i am not noticing much of a difference in the volume of the noise when i switch the host samplerate between 48 and 96k.

https://tonehunt.org/2dor/9115b091-7858-4f69-ae42-a324edc3b527

This should cover it. It's 1 DI profile and 2 that have cooked in IRs

@DomMcsweeney
Copy link

DomMcsweeney commented Dec 6, 2023

To be fair, when no plugins are loaded on a track in reaper, and when you change sample rates - the noise floor of an armed track with instrument input selected (but with nothing physically connected to audio interface) - is louder at 96khz than at 48khz.
image

(I had to boost the track level by about 70db to exaggerate the result, but it seems to be consistent regardless of any plugins present on the track)

@olilarkin
Copy link
Contributor

I think setting A=12 is a big improvement for 44.1khz -> 48khz as well as 96khz->48khz. I've reworked the iPlug2 resampling classes to default to this value. I've also renamed the class... iPlug2/iPlug2@4bfc3e1

@sdatkinson if you define IPLUG_SIMDE you can get some extra performance too since i think you were using the scalar version before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:high important release-candidate Issue found with a release candidate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants