From 471d00254f03325f11c47f05f9dc4f8961e5ce10 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sun, 8 Oct 2023 00:17:44 -0400 Subject: [PATCH] constraining the pitch --- dnn/torch/fargan/fargan.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dnn/torch/fargan/fargan.py b/dnn/torch/fargan/fargan.py index 39b5ddaf7..d9933b42a 100644 --- a/dnn/torch/fargan/fargan.py +++ b/dnn/torch/fargan/fargan.py @@ -208,15 +208,17 @@ def forward(self, cond, prev_pred, exc_mem, period, states, gain=None): #print(cond.shape, prev.shape) - idx = 256-torch.clamp(period[:,None], min=self.subframe_size+2, max=254) + idx = 256-period[:,None] rng = torch.arange(self.subframe_size+4, device=device) idx = idx + rng[None,:] - 2 + mask = idx >= 256 + idx = idx - mask*period[:,None] pred = torch.gather(exc_mem, 1, idx) - pred = pred/(1e-5+gain) + pred = torch.clamp(pred/(1e-5+gain), min=-1, max=1) prev = exc_mem[:,-self.subframe_size:] dump_signal(prev, 'prev_in.f32') - prev = prev/(1e-5+gain) + prev = torch.clamp(prev/(1e-5+gain), min=-1, max=1) dump_signal(prev, 'pitch_exc.f32') dump_signal(exc_mem, 'exc_mem.f32')