|
19 | 19 | "lfilter",
|
20 | 20 | "lowpass_biquad",
|
21 | 21 | "highpass_biquad",
|
| 22 | + "equalizer_biquad", |
22 | 23 | "biquad",
|
23 | 24 | 'mask_along_axis',
|
24 | 25 | 'mask_along_axis_iid'
|
@@ -685,6 +686,33 @@ def lowpass_biquad(waveform, sample_rate, cutoff_freq, Q=0.707):
|
685 | 686 | return biquad(waveform, b0, b1, b2, a0, a1, a2)
|
686 | 687 |
|
687 | 688 |
|
| 689 | +def equalizer_biquad(waveform, sample_rate, center_freq, gain, Q=0.707): |
| 690 | + # type: (Tensor, int, float, float, float) -> Tensor |
| 691 | + r"""Designs biquad peaking equalizer filter and performs filtering. Similar to SoX implementation. |
| 692 | +
|
| 693 | + Args: |
| 694 | + waveform (torch.Tensor): audio waveform of dimension of `(channel, time)` |
| 695 | + sample_rate (int): sampling rate of the waveform, e.g. 44100 (Hz) |
| 696 | + center_freq (float): filter’s central frequency |
| 697 | + gain (float): desired gain at the boost (or attenuation) in dB |
| 698 | + q_factor (float): https://en.wikipedia.org/wiki/Q_factor |
| 699 | +
|
| 700 | + Returns: |
| 701 | + output_waveform (torch.Tensor): Dimension of `(channel, time)` |
| 702 | + """ |
| 703 | + w0 = 2 * math.pi * center_freq / sample_rate |
| 704 | + A = math.exp(gain / 40.0 * math.log(10)) |
| 705 | + alpha = math.sin(w0) / 2 / Q |
| 706 | + |
| 707 | + b0 = 1 + alpha * A |
| 708 | + b1 = -2 * math.cos(w0) |
| 709 | + b2 = 1 - alpha * A |
| 710 | + a0 = 1 + alpha / A |
| 711 | + a1 = -2 * math.cos(w0) |
| 712 | + a2 = 1 - alpha / A |
| 713 | + return biquad(waveform, b0, b1, b2, a0, a1, a2) |
| 714 | + |
| 715 | + |
688 | 716 | @torch.jit.script
|
689 | 717 | def mask_along_axis_iid(specgrams, mask_param, mask_value, axis):
|
690 | 718 | # type: (Tensor, int, float, int) -> Tensor
|
|
0 commit comments