3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from aubio import notes, source
6 from utils import list_all_sounds
8 list_of_sounds = list_all_sounds('sounds')
10 AUBIO_DEFAULT_NOTES_SILENCE = -70.
11 AUBIO_DEFAULT_NOTES_RELEASE_DROP = 10.
12 AUBIO_DEFAULT_NOTES_MINIOI_MS = 30.
14 class aubio_notes_default(TestCase):
16 def test_members(self):
18 assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate],
19 [1024,512,'default',44100])
22 class aubio_notes_params(TestCase):
27 self.o = notes(samplerate = self.samplerate)
29 def test_get_minioi_ms(self):
30 assert_equal (self.o.get_minioi_ms(), AUBIO_DEFAULT_NOTES_MINIOI_MS)
32 def test_set_minioi_ms(self):
34 self.o.set_minioi_ms(val)
35 assert_almost_equal (self.o.get_minioi_ms(), val)
37 def test_get_silence(self):
38 assert_equal (self.o.get_silence(), AUBIO_DEFAULT_NOTES_SILENCE)
40 def test_set_silence(self):
42 self.o.set_silence(val)
43 assert_equal (self.o.get_silence(), val)
45 def test_get_release_drop(self):
46 assert_equal (self.o.get_release_drop(), AUBIO_DEFAULT_NOTES_RELEASE_DROP)
48 def test_set_release_drop(self):
50 self.o.set_release_drop(val)
51 assert_equal (self.o.get_release_drop(), val)
53 def test_set_release_drop_wrong(self):
55 with self.assertRaises(ValueError):
56 self.o.set_release_drop(val)
58 class aubio_notes_sinewave(TestCase):
60 def analyze_file(self, filepath, samplerate=0):
61 win_s = 512 # fft size
62 hop_s = 256 # hop size
64 s = source(filepath, samplerate, hop_s)
65 samplerate = s.samplerate
69 notes_o = notes("default", win_s, hop_s, samplerate)
75 new_note = notes_o(samples)
76 if (new_note[0] != 0):
77 note_str = ' '.join(["%.2f" % i for i in new_note])
78 results.append( [total_frames, np.copy(new_note)] )
80 if read < hop_s: break
83 def test_sinewave(self):
84 for filepath in list_of_sounds:
85 if '44100Hz_44100f_sine441.wav' in filepath:
86 results = self.analyze_file(filepath)
87 assert_equal (len(results), 1)
88 assert_equal (len(results[0]), 2)
89 assert_equal (results[0][0], 1280)
90 assert_equal (results[0][1], [69, 123, -1])
92 if __name__ == '__main__':
93 from unittest import main