MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / SourceModuleHnNSF

Class SourceModuleHnNSF

modules/parallel_wavegan/models/source.py:484–531  ·  view source on GitHub ↗

SourceModule for hn-nsf SourceModule(sampling_rate, harmonic_num=0, sine_amp=0.1, add_noise_std=0.003, voiced_threshod=0) sampling_rate: sampling_rate in Hz harmonic_num: number of harmonic above F0 (default: 0) sine_amp: amplitude of sine source signal (default: 0.

Source from the content-addressed store, hash-verified

482
483
484class SourceModuleHnNSF(torch.nn.Module):
485 """ SourceModule for hn-nsf
486 SourceModule(sampling_rate, harmonic_num=0, sine_amp=0.1,
487 add_noise_std=0.003, voiced_threshod=0)
488 sampling_rate: sampling_rate in Hz
489 harmonic_num: number of harmonic above F0 (default: 0)
490 sine_amp: amplitude of sine source signal (default: 0.1)
491 add_noise_std: std of additive Gaussian noise (default: 0.003)
492 note that amplitude of noise in unvoiced is decided
493 by sine_amp
494 voiced_threshold: threhold to set U/V given F0 (default: 0)
495
496 Sine_source, noise_source = SourceModuleHnNSF(F0_sampled)
497 F0_sampled (batchsize, length, 1)
498 Sine_source (batchsize, length, 1)
499 noise_source (batchsize, length 1)
500 uv (batchsize, length, 1)
501 """
502
503 def __init__(self, sampling_rate, harmonic_num=0, sine_amp=0.1,
504 add_noise_std=0.003, voiced_threshod=0):
505 super(SourceModuleHnNSF, self).__init__()
506
507 self.sine_amp = sine_amp
508 self.noise_std = add_noise_std
509
510 # to produce sine waveforms
511 self.l_sin_gen = SineGen(sampling_rate, harmonic_num,
512 sine_amp, add_noise_std, voiced_threshod)
513
514 # to merge source harmonics into a single excitation
515 self.l_linear = torch.nn.Linear(harmonic_num + 1, 1)
516 self.l_tanh = torch.nn.Tanh()
517
518 def forward(self, x):
519 """
520 Sine_source, noise_source = SourceModuleHnNSF(F0_sampled)
521 F0_sampled (batchsize, length, 1)
522 Sine_source (batchsize, length, 1)
523 noise_source (batchsize, length 1)
524 """
525 # source for harmonic branch
526 sine_wavs, uv, _ = self.l_sin_gen(x)
527 sine_merge = self.l_tanh(self.l_linear(sine_wavs))
528
529 # source for noise branch, in the same shape as uv
530 noise = torch.randn_like(uv) * self.sine_amp / 3
531 return sine_merge, noise, uv
532
533
534if __name__ == '__main__':

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected