def __init__(self, sample_rate: int = 10000, use_vad: bool = True, extended: bool = False): super().__init__() # Independant from FS self.sample_rate = sample_rate self.use_vad = use_vad self.extended = extended self.intel_frames = N self.beta = BETA self.dyn_range = DYN_RANGE self.do_resample = True # Dependant from FS if self.do_resample: sample_rate = FS self.resample = torchaudio.transforms.Resample( orig_freq=self.sample_rate, new_freq=FS, resampling_method='sinc_interpolation', ) self.win_len = (N_FRAME * sample_rate) // FS self.nfft = 2 * self.win_len win = torch.from_numpy(np.hanning(self.win_len + 2)[1:-1]).float() self.win = nn.Parameter(win, requires_grad=False) obm_mat = thirdoct(sample_rate, self.nfft, NUMBAND, MINFREQ)[0] self.OBM = nn.Parameter(torch.from_numpy(obm_mat).float(), requires_grad=False)
def test_thirdoct(): """Test thirdoct by comparing to Octave""" obm_m, cf_m = octave.feval('octave/thirdoct.m', float(FS), float(NFFT), float(NUMBAND), float(MINFREQ), nout=2) obm, cf = thirdoct(FS, NFFT, NUMBAND, MINFREQ) obm_m = np.array(obm_m) cf_m = np.array(cf_m).transpose().squeeze() assert_allclose(obm, obm_m, atol=ATOL) assert_allclose(cf, cf_m, atol=ATOL)
def test_thirdoct(): obm_m, cf_m = eng.thirdoct(float(FS), float(NFFT), float(NUMBAND), float(MINFREQ), nargout=2) obm, cf = thirdoct(FS, NFFT, NUMBAND, MINFREQ) obm_m = np.array(obm_m) cf_m = np.array(cf_m).transpose().squeeze() assert_allclose(obm, obm_m, atol=ATOL) assert_allclose(cf, cf_m, atol=ATOL)