espnet2.gan_svs.visinger2.ddsp.harmonic_synth
Less than 1 minute
espnet2.gan_svs.visinger2.ddsp.harmonic_synth
espnet2.gan_svs.visinger2.ddsp.harmonic_synth(pitch, amplitudes, sampling_rate)
Generate a harmonic signal based on pitch and amplitude information.
This function synthesizes a harmonic signal by computing the sum of sinusoidal waves, where each harmonic is weighted by the provided amplitude values. The pitch determines the fundamental frequency, and the number of harmonics is determined by the length of the amplitudes tensor.
- Parameters:
- pitch (torch.Tensor) – A tensor containing the fundamental frequency (in Hz) for each time step. Shape should be (batch_size,).
- amplitudes (torch.Tensor) – A tensor containing the amplitudes for each harmonic. Shape should be (batch_size, n_harmonics).
- sampling_rate (int) – The sampling rate of the generated signal.
- Returns: A tensor containing the synthesized harmonic signal. : Shape will be (batch_size, 1, signal_length).
- Return type: torch.Tensor
Examples
>>> pitch = torch.tensor([[440.0]]) # A4 note
>>> amplitudes = torch.tensor([[1.0, 0.5, 0.25]]) # Amplitudes for harmonics
>>> sampling_rate = 44100 # Standard audio sampling rate
>>> signal = harmonic_synth(pitch, amplitudes, sampling_rate)
>>> print(signal.shape) # Should output: torch.Size([1, 1, signal_length])
NOTE
The output signal will be a single channel (mono) audio signal that can be played or processed further.