Skip to content

Commit

Permalink
remove float64 by changing how computations are done.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentqb committed May 7, 2020
1 parent 7ff6b7e commit 26582fd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions torchaudio/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _hz_to_mel(freq: Tensor, mel_scale: str = "htk") -> Tensor:
raise ValueError('mel_scale should be one of "htk" or "slaney".')

if mel_scale == "htk":
return 2595.0 * torch.log10(1.0 + (freq / 700.0))
return 2595.0 * torch.log10((700.0 + freq)/ 700.0)

# Fill in the linear part
f_min = 0.0
Expand Down Expand Up @@ -515,9 +515,9 @@ def create_fb_matrix(
# Equivalent filterbank construction by Librosa
all_freqs = torch.linspace(0, sample_rate // 2, n_freqs)

# torch.log10 with float32 produces different results on different CPUs
m_min = _hz_to_mel(torch.tensor(f_min, dtype=torch.float64), mel_scale=mel_scale)
m_max = _hz_to_mel(torch.tensor(f_max, dtype=torch.float64), mel_scale=mel_scale)
# convert hz to mel
m_min = _hz_to_mel(torch.tensor(f_min), mel_scale=mel_scale)
m_max = _hz_to_mel(torch.tensor(f_max), mel_scale=mel_scale)

# calculate mel freq bins
m_pts = torch.linspace(m_min, m_max, n_mels + 2)
Expand All @@ -533,7 +533,7 @@ def create_fb_matrix(
up_slopes = slopes[:, 2:] / f_diff[1:] # (n_freqs, n_mels)
fb = torch.max(zero, torch.min(down_slopes, up_slopes))

return fb.to(torch.float32)
return fb


def create_dct(
Expand Down

0 comments on commit 26582fd

Please sign in to comment.