def test_band_without_noise(self): """ Test biquad band filter without noise mode, compare to SoX implementation """ CENTRAL_FREQ = 1000 Q = 0.707 NOISE = False noise_filepath = os.path.join(self.test_dirpath, "assets", "whitenoise.wav") E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(noise_filepath) E.append_effect_to_chain("band", [CENTRAL_FREQ, str(Q) + 'q']) sox_output_waveform, sr = E.sox_build_flow_effects() waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True) output_waveform = F.band_biquad(waveform, sample_rate, CENTRAL_FREQ, Q, NOISE) torch.testing.assert_allclose(output_waveform, sox_output_waveform, atol=1e-4, rtol=1e-5)
def test_band_without_noise(self): central_freq = 1000 q = 0.707 noise = False sample_rate = 8000 data, path = self.get_whitenoise(sample_rate) result = F.band_biquad(data, sample_rate, central_freq, q, noise) self.assert_sox_effect(result, path, ['band', central_freq, f'{q}q'])
def test_band_without_noise(self): """ Test biquad band filter without noise mode, compare to SoX implementation """ central_freq = 1000 q = 0.707 noise = False noise_filepath = common_utils.get_asset_path('whitenoise.wav') E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(noise_filepath) E.append_effect_to_chain("band", [central_freq, str(q) + 'q']) sox_output_waveform, sr = E.sox_build_flow_effects() waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True) output_waveform = F.band_biquad(waveform, sample_rate, central_freq, q, noise) self.assertEqual(output_waveform, sox_output_waveform, atol=1e-4, rtol=1e-5)
def test_band_with_noise(self): """ Test biquad band filter with noise mode, compare to SoX implementation """ central_freq = 1000 q = 0.707 noise = True E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(self.noise_filepath) E.append_effect_to_chain("band", ["-n", central_freq, str(q) + 'q']) sox_output_waveform, sr = E.sox_build_flow_effects() output_waveform = F.band_biquad(self.noise_waveform, self.NOISE_SAMPLE_RATE, central_freq, q, noise) self.assertEqual(output_waveform, sox_output_waveform, atol=1e-4, rtol=1e-5)
def test_band_with_noise(self): """ Test biquad band filter with noise mode, compare to SoX implementation """ CENTRAL_FREQ = 1000 Q = 0.707 NOISE = True noise_filepath = os.path.join(self.test_dirpath, "assets", "whitenoise.mp3") E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(noise_filepath) E.append_effect_to_chain("band", ["-n", CENTRAL_FREQ, str(Q) + 'q']) sox_output_waveform, sr = E.sox_build_flow_effects() waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True) output_waveform = F.band_biquad(waveform, sample_rate, CENTRAL_FREQ, Q, NOISE) assert torch.allclose(sox_output_waveform, output_waveform, atol=1e-4) _test_torchscript_functional(F.band_biquad, waveform, sample_rate, CENTRAL_FREQ, Q, NOISE)
def func(tensor): sample_rate = 44100 central_freq = 1000. q = 0.707 noise = False return F.band_biquad(tensor, sample_rate, central_freq, q, noise)