def func(tensor):
     sample_rate = 44100
     central_freq = 1000.
     q = 0.707
     const_skirt_gain = True
     return F.bandpass_biquad(tensor, sample_rate, central_freq, q,
                              const_skirt_gain)
Пример #2
0
    def test_bandpass_with_csg(self):
        """
        Test biquad bandpass filter, compare to SoX implementation
        """

        central_freq = 1000
        q = 0.707
        const_skirt_gain = True

        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(
            "bandpass", ["-c", 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.bandpass_biquad(waveform, sample_rate,
                                            central_freq, q, const_skirt_gain)

        torch.testing.assert_allclose(output_waveform,
                                      sox_output_waveform,
                                      atol=1e-4,
                                      rtol=1e-5)
Пример #3
0
    def test_bandpass_with_csg(self):
        """
        Test biquad bandpass filter, compare to SoX implementation
        """

        CENTRAL_FREQ = 1000
        Q = 0.707
        CONST_SKIRT_GAIN = 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(
            "bandpass", ["-c", 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.bandpass_biquad(waveform, sample_rate,
                                            CENTRAL_FREQ, Q, CONST_SKIRT_GAIN)

        assert torch.allclose(sox_output_waveform, output_waveform, atol=1e-4)
        _test_torchscript_functional(F.bandpass_biquad, waveform, sample_rate,
                                     CENTRAL_FREQ, Q, CONST_SKIRT_GAIN)
Пример #4
0
    def test_bandpass_without_csg(self):
        central_freq = 1000
        q = 0.707
        const_skirt_gain = False
        sample_rate = 8000

        data, path = self.get_whitenoise(sample_rate)
        result = F.bandpass_biquad(data, sample_rate, central_freq, q, const_skirt_gain)
        self.assert_sox_effect(result, path, ['bandpass', central_freq, f'{q}q'])
    def test_bandpass_without_csg(self):
        """
        Test biquad bandpass filter, compare to SoX implementation
        """
        central_freq = 1000
        q = 0.707
        const_skirt_gain = False

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(self.noise_filepath)
        E.append_effect_to_chain("bandpass", [central_freq, str(q) + 'q'])
        sox_output_waveform, sr = E.sox_build_flow_effects()

        output_waveform = F.bandpass_biquad(self.noise_waveform,
                                            self.NOISE_SAMPLE_RATE,
                                            central_freq, q, const_skirt_gain)

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