1 stable release

Uses old Rust 2015

1.0.0 Apr 7, 2018

#1501 in Database interfaces

LGPL-2.1

115KB
511 lines

README

Build status

This is a LADSPA high quality noise reduction plug-in. It can be used by any LADSPA-enabled audio processing application. It is able to remove most types of continuous noise from audio signals, including blue, white, pink and brown noise.

License

This plug-in is copyright ⓒ2011-2018 Jérôme M. Berger and released under the terms of the GNU LGPLv2.1. You should have found a copy of the license along with this plug-in, or you can find it here.

Parameters

The plug-in exposes the following parameters:

  • Reduction amount (dB) – Amount by which the noise will be reduced.
  • Noise level (dB) – Noise level (see Noise model).
  • Noise shape (dB/decade) – Noise shape in decibels per decade (see Noise model).
  • Filter length – Filter length. This parameters affects the balance between resolution in time and resolution in frequency. Small values give better time resolution, while large values give better frequency resolution. This should preferably be set to a power of 2.
  • Residual output – If this is enabled, the filter effect will be reversed: instead of removing the noise, the filter will keep only the noise. This can be used to check that you are not removing part of the signal along with the noise.
  • Automatic noise model – If this is enabled, estimate the Noise level and Noise shape parameters from the input signal. The values given to these parameters through the input ports are ignored.
  • Automatic reactivity – Speed at which the automatic noise shape adjusts to changes in the input noise. Smaller values mean that the filter is more stable but adapts more slowly to changes (at the extreme, if this is 0, then the filter will estimate the parameters from the first window and doesn't adapt if the noise changes). With larger values the filter adapts faster, which may caus artefacts as the filter changes. Note that the default value of 0.25 make for a very stable filter that is still able to adapt to changes in only a few milliseconds (less than 20ms at 44kHz with a filter length of 4096).
  • Fast mode – If this is enabled, the filter will only overlap two windows instead of four. This causes the filter to run twice as fast, but may cause a slight degradation in output quality.

Note: The automatic noise model is pretty conservative and tends to underestimate the noise level. Don't hesitate to increase the reduction amount when the automatic model is enabled (increasing the amount by 4dB is reasonable in this situation).

Noise model

The filter relies on a simple noise model to determine which part of the signal is noise and which part is legitimate signal. The noise model assumes that noise will have level $l_n(f)$ in dB at frequency $f$ with:

$$l_n(f)=L-shape\times\log\left(\frac{f}{f_0}\right)$$

where:

  • $f_0$ is a reference frequency fixed arbitrarily to $F_s/100$ (this results in $f_0=440,\text{Hz}$ for a sampling frequency of 44 kHz).
  • $L$ is the noise level in dB at frequency $f_0$. This can be estimated from a spectrum plot using a Hann or Hanning window with a size equal to twice the filter length rounded up to the next power of 2.
  • $shape$ expresses the noise shape in dB/decade. It is the amount by which the noise level decreases each time the frequency is multiplied by 10. It can be estimated from the spectrum plot by looking at the noise level at frequencies 100 Hz and 1 kHz (or any pair of frequencies with a ratio of 10).

Standard noise shapes

  • Blue noise has level that increases with frequency and is modelled with $shape=-10,\text{dB/decade}$. Note that blue noise is very rarely seen in audio processing.
  • White noise has constant level over all frequencies and is modelled with $shape=0,\text{dB/decade}$.
  • Pink noise has level that decreases when frequency increases and is modelled with $shape=10,\text{dB/decade}$.
  • Brown noise decreases more sharply than pink noise and is modelled with $shape=20,\text{dB/decade}$.

Real-time use

The plug-in is real-time compatible provided that the Filter length parameter does not change.

Technical details

The plug-in assumes that any frequency whose level is significantly greater than the modelled noise level is mostly signal and should be preserved. Conversely, any frequency whose level is close to or lower than the modelled noise level is mostly noise and should be removed. Therefore the plug-in builds a dynamic equalisation filter whose frequency response depends on the input at any given point in time.

Filter response

The ideal frequency response is given by:

$$g(f)=1-e^{-\frac{l(f)}{s(f)}}$$

where $l(f)$ is the input level at frequency $f$ and $s(f)$ is the filter strength at that same frequency. This gives a response of 1 for large input levels, which are mostly signal, and a value of 0 for small input levels, which are mostly noise.

The strength $s(f)$ is computed from the modelled noise level $l_n(f)$ and the desired reduction amount $a$ in such a way that the response will be equal to $a$ if the measured level is equal to the modelled noise level:

$$1-e^{-\frac{l_n(f)}{s(f)}}=a$$

solving for $s(f)$ gives:

$$s(f)=-\frac{l_n(f)}{\ln(1-a)}$$

This ideal response is then dilated by an amount $\delta_f$ that depends on the filter length. This dilation ensures that narrow-band signals will be preserved by the windowing. As an unfortunate side-effect this also preserves noise at frequencies close to the signal. However this is not an issue in practise because psycho-acoustic effects mean that the signal will mask most of the preserved noise. The dilated response is given by:

$$g_d(f)=\max_{|\phi-f|<\delta_f}g(\phi)$$

Finally the dilated response is windowed in order to avoid the Gibbs phenomenon.

Application on overlapped windows

In order to apply the filter, the input signal is divided in windows of size twice the filter length (rounded up to the next power of two). Each window is then analysed to create the equalisation filter and this filter is applied to the signal. In fast mode each window is overlapped by half its length with the previous one. In standard mode, four windows are overlapped. In either case, the outputs are mixed to ensure a smooth transition between equalisation filters.

Automatic noise model

When using the automatic noise model, each window is analysed to guess the noise level and noise shape. The analysis is a two steps process:

  • A rough noise model is created by searching for local minima at both ends of the spectrum.
  • A refined noise model is created by linear regression of the spectrum keeping only the frequency bands that appear to be mostly noise according to the rough model.

Rough noise model

In order to create the rough noise model, the plugin looks at local minimas of the spectrum, i.e. frequency bands whose amplitude is less than the immediately preceding and following bands. Those frequency bands are assumed to be mostly noise and so suitable for building our noise model. The plugin searches for two such bands, one at the low end of the spectrum ($l(f_l)$) and the other at the high end of the spectrum ($l(f_h)$), then builds the rough noise model from those two bands:

$$l^{(r)}_n(f)=\frac{l(f_h)-l(f_l)}{log(f_h)-log(f_l)}(log(f)-log(f_l))+l(f_l)$$

In order to increase robustness of the model, the plugin looks at the first three local minimas at the low end of the spectrum, and at the last three local minimas at the high end of the spectrum and keeps the band with the middle level in each group of three.

Refined noise model

The refined model is created through linear regression of the spectrum in the loglog domain, keeping only the frequency bands such that $l(f)<l^{(r)}_n(f)+M$ (where $M$ is set to 10dB).

Dependencies

~3.5MB
~66K SLoC