-
Notifications
You must be signed in to change notification settings - Fork 736
[BC-Breaking] Drop pseudo complex support from phase_vocoder / TimeStretch #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -714,8 +714,7 @@ def phase_vocoder( | |
|
|
||
| Args: | ||
| complex_specgrams (Tensor): | ||
| Either a real tensor of dimension of `(..., freq, num_frame, complex=2)` | ||
| or a tensor of dimension `(..., freq, num_frame)` with complex dtype. | ||
| A tensor of dimension `(..., freq, num_frame)` with complex dtype. | ||
| rate (float): Speed-up factor | ||
| phase_advance (Tensor): Expected phase advance in each bin. Dimension of `(freq, 1)` | ||
|
|
||
|
|
@@ -724,7 +723,7 @@ def phase_vocoder( | |
| Stretched spectrogram. The resulting tensor is of the same dtype as the input | ||
| spectrogram, but the number of frames is changed to ``ceil(num_frame / rate)``. | ||
|
|
||
| Example - With Tensor of complex dtype | ||
| Example | ||
| >>> freq, hop_length = 1025, 512 | ||
| >>> # (channel, freq, time) | ||
| >>> complex_specgrams = torch.randn(2, freq, 300, dtype=torch.cfloat) | ||
|
|
@@ -734,41 +733,10 @@ def phase_vocoder( | |
| >>> x = phase_vocoder(complex_specgrams, rate, phase_advance) | ||
| >>> x.shape # with 231 == ceil(300 / 1.3) | ||
| torch.Size([2, 1025, 231]) | ||
|
|
||
| Example - With Tensor of real dtype and extra dimension for complex field | ||
| >>> freq, hop_length = 1025, 512 | ||
| >>> # (channel, freq, time, complex=2) | ||
| >>> complex_specgrams = torch.randn(2, freq, 300, 2) | ||
| >>> rate = 1.3 # Speed up by 30% | ||
| >>> phase_advance = torch.linspace( | ||
| >>> 0, math.pi * hop_length, freq)[..., None] | ||
| >>> x = phase_vocoder(complex_specgrams, rate, phase_advance) | ||
| >>> x.shape # with 231 == ceil(300 / 1.3) | ||
| torch.Size([2, 1025, 231, 2]) | ||
| """ | ||
| if rate == 1.0: | ||
| return complex_specgrams | ||
|
|
||
| if not complex_specgrams.is_complex(): | ||
| warnings.warn( | ||
| "The support for pseudo complex type in `torchaudio.functional.phase_vocoder` and " | ||
| "`torchaudio.transforms.TimeStretch` is now deprecated and will be removed " | ||
| "from 0.11 release." | ||
| "Please migrate to native complex type by converting the input tensor with " | ||
| "`torch.view_as_complex`. " | ||
| "Please refer to https://github.com/pytorch/audio/issues/1337 " | ||
| "for more details about torchaudio's plan to migrate to native complex type." | ||
| ) | ||
| if complex_specgrams.size(-1) != 2: | ||
| raise ValueError( | ||
| "complex_specgrams must be either native complex tensors or " | ||
| "real valued tensors with shape (..., 2)") | ||
|
|
||
| is_complex = complex_specgrams.is_complex() | ||
|
|
||
| if not is_complex: | ||
| complex_specgrams = torch.view_as_complex(complex_specgrams) | ||
|
|
||
| # pack batch | ||
| shape = complex_specgrams.size() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, unfortunately, it is BC-breaking and we do not have a strong reason to push the BC-breaking here. |
||
| complex_specgrams = complex_specgrams.reshape([-1] + list(shape[-2:])) | ||
|
|
@@ -813,9 +781,6 @@ def phase_vocoder( | |
|
|
||
| # unpack batch | ||
| complex_specgrams_stretch = complex_specgrams_stretch.reshape(shape[:-2] + complex_specgrams_stretch.shape[1:]) | ||
|
|
||
| if not is_complex: | ||
| return torch.view_as_real(complex_specgrams_stretch) | ||
| return complex_specgrams_stretch | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change it by using the
get_spectrogrammethod?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Using
get_specgrogramfirst time in a while and now I feel it's not user-friendly...