Commit a3b6bfb6 authored by Bogdan Teleaga's avatar Bogdan Teleaga Committed by Facebook GitHub Bot
Browse files

Fix resampling to support dynamic input lengths for onnx exports. (#3473)

Summary:
This is a port of https://github.com/adefossez/julius/pull/17 for torchaudio.

Not sure if it's possible/desirable to add tests to test the functionality of ONNX exports, but I did a quick test on my machine to ensure this works. The logic is a bit simpler compared to the other PR because the torchaudio version does not support the additional flags available in julius.

Pull Request resolved: https://github.com/pytorch/audio/pull/3473

Differential Revision: D47401988

Pulled By: mthrok

fbshipit-source-id: 62fa1e4388923f6a62cef2c0f902a79ea179cec4
parent 989702b3
......@@ -1463,7 +1463,7 @@ def _apply_sinc_resample_kernel(
waveform = torch.nn.functional.pad(waveform, (width, width + orig_freq))
resampled = torch.nn.functional.conv1d(waveform[:, None], kernel, stride=orig_freq)
resampled = resampled.transpose(1, 2).reshape(num_wavs, -1)
target_length = int(math.ceil(new_freq * length / orig_freq))
target_length = torch.ceil(torch.as_tensor(new_freq * length / orig_freq)).long()
resampled = resampled[..., :target_length]
# unpack batch
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment