drc#

diffsptk.DRC#

alias of DynamicRangeCompression

class diffsptk.DynamicRangeCompression(threshold: float, ratio: float, attack_time: float, release_time: float, sample_rate: int, makeup_gain: float = 0, abs_max: float = 1, learnable: bool = False, device: device | None = None, dtype: dtype | None = None)[source]#

See this page for details.

Parameters:
thresholdfloat <= 0

The threshold in dB.

ratiofloat > 1

The input/output ratio.

attack_timefloat > 0

The attack time in msec.

release_timefloat > 0

The release time in msec.

sample_rateint >= 1

The sample rate in Hz.

makeup_gainfloat >= 0

The make-up gain in dB.

abs_maxfloat > 0

The absolute maximum value of input.

learnablebool

Whether to make the DRC parameters learnable.

devicetorch.device or None

The device of this module.

dtypetorch.dtype or None

The data type of this module.

References

[1]

C.-Y. Yu et al., “Differentiable all-pole filters for time-varying audio systems,” Proceedings of DAFx, pp. 345-352, 2024.

forward(x: Tensor) Tensor[source]#

Perform dynamic range compression.

Parameters:
xTensor [shape=(…, T)]

The input waveform.

Returns:
outTensor [shape=(…, T)]

The compressed waveform.

Examples

>>> x = torch.randn(16000)
>>> x.abs().max()
tensor(4.2224)
>>> drc = diffsptk.DynamicRangeCompression(-20, 4, 10, 100, 16000)
>>> y = drc(x)
>>> y.abs().max()
tensor(2.5779)
diffsptk.functional.drc(x: Tensor, threshold: float, ratio: float, attack_time: float, release_time: float, sample_rate: int, makeup_gain: float = 0, abs_max: float = 1) Tensor[source]#

Perform dynamic range compression.

Parameters:
xTensor [shape=(…, T)]

The input waveform.

thresholdfloat <= 0

The threshold in dB.

ratiofloat > 1

The input/output ratio.

attack_timefloat > 0

The attack time in msec.

release_timefloat > 0

The release time in msec.

sample_rateint >= 1

The sample rate in Hz.

makeup_gainfloat >= 0

The make-up gain in dB.

abs_maxfloat > 0

The absolute maximum value of input.

Returns:
outTensor [shape=(…, T)]

The compressed waveform.