From 748219e64cf20e8e9344fb6aea49f431f0119b4e Mon Sep 17 00:00:00 2001 From: roebel Date: Wed, 21 Jun 2023 12:21:11 +0200 Subject: [PATCH] Fix inefficient phase unwrapping (#7) --- vocos/heads.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vocos/heads.py b/vocos/heads.py index 181865f..21863f1 100644 --- a/vocos/heads.py +++ b/vocos/heads.py @@ -54,10 +54,15 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: mag, p = x.chunk(2, dim=1) mag = torch.exp(mag) mag = torch.clip(mag, max=1e2) # safeguard to prevent excessively large magnitudes + # wrapping happens here. These two lines produce real and imaginary value x = torch.cos(p) y = torch.sin(p) - phase = torch.atan2(y, x) - S = mag * torch.exp(phase * 1j) + # recalculating phase here does not produce anything new + # only costs time + # phase = torch.atan2(y, x) + # S = mag * torch.exp(phase * 1j) + # better directly produce the complex value + S = mag * (x + 1j * y) audio = self.istft(S) return audio