Skip to content

Commit 18bd61d

Browse files
committed
Fix inconsistency between amp_to_db and db_to_amp
hopefully helps #43
1 parent 2987b76 commit 18bd61d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def _build_mel_basis():
7676

7777

7878
def _amp_to_db(x):
79-
return 20 * np.log10(np.maximum(1e-5, x + 0.01))
79+
return 20 * np.log10(x + 0.01)
8080

8181

8282
def _db_to_amp(x):
83-
return np.power(10.0, x * 0.05)
83+
return np.maximum(np.power(10.0, x * 0.05) - 0.01, 0.0)
8484

8585

8686
def _normalize(S):

tests/test_audio.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding: utf-8
2+
from __future__ import with_statement, print_function, absolute_import
3+
4+
import sys
5+
from os.path import dirname, join
6+
sys.path.insert(0, join(dirname(__file__), ".."))
7+
8+
import numpy as np
9+
from nose.plugins.attrib import attr
10+
11+
import logging
12+
logging.getLogger('tensorflow').disabled = True
13+
14+
15+
@attr("local_only")
16+
def test_amp_to_db():
17+
import audio
18+
x = np.random.rand(10)
19+
x_hat = audio._db_to_amp(audio._amp_to_db(x))
20+
assert np.allclose(x, x_hat)

0 commit comments

Comments
 (0)