clarity.enhancer.multiband_compressor package¶
Submodules¶
Module contents¶
- class clarity.enhancer.multiband_compressor.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()
- class clarity.enhancer.multiband_compressor.Crossover(freq_crossover: list | ndarray | int, sample_rate: float = 44100)[source]¶
Bases:
object
A class to compute crossover filter for two or more crossover frequencies. This is based on [1]
References: [1] D’Appolito, J. A. (1984, October). Active realization of multiway all-pass crossover systems. In Audio Engineering Society Convention 76. Audio Engineering Society.
Example: >>> xover_freqs = np.array( … [250, 500, 1000, 1500, 2000, 3000, 4000, 5000, 6000, 8000] …) * np.sqrt(2) >>> xover = Crossover(xover_freqs) >>> signal = np.random.randn(1000) >>> filtered_signal = xover(signal) >>> xover.plot_filter()
- FILTER_ORDER = 4¶
- plot_filter()[source]¶
Method to plot the frequency response of the filter. This can help to validate the Class is generating the expected filters
- xover_component(signal: ndarray, filter_idx: int, len_xover_freqs: int, axis: int = -1) ndarray [source]¶
Apply the crossover filter to the signal.
- Parameters:
signal (np.ndarray) – The input signal.
filter_idx (int) – The index of the filter to apply.
len_xover_freqs (int) – The number of crossover frequencies.
axis (int) – The axis along which to apply the filter. Default is -1.
`More information in scipy.signal.lfilter`
documentation.
- Returns:
The filtered signal.
- Return type:
np.ndarray
- class clarity.enhancer.multiband_compressor.MultibandCompressor(crossover_frequencies: int | float | list | np.ndarray, sample_rate: float = 44100, compressors_params: dict | None = None)[source]¶
Bases:
object
Multiband Compressor.
- set_compressors(attack: list | float = 15.0, release: list | float = 100.0, threshold: list | float = 0.0, ratio: list | float = 1.0, makeup_gain: list | float = 0.0, knee_width: list | float = 0.0) None [source]¶
Set the compressors parameters.
Parameters can be a float or a list with the same length as center_frequencies.
- Parameters:
attack (list | float) – The attack time in milliseconds.
release (list | float) – The release time in milliseconds.
threshold (list | float) – The threshold in dB.
ratio (list | float) – The ratio.
gain (list | float) – The make-up gain in dB.
knee_width (list | float) – The knee width in dB.
- Returns:
The compressors.
- Return type:
list[Compressor]
- Raises:
ValueError – If the parameters are not the same length as
crossover frequencies + 1. –