clarity.enhancer.multiband_compressor.compressor_qmul module

“Module for the Compressor class.

class clarity.enhancer.multiband_compressor.compressor_qmul.Compressor(threshold: float = 0.0, ratio: float = 1.0, attack: float = 15.0, release: float = 100.0, makeup_gain: float = 0.0, knee_width: float = 0.0, sample_rate: float = 44100.0)[source]

Bases: object

Based in the compressor from [1]. Code adapted from JUCE C++ source code. Optimization using IIR filters.

References: [1] Giannoulis, D., Massberg, M., & Reiss, J. D. (2012). Digital dynamic range compressor design - A tutorial and analysis. Journal of the Audio Engineering Society, 60(6), 399-408.

Example: >>> import librosa >>> import matplotlib.pyplot as plt

>>> signal, sr = librosa.load(
...     librosa.ex("brahms"),
...     sr=None,
...     duration=10,
...     mono=False
... )
>>> if signal.ndim == 1:
>>>      signal = signal[np.newaxis, :]
>>> compressor = Compressor(
...    threshold=-30.0,
...    ratio=4.0,
...    attack=10.0,
...    release=100.0,
...    makeup_gain=1.25,
...    sample_rate=sr,
...    knee_width=10.0,
...)
>>> compressed_signal = compressor(signal)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].specgram(signal[0], Fs=sr, NFFT=512, noverlap=256)
>>> axes[0].set_title("original signal")
>>> axes[1].specgram(compressed_signal[0], Fs=sr, NFFT=512, noverlap=256)
>>> axes[1].set_title("Compressed signal")
>>> plt.yticks([x for x in range(0, int(sr / 2), 1000)])
>>> plt.tight_layout()
>>> plt.show()
>>> plt.close()
>>> plt.figure()
>>> plt.plot(signal[0])
>>> plt.plot(compressed_signal[0])
>>> plt.show()