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_RELEASE_DROP = 10.
9 AUBIO_DEFAULT_NOTES_MINIOI_MS = 30.
11 class aubio_notes_default(TestCase):
13 def test_members(self):
15 assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate],
16 [1024,512,'default',44100])
19 class aubio_notes_params(TestCase):
24 self.o = notes(samplerate = self.samplerate)
26 def test_get_minioi_ms(self):
27 assert_equal (self.o.get_minioi_ms(), AUBIO_DEFAULT_NOTES_MINIOI_MS)
29 def test_set_minioi_ms(self):
31 self.o.set_minioi_ms(val)
32 assert_almost_equal (self.o.get_minioi_ms(), val)
34 def test_get_silence(self):
35 assert_equal (self.o.get_silence(), AUBIO_DEFAULT_NOTES_SILENCE)
37 def test_set_silence(self):
39 self.o.set_silence(val)
40 assert_equal (self.o.get_silence(), val)
42 def test_get_release_drop(self):
43 assert_equal (self.o.get_release_drop(), AUBIO_DEFAULT_NOTES_RELEASE_DROP)
45 def test_set_release_drop(self):
47 self.o.set_release_drop(val)
48 assert_equal (self.o.get_release_drop(), val)
50 def test_set_release_drop_wrong(self):
52 with self.assertRaises(ValueError):
53 self.o.set_release_drop(val)
55 from .utils import list_all_sounds
56 list_of_sounds = list_all_sounds('sounds')
58 class aubio_notes_sinewave(TestCase):
60 def analyze_file(self, filepath, samplerate=0):
61 from aubio import source
63 win_s = 512 # fft size
64 hop_s = 256 # hop size
66 s = source(filepath, samplerate, hop_s)
67 samplerate = s.samplerate
71 notes_o = notes("default", win_s, hop_s, samplerate)
77 new_note = notes_o(samples)
78 if (new_note[0] != 0):
79 note_str = ' '.join(["%.2f" % i for i in new_note])
80 results.append( [total_frames, np.copy(new_note)] )
82 if read < hop_s: break
85 def test_sinewave(self):
86 for filepath in list_of_sounds:
87 if '44100Hz_44100f_sine441.wav' in filepath:
88 results = self.analyze_file(filepath)
89 assert_equal (len(results), 1)
90 assert_equal (len(results[0]), 2)
91 assert_equal (results[0][0], 1280)
92 assert_equal (results[0][1], [69, 123, -1])
94 if __name__ == '__main__':