3 from unittest import main
4 from numpy.testing import TestCase, assert_equal, assert_almost_equal
5 from aubio import notes
7 AUBIO_DEFAULT_NOTES_SILENCE = -70.
8 AUBIO_DEFAULT_NOTES_MINIOI_MS = 30.
10 class aubio_notes_default(TestCase):
12 def test_members(self):
14 assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate],
15 [1024,512,'default',44100])
18 class aubio_notes_params(TestCase):
23 self.o = notes(samplerate = self.samplerate)
25 def test_get_minioi_ms(self):
26 assert_equal (self.o.get_minioi_ms(), AUBIO_DEFAULT_NOTES_MINIOI_MS)
28 def test_set_minioi_ms(self):
30 self.o.set_minioi_ms(val)
31 assert_almost_equal (self.o.get_minioi_ms(), val)
33 def test_get_silence(self):
34 assert_equal (self.o.get_silence(), AUBIO_DEFAULT_NOTES_SILENCE)
36 def test_set_silence(self):
38 self.o.set_silence(val)
39 assert_equal (self.o.get_silence(), val)
41 from utils import list_all_sounds
42 list_of_sounds = list_all_sounds('sounds')
44 class aubio_notes_sinewave(TestCase):
46 def analyze_file(self, filepath, samplerate=0):
47 from aubio import source
49 win_s = 512 # fft size
50 hop_s = 256 # hop size
52 s = source(filepath, samplerate, hop_s)
53 samplerate = s.samplerate
57 notes_o = notes("default", win_s, hop_s, samplerate)
63 new_note = notes_o(samples)
64 if (new_note[0] != 0):
65 note_str = ' '.join(["%.2f" % i for i in new_note])
66 results.append( [total_frames, np.copy(new_note)] )
68 if read < hop_s: break
71 def test_sinewave(self):
72 for filepath in list_of_sounds:
73 if '44100Hz_44100f_sine441.wav' in filepath:
74 results = self.analyze_file(filepath)
75 assert_equal (len(results), 1)
76 assert_equal (len(results[0]), 2)
77 assert_equal (results[0][0], 1280)
78 assert_equal (results[0][1], [69, 123, -1])
80 if __name__ == '__main__':