Skip to content

Commit

Permalink
Fix inefficient phase unwrapping (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
roebel authored Jun 21, 2023
1 parent 03c4fcb commit 748219e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vocos/heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 748219e

Please sign in to comment.