Commit c6c6b689 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Randomize initial phase of sinusoid data in test (#2301)

Summary:
This commit update `get_sinusoid` function in test utility so that
when a multi channel is requested, non-primal channel have randomized
initial phase.

This adds some variety in test data which should not break the tests.
Currently `get_sinusoid` returns identical waveforms for all the channels.
This multi channel support was added just to mock the input data so that
it is easy to test features with multi-channel inputs, so tests should not be
expecting the all channels to be identical.

When working on numerical parity, it is more useful if the raw waveforms
are somewhat different.

Image: waveforms generated by `get_sinusoid` after the change. left: 1st channel, right: 2nd channel
<img width="524" alt="Screen Shot 2022-03-31 at 10 06 17 AM" src="https://user-images.githubusercontent.com/855818/161111163-1ea58ff6-51ee-4e37-bcd6-411041dd2603.png">

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

Reviewed By: hwangjeff

Differential Revision: D35291689

Pulled By: mthrok

fbshipit-source-id: 9160d07ccdd1494acb6d41cb07ac434c0676dbfd
parent ec552b69
......@@ -106,8 +106,13 @@ def get_sinusoid(
dtype = getattr(torch, dtype)
pie2 = 2 * 3.141592653589793
end = pie2 * frequency * duration
theta = torch.linspace(0, end, int(sample_rate * duration), dtype=torch.float32, device=device)
tensor = torch.sin(theta, out=None).repeat([n_channels, 1])
num_frames = int(sample_rate * duration)
# Randomize the initial phase. (except the first channel)
theta0 = pie2 * torch.randn(n_channels, 1, dtype=torch.float32, device=device)
theta0[0, :] = 0
theta = torch.linspace(0, end, num_frames, dtype=torch.float32, device=device)
theta = theta0 + theta
tensor = torch.sin(theta, out=None)
if not channels_first:
tensor = tensor.t()
return convert_tensor_encoding(tensor, dtype)
......
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