A PyTorch module that applies a spectral gate to an input signal. Arguments: sr {int} -- Sample rate of the input signal. nonstationary {bool} -- Whether to use non-stationary or stationary masking (default: {False}). n_std_thresh_stationary {float} -- Number of sta
| 6 | |
| 7 | |
| 8 | class TorchGate(torch.nn.Module): |
| 9 | """ |
| 10 | A PyTorch module that applies a spectral gate to an input signal. |
| 11 | |
| 12 | Arguments: |
| 13 | sr {int} -- Sample rate of the input signal. |
| 14 | nonstationary {bool} -- Whether to use non-stationary or stationary masking (default: {False}). |
| 15 | n_std_thresh_stationary {float} -- Number of standard deviations above mean to threshold noise for |
| 16 | stationary masking (default: {1.5}). |
| 17 | n_thresh_nonstationary {float} -- Number of multiplies above smoothed magnitude spectrogram. for |
| 18 | non-stationary masking (default: {1.3}). |
| 19 | temp_coeff_nonstationary {float} -- Temperature coefficient for non-stationary masking (default: {0.1}). |
| 20 | n_movemean_nonstationary {int} -- Number of samples for moving average smoothing in non-stationary masking |
| 21 | (default: {20}). |
| 22 | prop_decrease {float} -- Proportion to decrease signal by where the mask is zero (default: {1.0}). |
| 23 | n_fft {int} -- Size of FFT for STFT (default: {1024}). |
| 24 | win_length {[int]} -- Window length for STFT. If None, defaults to `n_fft` (default: {None}). |
| 25 | hop_length {[int]} -- Hop length for STFT. If None, defaults to `win_length` // 4 (default: {None}). |
| 26 | freq_mask_smooth_hz {float} -- Frequency smoothing width for mask (in Hz). If None, no smoothing is applied |
| 27 | (default: {500}). |
| 28 | time_mask_smooth_ms {float} -- Time smoothing width for mask (in ms). If None, no smoothing is applied |
| 29 | (default: {50}). |
| 30 | """ |
| 31 | |
| 32 | @torch.no_grad() |
| 33 | def __init__( |
| 34 | self, |
| 35 | sr: int, |
| 36 | nonstationary: bool = False, |
| 37 | n_std_thresh_stationary: float = 1.5, |
| 38 | n_thresh_nonstationary: float = 1.3, |
| 39 | temp_coeff_nonstationary: float = 0.1, |
| 40 | n_movemean_nonstationary: int = 20, |
| 41 | prop_decrease: float = 1.0, |
| 42 | n_fft: int = 1024, |
| 43 | win_length: bool = None, |
| 44 | hop_length: int = None, |
| 45 | freq_mask_smooth_hz: float = 500, |
| 46 | time_mask_smooth_ms: float = 50, |
| 47 | ): |
| 48 | super().__init__() |
| 49 | |
| 50 | # General Params |
| 51 | self.sr = sr |
| 52 | self.nonstationary = nonstationary |
| 53 | assert 0.0 <= prop_decrease <= 1.0 |
| 54 | self.prop_decrease = prop_decrease |
| 55 | |
| 56 | # STFT Params |
| 57 | self.n_fft = n_fft |
| 58 | self.win_length = self.n_fft if win_length is None else win_length |
| 59 | self.hop_length = self.win_length // 4 if hop_length is None else hop_length |
| 60 | |
| 61 | # Stationary Params |
| 62 | self.n_std_thresh_stationary = n_std_thresh_stationary |
| 63 | |
| 64 | # Non-Stationary Params |
| 65 | self.temp_coeff_nonstationary = temp_coeff_nonstationary |