Skip to content

Commit d4e651e

Browse files
scriptatorSebastian Böck
authored andcommitted
Add MFCC unittests
1 parent 1535c20 commit d4e651e

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

madmom/audio/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class or inherit from madmom.SequentialProcessor or ParallelProcessor.
2727
from . import signal, ffmpeg, filters, comb_filters, stft, spectrogram
2828

2929
# import often used classes
30+
from .cepstrogram import MFCC, MFCCProcessor
3031
from .chroma import DeepChromaProcessor
3132
from .signal import (
3233
FramedSignal, FramedSignalProcessor, Signal, SignalProcessor)

tests/test_audio_mfcc.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# encoding: utf-8
2+
# pylint: skip-file
3+
"""
4+
This file contains tests for the madmom.audio.cepstrogram module.
5+
6+
"""
7+
8+
from __future__ import absolute_import, division, print_function
9+
10+
import unittest
11+
from functools import partial
12+
from os.path import join as pj
13+
14+
from madmom.audio.cepstrogram import MFCC, Cepstrogram
15+
from madmom.audio.filters import MelFilterbank
16+
from madmom.audio.spectrogram import *
17+
from . import AUDIO_PATH
18+
19+
sample_file = pj(AUDIO_PATH, 'sample.wav')
20+
sample_file_22050 = pj(AUDIO_PATH, 'sample_22050.wav')
21+
22+
23+
class TestMFCCClass(unittest.TestCase):
24+
def test_types(self):
25+
result = MFCC(sample_file)
26+
self.assertIsInstance(result, MFCC)
27+
self.assertIsInstance(result, Cepstrogram)
28+
# attributes
29+
self.assertIsInstance(result.filterbank, MelFilterbank)
30+
# properties
31+
self.assertIsInstance(result.deltas, np.ndarray)
32+
self.assertIsInstance(result.deltadeltas, np.ndarray)
33+
self.assertIsInstance(result.num_bins, int)
34+
self.assertIsInstance(result.num_frames, int)
35+
# wrong filterbank type
36+
with self.assertRaises(TypeError):
37+
FilteredSpectrogram(sample_file, filterbank='bla')
38+
39+
def test_values(self):
40+
# from file
41+
result = MFCC(sample_file)
42+
allclose = partial(np.allclose, rtol=1.e-3, atol=1.e-5)
43+
self.assertTrue(allclose(result[0, :6],
44+
[-3.61102366, 6.81075716, 2.55457568,
45+
1.88377929, 1.04133379, 0.6382336]))
46+
self.assertTrue(allclose(result[0, -6:],
47+
[-0.20386486, -0.18468723, -0.00233107,
48+
0.20703268, 0.21419463, 0.00598407]))
49+
# attributes
50+
self.assertTrue(result.shape == (281, 30))
51+
52+
# properties
53+
self.assertEqual(result.num_bins, 30)
54+
self.assertEqual(result.num_frames, 281)
55+
56+
def test_deltas(self):
57+
# from file
58+
result = MFCC(sample_file)
59+
allclose = partial(np.allclose, rtol=1.e-2, atol=1.e-4)
60+
61+
# don't compare first element because it is dependent on the
62+
# padding used for filtering
63+
self.assertTrue(allclose(result.deltas[1, :6],
64+
[-0.02286286, -0.11329014, 0.05381977,
65+
0.10438456, 0.04268386, -0.06839912]))
66+
self.assertTrue(allclose(result.deltas[1, -6:],
67+
[-0.03156065, -0.019716, -0.03417692,
68+
-0.07768068, -0.05539324, -0.02616282]))
69+
70+
self.assertTrue(allclose(result.deltadeltas[1, :6],
71+
[-0.00804922, -0.009922, -0.00454391,
72+
0.0038989, 0.00254525, 0.0120557]))
73+
self.assertTrue(allclose(result.deltadeltas[1, -6:],
74+
[0.0072148, 0.00094424, 0.00029913,
75+
0.00530994, 0.00184207, -0.00276511]))

0 commit comments

Comments
 (0)