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

Function f0_to_coarse

utils/pitch_utils.py:22–31  ·  view source on GitHub ↗
(f0)

Source from the content-addressed store, hash-verified

20
21
22def f0_to_coarse(f0):
23 is_torch = isinstance(f0, torch.Tensor)
24 f0_mel = 1127 * (1 + f0 / 700).log() if is_torch else 1127 * np.log(1 + f0 / 700)
25 f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - f0_mel_min) * (f0_bin - 2) / (f0_mel_max - f0_mel_min) + 1
26
27 f0_mel[f0_mel <= 1] = 1
28 f0_mel[f0_mel > f0_bin - 1] = f0_bin - 1
29 f0_coarse = (f0_mel + 0.5).long() if is_torch else np.rint(f0_mel).astype(np.int)
30 assert f0_coarse.max() <= 255 and f0_coarse.min() >= 1, (f0_coarse.max(), f0_coarse.min())
31 return f0_coarse
32
33
34def norm_f0(f0, uv, hparams):

Callers 4

add_pitchMethod · 0.90
spec2wavMethod · 0.90
get_pitchMethod · 0.90
get_pitchFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected