Exemplo n.º 1
0
    def test_lowpass(self):
        """
        Test biquad lowpass filter, compare to SoX implementation
        """

        cutoff_freq = 3000

        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("lowpass", [cutoff_freq])
        sox_output_waveform, sr = E.sox_build_flow_effects()

        waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True)
        output_waveform = F.lowpass_biquad(waveform, sample_rate, cutoff_freq)

        self.assertEqual(output_waveform, sox_output_waveform, atol=1e-4, rtol=1e-5)
    def test_lowpass(self):
        """
        Test biquad lowpass filter, compare to SoX implementation
        """
        cutoff_freq = 3000

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(self.noise_filepath)
        E.append_effect_to_chain("lowpass", [cutoff_freq])
        sox_output_waveform, sr = E.sox_build_flow_effects()

        output_waveform = F.lowpass_biquad(self.noise_waveform,
                                           self.NOISE_SAMPLE_RATE, cutoff_freq)

        self.assertEqual(output_waveform,
                         sox_output_waveform,
                         atol=1e-4,
                         rtol=1e-5)
    def test_lowpass(self):

        """
        Test biquad lowpass filter, compare to SoX implementation
        """

        CUTOFF_FREQ = 3000

        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("lowpass", [CUTOFF_FREQ])
        sox_output_waveform, sr = E.sox_build_flow_effects()

        waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True)
        output_waveform = F.lowpass_biquad(waveform, sample_rate, CUTOFF_FREQ)

        assert torch.allclose(sox_output_waveform, output_waveform, atol=1e-4)
 def func(tensor):
     sample_rate = 44100
     cutoff_freq = 3000.
     return F.lowpass_biquad(tensor, sample_rate, cutoff_freq)
Exemplo n.º 5
0
Min of gain_waveform: {gain_waveform.min()}
Max of gain_waveform: {gain_waveform.max()}
Mean of gain_waveform: {gain_waveform.mean()}
''')

dither_waveform = F.dither(waveform)
print(f'''
Min of dither_waveform: {dither_waveform.min()}
Max of dither_waveform: {dither_waveform.max()}
Mean of dither_waveform: {dither_waveform.mean()}
''')
# %%

#Applying filters

lowpass_waveform = F.lowpass_biquad(waveform, sample_rate, cutoff_freq=3000)

print(f'''
Min of lowpass_waveform: {lowpass_waveform.min()}
Max of lowpass_waveform: {lowpass_waveform.max()}
Mean of lowpass_waveform: {lowpass_waveform.mean()}
''')

fig, axis = plt.subplots(2)
axis[0].plot(lowpass_waveform[0].t().numpy())
axis[0].set_ylabel("R")
axis[1].plot(lowpass_waveform[1].t().numpy())
axis[1].set_ylabel("L")

highpass_waveform = F.lowpass_biquad(waveform, sample_rate, cutoff_freq=2000)