sine_tensor, uv = forward(f0) input F0: tensor(batchsize=1, length, dim=1) f0 for unvoiced steps should be 0 output sine_tensor: tensor(batchsize=1, length, dim) output uv: tensor(batchsize=1, length, 1)
(self, f0)
| 102 | return sines |
| 103 | |
| 104 | def forward(self, f0): |
| 105 | """ sine_tensor, uv = forward(f0) |
| 106 | input F0: tensor(batchsize=1, length, dim=1) |
| 107 | f0 for unvoiced steps should be 0 |
| 108 | output sine_tensor: tensor(batchsize=1, length, dim) |
| 109 | output uv: tensor(batchsize=1, length, 1) |
| 110 | """ |
| 111 | with torch.no_grad(): |
| 112 | f0_buf = torch.zeros(f0.shape[0], f0.shape[1], self.dim, |
| 113 | device=f0.device) |
| 114 | # fundamental component |
| 115 | f0_buf[:, :, 0] = f0[:, :, 0] |
| 116 | for idx in np.arange(self.harmonic_num): |
| 117 | # idx + 2: the (idx+1)-th overtone, (idx+2)-th harmonic |
| 118 | f0_buf[:, :, idx + 1] = f0_buf[:, :, 0] * (idx + 2) |
| 119 | |
| 120 | # generate sine waveforms |
| 121 | sine_waves = self._f02sine(f0_buf) * self.sine_amp |
| 122 | |
| 123 | # generate uv signal |
| 124 | # uv = torch.ones(f0.shape) |
| 125 | # uv = uv * (f0 > self.voiced_threshold) |
| 126 | uv = self._f02uv(f0) |
| 127 | |
| 128 | # noise: for unvoiced should be similar to sine_amp |
| 129 | # std = self.sine_amp/3 -> max value ~ self.sine_amp |
| 130 | # . for voiced regions is self.noise_std |
| 131 | noise_amp = uv * self.noise_std + (1 - uv) * self.sine_amp / 3 |
| 132 | noise = noise_amp * torch.randn_like(sine_waves) |
| 133 | |
| 134 | # first: set the unvoiced part to 0 by uv |
| 135 | # then: additive noise |
| 136 | sine_waves = sine_waves * uv + noise |
| 137 | return sine_waves, uv, noise |
| 138 | |
| 139 | |
| 140 | class PulseGen(torch.nn.Module): |