Пример #1
0
    def forward(self, waveform: Tensor) -> Tensor:
        r"""
        Args:
            waveform (Tensor): Tensor of audio of dimension (..., time).

        Returns:
            Tensor: Tensor of audio of dimension (..., time).
        """
        if self.gain_type == "amplitude":
            waveform = waveform * self.gain

        if self.gain_type == "db":
            waveform = F.gain(waveform, self.gain)

        if self.gain_type == "power":
            waveform = F.gain(waveform, 10 * math.log10(self.gain))

        return torch.clamp(waveform, -1, 1)
Пример #2
0
    def test_gain(self):
        waveform_gain = F.gain(self.waveform_train, 3)
        self.assertTrue(waveform_gain.abs().max().item(), 1.)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(self.test_filepath)
        E.append_effect_to_chain("gain", [3])
        sox_gain_waveform = E.sox_build_flow_effects()[0]

        self.assertTrue(torch.allclose(waveform_gain, sox_gain_waveform, atol=1e-04))
Пример #3
0
    def test_gain(self):
        test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
        waveform, _ = torchaudio.load(test_filepath)

        waveform_gain = F.gain(waveform, 3)
        self.assertTrue(waveform_gain.abs().max().item(), 1.)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(test_filepath)
        E.append_effect_to_chain("gain", [3])
        sox_gain_waveform = E.sox_build_flow_effects()[0]

        self.assertEqual(waveform_gain, sox_gain_waveform, atol=1e-04, rtol=1e-5)
Пример #4
0
    def test_gain(self):
        test_filepath = os.path.join(self.test_dirpath, "assets",
                                     "steam-train-whistle-daniel_simon.wav")
        waveform, _ = torchaudio.load(test_filepath)

        waveform_gain = F.gain(waveform, 3)
        self.assertTrue(waveform_gain.abs().max().item(), 1.)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(test_filepath)
        E.append_effect_to_chain("gain", [3])
        sox_gain_waveform = E.sox_build_flow_effects()[0]

        torch.testing.assert_allclose(waveform_gain,
                                      sox_gain_waveform,
                                      atol=1e-04,
                                      rtol=1e-5)
 def func(tensor):
     gainDB = 2.0
     return F.gain(tensor, gainDB)
Пример #6
0
 def test_gain(self):
     path = get_asset_path('steam-train-whistle-daniel_simon.wav')
     data, _ = load_wav(path)
     result = F.gain(data, 3)
     self.assert_sox_effect(result, path, ['gain', 3])
Пример #7
0
#Functional spectrogram deltas

specgram = torchaudio.transforms.Spectrogram()(waveform)
computed = torchaudio.functional.compute_deltas(specgram.contiguous(), win_length=3)
print(f"Shape of computed deltas: {computed.shape}")

plt.figure()

#The image is blank?? Probably matplotlib issue
plt.imshow(computed.log2()[0,:,:].detach().numpy(), cmap='gray')
# %%

#Applying gain and dithering

gain_waveform = F.gain(waveform, gain_db=5.0)
print(f'''
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