Skip to content

Commit

Permalink
added basic tests for db conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Dec 7, 2016
1 parent 8f68c8a commit e7169ea
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion librosa/core/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def db_to_power(log_S, ref_power=1.0):
-----
This function caches at level 30.
'''
return np.pow(10.0, 0.1 * (log_S + np.log10(ref_power)))
return np.power(10.0, 0.1 * (log_S + np.log10(ref_power)))


@cache(level=30)
Expand Down
60 changes: 60 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,66 @@ def __test(x, ref_power, amin, top_db):
yield tf, x * phase, ref_power, amin, top_db


def test_power_to_db():

srand()

NOISE_FLOOR = 1e-6

# Make some noise
x = np.abs(np.random.randn(1000)) + NOISE_FLOOR

db1 = librosa.power_to_db(x**2, top_db=None)
db2 = librosa.logamplitude(x**2, top_db=None)

assert np.allclose(db1, db2)


def test_amplitude_to_db():

srand()

NOISE_FLOOR = 1e-6

# Make some noise
x = np.abs(np.random.randn(1000)) + NOISE_FLOOR

db1 = librosa.amplitude_to_db(x, top_db=None)
db2 = librosa.logamplitude(x**2, top_db=None)

assert np.allclose(db1, db2)


def test_db_to_power():

srand()

NOISE_FLOOR = 1e-6

# Make some noise
xp = (np.abs(np.random.randn(1000)) + NOISE_FLOOR)**2

db = librosa.power_to_db(xp, top_db=None)
xp2 = librosa.db_to_power(db)

assert np.allclose(xp, xp2)


def test_db_to_amplitude():

srand()

NOISE_FLOOR = 1e-6

# Make some noise
x = np.abs(np.random.randn(1000)) + NOISE_FLOOR

db = librosa.amplitude_to_db(x, top_db=None)
x2 = librosa.db_to_amplitude(db)

assert np.allclose(x, x2)


def test_clicks():

def __test(times, frames, sr, hop_length, click_freq, click_duration, click, length):
Expand Down

0 comments on commit e7169ea

Please sign in to comment.