Changeset 633400d for python/tests
- Timestamp:
- Dec 5, 2018, 10:34:39 PM (6 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 283a619a
- Parents:
- 5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- python/tests
- Files:
-
- 9 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/eval_pitch
r5b46bc3 r633400d 25 25 import os.path 26 26 import numpy 27 from utils import array_from_text_file, array_from_yaml_file27 from .utils import array_from_text_file, array_from_yaml_file 28 28 from aubio import source, pitch, freqtomidi 29 29 -
python/tests/test_aubio.py
r5b46bc3 r633400d 10 10 import aubio 11 11 12 def test_version(self): 13 """ test aubio.version """ 14 import aubio 15 self.assertEqual('0', aubio.version[0]) 16 12 17 if __name__ == '__main__': 13 18 main() -
python/tests/test_fft.py
r5b46bc3 r633400d 34 34 fftgrain = f (timegrain) 35 35 assert_equal ( fftgrain.norm, 0 ) 36 assert_equal ( fftgrain.phas, 0 ) 36 try: 37 assert_equal ( fftgrain.phas, 0 ) 38 except AssertionError: 39 assert_equal (fftgrain.phas[fftgrain.phas > 0], +pi) 40 assert_equal (fftgrain.phas[fftgrain.phas < 0], -pi) 41 assert_equal (np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0) 42 self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \ 43 + 'This is expected when using fftw3 on powerpc.') 37 44 38 45 def test_impulse(self): … … 136 143 assert_almost_equal ( r[1:], 0) 137 144 145 class aubio_fft_odd_sizes(TestCase): 146 147 def test_reconstruct_with_odd_size(self): 148 win_s = 29 149 self.recontruct(win_s, 'odd sizes not supported') 150 151 def test_reconstruct_with_radix15(self): 152 win_s = 2 ** 4 * 15 153 self.recontruct(win_s, 'radix 15 supported') 154 155 def test_reconstruct_with_radix5(self): 156 win_s = 2 ** 4 * 5 157 self.recontruct(win_s, 'radix 5 supported') 158 159 def test_reconstruct_with_radix3(self): 160 win_s = 2 ** 4 * 3 161 self.recontruct(win_s, 'radix 3 supported') 162 163 def recontruct(self, win_s, skipMessage): 164 try: 165 f = fft(win_s) 166 except RuntimeError: 167 self.skipTest(skipMessage) 168 input_signal = fvec(win_s) 169 input_signal[win_s//2] = 1 170 c = f(input_signal) 171 output_signal = f.rdo(c) 172 assert_almost_equal(input_signal, output_signal) 173 174 class aubio_fft_wrong_params(TestCase): 175 138 176 def test_large_input_timegrain(self): 139 177 win_s = 1024 … … 163 201 with self.assertRaises(ValueError): 164 202 f.rdo(s) 165 166 class aubio_fft_wrong_params(TestCase):167 203 168 204 def test_wrong_buf_size(self): … … 170 206 with self.assertRaises(ValueError): 171 207 fft(win_s) 172 173 def test_buf_size_not_power_of_two(self):174 # when compiled with fftw3, aubio supports non power of two fft sizes175 win_s = 320176 try:177 with self.assertRaises(RuntimeError):178 fft(win_s)179 except AssertionError:180 self.skipTest('creating aubio.fft with size %d did not fail' % win_s)181 208 182 209 def test_buf_size_too_small(self): -
python/tests/test_filter.py
r5b46bc3 r633400d 4 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 5 from aubio import fvec, digital_filter 6 from utils import array_from_text_file6 from .utils import array_from_text_file 7 7 8 8 class aubio_filter_test_case(TestCase): … … 78 78 f.set_biquad(0., 0., 0, 0., 0.) 79 79 80 def test_all_available_presets(self): 81 f = digital_filter(7) 82 for sr in [8000, 11025, 16000, 22050, 24000, 32000, 83 44100, 48000, 88200, 96000, 192000]: 84 f.set_a_weighting(sr) 85 f = digital_filter(5) 86 for sr in [8000, 11025, 16000, 22050, 24000, 32000, 87 44100, 48000, 88200, 96000, 192000]: 88 f.set_c_weighting(sr) 89 80 90 class aubio_filter_wrong_params(TestCase): 81 91 -
python/tests/test_filterbank.py
r5b46bc3 r633400d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main4 from numpy.testing import TestCase5 from numpy.testing import assert_equal, assert_almost_equal6 3 import numpy as np 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 7 6 from aubio import cvec, filterbank, float_type 8 from utils import array_from_text_file7 from .utils import array_from_text_file 9 8 10 9 class aubio_filterbank_test_case(TestCase): … … 63 62 assert_almost_equal ( expected, f.get_coeffs() ) 64 63 64 def test_mfcc_coeffs_get_coeffs(self): 65 f = filterbank(40, 512) 66 coeffs = f.get_coeffs() 67 self.assertIsInstance(coeffs, np.ndarray) 68 assert_equal (coeffs, 0) 69 assert_equal (np.shape(coeffs), (40, 512 / 2 + 1)) 70 65 71 class aubio_filterbank_wrong_values(TestCase): 66 72 … … 82 88 83 89 if __name__ == '__main__': 84 main() 90 import nose2 91 nose2.main() -
python/tests/test_filterbank_mel.py
r5b46bc3 r633400d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 4 from numpy.testing import TestCase 5 from numpy.testing import assert_equal, assert_almost_equal 6 from numpy import array, shape 7 from aubio import cvec, filterbank, float_type 3 import numpy as np 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 6 from aubio import fvec, cvec, filterbank, float_type 7 8 import warnings 9 warnings.filterwarnings('ignore', category=UserWarning, append=True) 8 10 9 11 class aubio_filterbank_mel_test_case(TestCase): … … 13 15 f.set_mel_coeffs_slaney(16000) 14 16 a = f.get_coeffs() 15 assert_equal( shape (a), (40, 512/2 + 1) )17 assert_equal(np.shape (a), (40, 512/2 + 1) ) 16 18 17 19 def test_other_slaney(self): 18 20 f = filterbank(40, 512*2) 19 21 f.set_mel_coeffs_slaney(44100) 20 _ = f.get_coeffs()22 self.assertIsInstance(f.get_coeffs(), np.ndarray) 21 23 #print "sum is", sum(sum(a)) 22 24 for win_s in [256, 512, 1024, 2048, 4096]: 23 25 f = filterbank(40, win_s) 24 26 f.set_mel_coeffs_slaney(32000) 25 _ = f.get_coeffs()26 27 #print "sum is", sum(sum(a)) 28 self.assertIsInstance(f.get_coeffs(), np.ndarray) 27 29 28 30 def test_triangle_freqs_zeros(self): 29 31 f = filterbank(9, 1024) 30 32 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] 31 freqs = array(freq_list, dtype = float_type)33 freqs = np.array(freq_list, dtype = float_type) 32 34 f.set_triangle_bands(freqs, 48000) 33 _ = f.get_coeffs().T34 35 assert_equal ( f(cvec(1024)), 0) 36 self.assertIsInstance(f.get_coeffs(), np.ndarray) 35 37 36 38 def test_triangle_freqs_ones(self): 37 39 f = filterbank(9, 1024) 38 40 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] 39 freqs = array(freq_list, dtype = float_type)41 freqs = np.array(freq_list, dtype = float_type) 40 42 f.set_triangle_bands(freqs, 48000) 41 _ = f.get_coeffs().T43 self.assertIsInstance(f.get_coeffs(), np.ndarray) 42 44 spec = cvec(1024) 43 45 spec.norm[:] = 1 … … 46 48 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) 47 49 50 def test_triangle_freqs_with_zeros(self): 51 """make sure set_triangle_bands works when list starts with 0""" 52 freq_list = [0, 40, 80] 53 freqs = np.array(freq_list, dtype = float_type) 54 f = filterbank(len(freqs)-2, 1024) 55 f.set_triangle_bands(freqs, 48000) 56 assert_equal ( f(cvec(1024)), 0) 57 self.assertIsInstance(f.get_coeffs(), np.ndarray) 58 59 def test_triangle_freqs_with_wrong_negative(self): 60 """make sure set_triangle_bands fails when list contains a negative""" 61 freq_list = [-10, 0, 80] 62 f = filterbank(len(freq_list)-2, 1024) 63 with self.assertRaises(ValueError): 64 f.set_triangle_bands(fvec(freq_list), 48000) 65 66 def test_triangle_freqs_with_wrong_ordering(self): 67 """make sure set_triangle_bands fails when list not ordered""" 68 freq_list = [0, 80, 40] 69 f = filterbank(len(freq_list)-2, 1024) 70 with self.assertRaises(ValueError): 71 f.set_triangle_bands(fvec(freq_list), 48000) 72 73 def test_triangle_freqs_with_large_freq(self): 74 """make sure set_triangle_bands warns when freq > nyquist""" 75 samplerate = 22050 76 freq_list = [0, samplerate//4, samplerate // 2 + 1] 77 f = filterbank(len(freq_list)-2, 1024) 78 # TODO add assert_warns 79 f.set_triangle_bands(fvec(freq_list), samplerate) 80 81 def test_triangle_freqs_with_not_enough_filters(self): 82 """make sure set_triangle_bands warns when not enough filters""" 83 samplerate = 22050 84 freq_list = [0, 100, 1000, 4000, 8000, 10000] 85 f = filterbank(len(freq_list)-3, 1024) 86 # TODO add assert_warns 87 f.set_triangle_bands(fvec(freq_list), samplerate) 88 89 def test_triangle_freqs_with_too_many_filters(self): 90 """make sure set_triangle_bands warns when too many filters""" 91 samplerate = 22050 92 freq_list = [0, 100, 1000, 4000, 8000, 10000] 93 f = filterbank(len(freq_list)-1, 1024) 94 # TODO add assert_warns 95 f.set_triangle_bands(fvec(freq_list), samplerate) 96 97 def test_triangle_freqs_with_double_value(self): 98 """make sure set_triangle_bands works with 2 duplicate freqs""" 99 samplerate = 22050 100 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] 101 f = filterbank(len(freq_list)-2, 1024) 102 # TODO add assert_warns 103 f.set_triangle_bands(fvec(freq_list), samplerate) 104 105 def test_triangle_freqs_with_triple(self): 106 """make sure set_triangle_bands works with 3 duplicate freqs""" 107 samplerate = 22050 108 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] 109 f = filterbank(len(freq_list)-2, 1024) 110 # TODO add assert_warns 111 f.set_triangle_bands(fvec(freq_list), samplerate) 112 113 def test_triangle_freqs_without_norm(self): 114 """make sure set_triangle_bands works without """ 115 samplerate = 22050 116 freq_list = fvec([0, 100, 1000, 10000]) 117 f = filterbank(len(freq_list) - 2, 1024) 118 f.set_norm(0) 119 f.set_triangle_bands(freq_list, samplerate) 120 expected = f.get_coeffs() 121 f.set_norm(1) 122 f.set_triangle_bands(fvec(freq_list), samplerate) 123 assert_almost_equal(f.get_coeffs().T, 124 expected.T * 2. / (freq_list[2:] - freq_list[:-2])) 125 126 def test_triangle_freqs_wrong_norm(self): 127 f = filterbank(10, 1024) 128 with self.assertRaises(ValueError): 129 f.set_norm(-1) 130 131 def test_triangle_freqs_with_power(self): 132 f = filterbank(9, 1024) 133 freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 134 24000]) 135 f.set_power(2) 136 f.set_triangle_bands(freqs, 48000) 137 spec = cvec(1024) 138 spec.norm[:] = .1 139 expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417, 140 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) 141 expected /= 100. 142 assert_almost_equal(f(spec), expected) 143 144 def test_mel_coeffs(self): 145 f = filterbank(40, 1024) 146 f.set_mel_coeffs(44100, 0, 44100 / 2) 147 148 def test_zero_fmax(self): 149 f = filterbank(40, 1024) 150 f.set_mel_coeffs(44100, 0, 0) 151 152 def test_wrong_mel_coeffs(self): 153 f = filterbank(40, 1024) 154 with self.assertRaises(ValueError): 155 f.set_mel_coeffs_slaney(0) 156 with self.assertRaises(ValueError): 157 f.set_mel_coeffs(44100, 0, -44100 / 2) 158 with self.assertRaises(ValueError): 159 f.set_mel_coeffs(44100, -0.1, 44100 / 2) 160 with self.assertRaises(ValueError): 161 f.set_mel_coeffs(-44100, 0.1, 44100 / 2) 162 with self.assertRaises(ValueError): 163 f.set_mel_coeffs_htk(-1, 0, 0) 164 165 def test_mel_coeffs_htk(self): 166 f = filterbank(40, 1024) 167 f.set_mel_coeffs_htk(44100, 0, 44100 / 2) 168 169 48 170 if __name__ == '__main__': 49 main() 171 import nose2 172 nose2.main() -
python/tests/test_fvec.py
r5b46bc3 r633400d 60 60 self.assertRaises(IndexError, a.__getitem__, 3) 61 61 self.assertRaises(IndexError, a.__getitem__, 2) 62 63 def test_wrong_dimensions(self): 64 a = np.array([[[1, 2], [3, 4]]], dtype=float_type) 65 self.assertRaises(ValueError, fvec, a) 66 67 def test_wrong_size(self): 68 a = np.ndarray([0,], dtype=float_type) 69 self.assertRaises(ValueError, fvec, a) 62 70 63 71 class aubio_wrong_fvec_input(TestCase): -
python/tests/test_mfcc.py
r5b46bc3 r633400d 111 111 #print coeffs 112 112 113 114 class aubio_mfcc_fb_params(TestCase): 115 116 def test_set_scale(self): 117 buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 118 m = mfcc(buf_size, n_filters, n_coeffs, samplerate) 119 m.set_scale(10.5) 120 assert m.get_scale() == 10.5 121 m(cvec(buf_size)) 122 123 def test_set_power(self): 124 buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 125 m = mfcc(buf_size, n_filters, n_coeffs, samplerate) 126 m.set_power(2.5) 127 assert m.get_power() == 2.5 128 m(cvec(buf_size)) 129 130 def test_set_mel_coeffs(self): 131 buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 132 m = mfcc(buf_size, n_filters, n_coeffs, samplerate) 133 m.set_mel_coeffs(0., samplerate/2.) 134 m(cvec(buf_size)) 135 136 def test_set_mel_coeffs_htk(self): 137 buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 138 m = mfcc(buf_size, n_filters, n_coeffs, samplerate) 139 m.set_mel_coeffs_htk(0., samplerate/2.) 140 m(cvec(buf_size)) 141 142 def test_set_mel_coeffs_slaney(self): 143 buf_size, n_filters, n_coeffs, samplerate = 512, 40, 10, 16000 144 m = mfcc(buf_size, n_filters, n_coeffs, samplerate) 145 m.set_mel_coeffs_slaney() 146 m(cvec(buf_size)) 147 assert m.get_power() == 1 148 assert m.get_scale() == 1 149 113 150 if __name__ == '__main__': 114 151 main() -
python/tests/test_midi2note.py
r5b46bc3 r633400d 3 3 4 4 from aubio import midi2note 5 from nose2.tools import params 5 6 import unittest 6 7 … … 17 18 class midi2note_good_values(unittest.TestCase): 18 19 19 def test_midi2note_known_values(self): 20 @params(*list_of_known_midis) 21 def test_midi2note_known_values(self, midi, note): 20 22 " known values are correctly converted " 21 for midi, note in list_of_known_midis: 22 self.assertEqual ( midi2note(midi), note ) 23 self.assertEqual ( midi2note(midi), note ) 23 24 24 25 class midi2note_wrong_values(unittest.TestCase): … … 41 42 42 43 if __name__ == '__main__': 43 unittest.main() 44 import nose2 45 nose2.main() -
python/tests/test_note2midi.py
r5b46bc3 r633400d 4 4 from __future__ import unicode_literals 5 5 6 from aubio import note2midi, freq2note 6 from aubio import note2midi, freq2note, note2freq, float_type 7 from nose2.tools import params 7 8 import unittest 8 9 … … 14 15 ( 'B3', 59 ), 15 16 ( 'B#3', 60 ), 17 ( 'C♯4', 61 ), 16 18 ( 'A4', 69 ), 17 19 ( 'A#4', 70 ), 20 ( 'A♯4', 70 ), 21 ( 'A\u266f4', 70 ), 18 22 ( 'Bb4', 70 ), 19 23 ( 'B♭4', 70 ), 24 ( 'B\u266d4', 70 ), 20 25 ( 'G8', 115 ), 21 26 ( 'G♯8', 116 ), 22 27 ( 'G9', 127 ), 23 ( 'G\udd2a2', 45 ),24 ( 'B\ufffd2', 45 ),25 28 ( 'A♮2', 45 ), 29 ) 30 31 list_of_known_notes_with_unicode_issues = ( 32 ('C𝄪4', 62 ), 33 ('E𝄫4', 62 ), 34 ) 35 36 list_of_unknown_notes = ( 37 ( 'G\udd2a2' ), 38 ( 'B\ufffd2' ), 39 ( 'B\u266e\u266e2' ), 40 ( 'B\u266f\u266d3' ), 41 ( 'B33' ), 42 ( 'C.3' ), 43 ( 'A' ), 44 ( '2' ), 26 45 ) 27 46 28 47 class note2midi_good_values(unittest.TestCase): 29 48 30 def test_note2midi_known_values(self): 49 @params(*list_of_known_notes) 50 def test_note2midi_known_values(self, note, midi): 31 51 " known values are correctly converted " 32 for note, midi in list_of_known_notes: 52 self.assertEqual ( note2midi(note), midi ) 53 54 @params(*list_of_known_notes_with_unicode_issues) 55 def test_note2midi_known_values_with_unicode_issues(self, note, midi): 56 " known values are correctly converted, unless decoding is expected to fail" 57 try: 33 58 self.assertEqual ( note2midi(note), midi ) 59 except UnicodeEncodeError as e: 60 import sys 61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}" 62 strres = strfmt.format(e, sys.platform, sys.version) 63 # happens with: darwin 2.7.10, windows 2.7.12 64 if len('\U0001D12A') != 1 and sys.version[0] == '2': 65 self.skipTest(strres + " | upgrade to Python 3 to fix") 66 else: 67 raise 34 68 35 69 class note2midi_wrong_values(unittest.TestCase): … … 67 101 self.assertRaises(TypeError, note2midi, 123) 68 102 103 def test_note2midi_wrong_data_too_long(self): 104 " fails when passed a note with a note name longer than expected" 105 self.assertRaises(ValueError, note2midi, 'CB+-3') 106 107 @params(*list_of_unknown_notes) 108 def test_note2midi_unknown_values(self, note): 109 " unknown values throw out an error " 110 self.assertRaises(ValueError, note2midi, note) 69 111 70 112 class freq2note_simple_test(unittest.TestCase): 71 113 72 def test_freq2note (self):114 def test_freq2note_above(self): 73 115 " make sure freq2note(441) == A4 " 74 116 self.assertEqual("A4", freq2note(441)) 75 117 118 def test_freq2note_under(self): 119 " make sure freq2note(439) == A4 " 120 self.assertEqual("A4", freq2note(439)) 121 122 class note2freq_simple_test(unittest.TestCase): 123 124 def test_note2freq(self): 125 " make sure note2freq('A3') == 220" 126 self.assertEqual(220, note2freq("A3")) 127 128 def test_note2freq_under(self): 129 " make sure note2freq(A4) == 440" 130 if float_type == 'float32': 131 self.assertEqual(440, note2freq("A4")) 132 else: 133 self.assertLess(abs(note2freq("A4")-440), 1.e-12) 134 76 135 if __name__ == '__main__': 77 unittest.main() 136 import nose2 137 nose2.main() -
python/tests/test_onset.py
r5b46bc3 r633400d 3 3 from unittest import main 4 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 from aubio import onset 5 from aubio import onset, fvec 6 6 7 7 class aubio_onset_default(TestCase): … … 20 20 21 21 def test_get_delay(self): 22 assert_equal (self.o.get_delay(), int(4.3 * self.o.hop_size))22 self.assertGreater(self.o.get_delay(), 0) 23 23 24 24 def test_get_delay_s(self): 25 assert_almost_equal (self.o.get_delay_s(), self.o.get_delay() / float(self.samplerate))25 self.assertGreater(self.o.get_delay_s(), 0.) 26 26 27 27 def test_get_delay_ms(self): 28 assert_almost_equal (self.o.get_delay_ms(), self.o.get_delay() * 1000. / self.samplerate, 5)28 self.assertGreater(self.o.get_delay_ms(), 0.) 29 29 30 30 def test_get_minioi(self): 31 assert_almost_equal (self.o.get_minioi(), 0.02 * self.samplerate)31 self.assertGreater(self.o.get_minioi(), 0) 32 32 33 33 def test_get_minioi_s(self): 34 assert_almost_equal (self.o.get_minioi_s(), 0.02)34 self.assertGreater(self.o.get_minioi_s(), 0.) 35 35 36 36 def test_get_minioi_ms(self): 37 assert_equal (self.o.get_minioi_ms(), 20.)37 self.assertGreater(self.o.get_minioi_ms(), 0.) 38 38 39 39 def test_get_threshold(self): 40 assert_almost_equal (self.o.get_threshold(), 0.3)40 self.assertGreater(self.o.get_threshold(), 0.) 41 41 42 42 def test_set_delay(self): … … 84 84 samplerate = 8000 85 85 86 class aubio_onset_coverate(TestCase): 87 # extra tests to execute the C routines and improve coverage 88 89 def test_all_methods(self): 90 for method in ['default', 'energy', 'hfc', 'complexdomain', 'complex', 91 'phase', 'wphase', 'mkl', 'kl', 'specflux', 'specdiff', 92 'old_default']: 93 o = onset(method=method, buf_size=512, hop_size=256) 94 o(fvec(256)) 95 96 def test_get_methods(self): 97 o = onset(method='default', buf_size=512, hop_size=256) 98 99 assert o.get_silence() == -70 100 o.set_silence(-20) 101 assert_almost_equal(o.get_silence(), -20) 102 103 assert o.get_compression() == 1 104 o.set_compression(.99) 105 assert_almost_equal(o.get_compression(), .99) 106 107 assert o.get_awhitening() == 0 108 o.set_awhitening(1) 109 assert o.get_awhitening() == 1 110 111 o.get_last() 112 o.get_last_ms() 113 o.get_last_s() 114 o.get_descriptor() 115 o.get_thresholded_descriptor() 116 117 86 118 if __name__ == '__main__': 87 119 main() -
python/tests/test_phasevoc.py
r5b46bc3 r633400d 47 47 assert_equal ( t, 0.) 48 48 assert_equal ( s.norm, 0.) 49 assert_equal ( s.phas, 0.) 49 try: 50 assert_equal ( s.phas, 0 ) 51 except AssertionError: 52 assert_equal (s.phas[s.phas > 0], +np.pi) 53 assert_equal (s.phas[s.phas < 0], -np.pi) 54 assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0) 55 self.skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \ 56 + 'This is expected when using fftw3 on powerpc.') 50 57 assert_equal ( r, 0.) 58 59 def test_no_overlap(self): 60 win_s, hop_s = 1024, 1024 61 f = pvoc (win_s, hop_s) 62 t = fvec (hop_s) 63 for _ in range(4): 64 s = f(t) 65 r = f.rdo(s) 66 assert_equal ( t, 0.) 51 67 52 68 @params( -
python/tests/test_pitch.py
r5b46bc3 r633400d 71 71 #print 'median errors: ', median(errors), 'median pitches: ', median(pitches) 72 72 73 pitch_algorithms = [ "default", "yinfft", "yin", " schmitt", "mcomb", "fcomb" , "specacf" ]74 pitch_algorithms = [ "default", "yinfft", "yin", " schmitt", "mcomb", "fcomb" ]73 pitch_algorithms = [ "default", "yinfft", "yin", "yinfast", "schmitt", "mcomb", "fcomb" , "specacf" ] 74 pitch_algorithms = [ "default", "yinfft", "yin", "yinfast", "schmitt", "mcomb", "fcomb" ] 75 75 76 76 #freqs = [ 27.5, 55., 110., 220., 440., 880., 1760., 3520. ] -
python/tests/test_sink.py
r5b46bc3 r633400d 5 5 from numpy.testing import TestCase 6 6 from aubio import fvec, source, sink 7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 7 from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 8 9 import warnings 10 warnings.filterwarnings('ignore', category=UserWarning, append=True) 8 11 9 12 list_of_sounds = list_all_sounds('sounds') … … 26 29 if not len(list_of_sounds): 27 30 self.skipTest('add some sound files in \'python/tests/sounds\'') 31 32 def test_wrong_filename(self): 33 with self.assertRaises(RuntimeError): 34 sink('') 35 36 def test_wrong_samplerate(self): 37 with self.assertRaises(RuntimeError): 38 sink(get_tmp_sink_path(), -1) 39 40 def test_wrong_samplerate_too_large(self): 41 with self.assertRaises(RuntimeError): 42 sink(get_tmp_sink_path(), 1536001, 2) 43 44 def test_wrong_channels(self): 45 with self.assertRaises(RuntimeError): 46 sink(get_tmp_sink_path(), 44100, -1) 47 48 def test_wrong_channels_too_large(self): 49 with self.assertRaises(RuntimeError): 50 sink(get_tmp_sink_path(), 44100, 202020) 28 51 29 52 def test_many_sinks(self): … … 94 117 del_tmp_sink_path(sink_path) 95 118 119 def test_read_with(self): 120 samplerate = 44100 121 sink_path = get_tmp_sink_path() 122 vec = fvec(128) 123 with sink(sink_path, samplerate) as g: 124 for _ in range(10): 125 g(vec, 128) 126 96 127 if __name__ == '__main__': 97 128 main() -
python/tests/test_slicing.py
r5b46bc3 r633400d 4 4 from numpy.testing import TestCase, assert_equal 5 5 from aubio import slice_source_at_stamps 6 from utils import count_files_in_directory, get_default_test_sound7 from utils import count_samples_in_directory, count_samples_in_file6 from .utils import count_files_in_directory, get_default_test_sound 7 from .utils import count_samples_in_directory, count_samples_in_file 8 8 9 9 import tempfile … … 24 24 def test_slice_start_only_no_zero(self): 25 25 regions_start = [i*1000 for i in range(1, n_slices)] 26 slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) 26 slice_source_at_stamps(self.source_file, regions_start, 27 output_dir = self.output_dir, create_first=True) 27 28 28 29 def test_slice_start_beyond_end(self): 29 30 regions_start = [i*1000 for i in range(1, n_slices)] 30 31 regions_start += [count_samples_in_file(self.source_file) + 1000] 31 slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) 32 slice_source_at_stamps(self.source_file, regions_start, 33 output_dir = self.output_dir, create_first=True) 32 34 33 35 def test_slice_start_every_blocksize(self): 34 36 hopsize = 200 35 regions_start = [i*hopsize for i in range( 1, n_slices)]37 regions_start = [i*hopsize for i in range(0, n_slices)] 36 38 slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir, 37 39 hopsize = 200) 40 41 def test_slice_start_every_half_blocksize(self): 42 hopsize = 200 43 regions_start = [i*hopsize//2 for i in range(0, n_slices)] 44 slice_source_at_stamps(self.source_file, regions_start, 45 output_dir = self.output_dir, hopsize = 200) 38 46 39 47 def tearDown(self): … … 92 100 "number of samples written different from number of original samples") 93 101 102 def test_slice_start_and_ends_with_missing_end(self): 103 regions_start = [i*1000 for i in range(n_slices)] 104 regions_ends = [r-1 for r in regions_start[1:]] 105 slice_source_at_stamps(self.source_file, regions_start, regions_ends, 106 output_dir = self.output_dir) 107 written_samples = count_samples_in_directory(self.output_dir) 108 original_samples = count_samples_in_file(self.source_file) 109 total_files = count_files_in_directory(self.output_dir) 110 assert_equal(n_slices, total_files, 111 "number of slices created different from expected") 112 assert_equal(written_samples, original_samples, 113 "number of samples written different from number of original samples") 114 94 115 def tearDown(self): 95 116 shutil.rmtree(self.output_dir) … … 134 155 regions_end = None 135 156 slice_source_at_stamps (self.source_file, regions_start, regions_end, 136 output_dir = self.output_dir )157 output_dir = self.output_dir, create_first=True) 137 158 total_files = count_files_in_directory(self.output_dir) 138 159 assert_equal(n_slices, total_files, -
python/tests/test_source.py
r5b46bc3 r633400d 3 3 from nose2 import main 4 4 from nose2.tools import params 5 from numpy.testing import TestCase 5 from numpy.testing import TestCase, assert_equal 6 6 from aubio import source 7 from utils import list_all_sounds7 from .utils import list_all_sounds 8 8 9 9 import warnings … … 52 52 total_frames = 0 53 53 while True: 54 _, read = f()54 samples , read = f() 55 55 total_frames += read 56 if read < f.hop_size: break 56 if read < f.hop_size: 57 assert_equal(samples[read:], 0) 58 break 57 59 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" 58 60 #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri … … 67 69 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e))) 68 70 assert f.samplerate != 0 69 self.read_from_source(f) 71 read_frames = self.read_from_source(f) 72 if 'f_' in soundfile and samplerate == 0: 73 import re 74 f = re.compile('.*_\([0:9]*f\)_.*') 75 match_f = re.findall('([0-9]*)f_', soundfile) 76 if len(match_f) == 1: 77 expected_frames = int(match_f[0]) 78 self.assertEqual(expected_frames, read_frames) 70 79 71 80 @params(*list_of_sounds) … … 150 159 total_frames = 0 151 160 while True: 152 _, read = f.do_multi()161 samples, read = f.do_multi() 153 162 total_frames += read 154 if read < f.hop_size: break 163 if read < f.hop_size: 164 assert_equal(samples[:,read:], 0) 165 break 155 166 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" 156 167 #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri … … 158 169 return total_frames 159 170 171 class aubio_source_with(aubio_source_test_case_base): 172 173 #@params(*list_of_sounds) 174 @params(*list_of_sounds) 175 def test_read_from_mono(self, filename): 176 total_frames = 0 177 hop_size = 2048 178 with source(filename, 0, hop_size) as input_source: 179 assert_equal(input_source.hop_size, hop_size) 180 #assert_equal(input_source.samplerate, samplerate) 181 total_frames = 0 182 for frames in input_source: 183 total_frames += frames.shape[-1] 184 # check we read as many samples as we expected 185 assert_equal(total_frames, input_source.duration) 186 160 187 if __name__ == '__main__': 161 188 main()
Note: See TracChangeset
for help on using the changeset viewer.