Changeset 1a6ef2c for interfaces
- Timestamp:
- Dec 25, 2009, 4:57:49 AM (15 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 9c9cd54
- Parents:
- 84e0606
- Location:
- interfaces/python
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/test_fft.py
r84e0606 r1a6ef2c 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 # WARNING: numpy also has an fft object 4 from _aubio import fft, fvec, cvec 4 from _aubio import fft, cvec 5 from aubio import fvec 5 6 from numpy import array, shape 6 7 from math import pi … … 10 11 def test_members(self): 11 12 f = fft() 12 assert_equal ([f.win_s, f.channels], [1024, 1]) 13 f = fft(2048, 4) 14 assert_equal ([f.win_s, f.channels], [2048, 4]) 13 assert_equal (f.win_s, 1024) 15 14 16 15 def test_output_dimensions(self): 17 16 """ check the dimensions of output """ 18 win_s , chan = 1024, 319 timegrain = fvec(win_s , chan)20 f = fft(win_s , chan)17 win_s = 1024 18 timegrain = fvec(win_s) 19 f = fft(win_s) 21 20 fftgrain = f (timegrain) 22 assert_equal (array(fftgrain), 0)23 assert_equal (shape(fftgrain), (chan * 2, win_s/2+1))24 21 assert_equal (fftgrain.norm, 0) 25 assert_equal (shape(fftgrain.norm), ( chan, win_s/2+1))22 assert_equal (shape(fftgrain.norm), (win_s/2+1,)) 26 23 assert_equal (fftgrain.phas, 0) 27 assert_equal (shape(fftgrain.phas), ( chan, win_s/2+1))24 assert_equal (shape(fftgrain.phas), (win_s/2+1,)) 28 25 29 26 def test_zeros(self): 30 27 """ check the transform of zeros """ 31 win_s , chan = 512, 332 timegrain = fvec(win_s , chan)33 f = fft(win_s , chan)28 win_s = 512 29 timegrain = fvec(win_s) 30 f = fft(win_s) 34 31 fftgrain = f(timegrain) 35 32 assert_equal ( fftgrain.norm == 0, True ) … … 40 37 from random import random 41 38 from math import floor 42 win_s , chan = 256, 139 win_s = 256 43 40 i = floor(random()*win_s) 44 41 impulse = pi * random() 45 f = fft(win_s , chan)46 timegrain = fvec(win_s , chan)47 timegrain[ 0][i] = impulse42 f = fft(win_s) 43 timegrain = fvec(win_s) 44 timegrain[i] = impulse 48 45 fftgrain = f ( timegrain ) 49 #self.plot_this ( fftgrain.phas [0])46 #self.plot_this ( fftgrain.phas ) 50 47 assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 ) 51 48 assert_equal ( fftgrain.phas <= pi, True) … … 56 53 from random import random 57 54 from math import floor 58 win_s , chan = 256, 155 win_s = 256 59 56 i = 0 60 57 impulse = -10. 61 f = fft(win_s , chan)62 timegrain = fvec(win_s , chan)63 timegrain[ 0][i] = impulse58 f = fft(win_s) 59 timegrain = fvec(win_s) 60 timegrain[i] = impulse 64 61 fftgrain = f ( timegrain ) 65 #self.plot_this ( fftgrain.phas [0])62 #self.plot_this ( fftgrain.phas ) 66 63 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 ) 67 64 if impulse < 0: 68 65 # phase can be pi or -pi, as it is not unwrapped 69 assert_almost_equal ( abs(fftgrain.phas[ 0][1:-1]) , pi, decimal = 6 )70 assert_almost_equal ( fftgrain.phas[0] [0], pi, decimal = 6)71 assert_almost_equal ( fftgrain.phas[ 0][-1], pi, decimal = 6)66 assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 ) 67 assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6) 68 assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6) 72 69 else: 73 assert_equal ( fftgrain.phas[ 0][1:-1] == 0, True)74 assert_equal ( fftgrain.phas[0] [0]== 0, True)75 assert_equal ( fftgrain.phas[ 0][-1] == 0, True)70 assert_equal ( fftgrain.phas[1:-1] == 0, True) 71 assert_equal ( fftgrain.phas[0] == 0, True) 72 assert_equal ( fftgrain.phas[-1] == 0, True) 76 73 # now check the resynthesis 77 74 synthgrain = f.rdo ( fftgrain ) … … 83 80 84 81 def test_impulse_at_zero(self): 85 """ check the transform of one impulse at a index 0 in one channel"""86 win_s , chan = 1024, 282 """ check the transform of one impulse at a index 0 """ 83 win_s = 1024 87 84 impulse = pi 88 f = fft(win_s , chan)89 timegrain = fvec(win_s , chan)90 timegrain[0] [0]= impulse85 f = fft(win_s) 86 timegrain = fvec(win_s) 87 timegrain[0] = impulse 91 88 fftgrain = f ( timegrain ) 92 89 #self.plot_this ( fftgrain.phas ) 93 90 assert_equal ( fftgrain.phas[0], 0) 94 91 assert_equal ( fftgrain.phas[1], 0) 95 assert_almost_equal ( fftgrain.norm[0], impulse, decimal = 6 ) 96 assert_equal ( fftgrain.norm[0], impulse) 92 assert_almost_equal (fftgrain.norm[0], impulse, decimal = 6 ) 97 93 98 94 def test_rdo_before_do(self): 99 95 """ check running fft.rdo before fft.do works """ 100 win_s , chan = 1024, 296 win_s = 1024 101 97 impulse = pi 102 f = fft(win_s , chan)103 fftgrain = cvec(win_s , chan)98 f = fft(win_s) 99 fftgrain = cvec(win_s) 104 100 t = f.rdo( fftgrain ) 105 101 assert_equal ( t, 0 ) -
interfaces/python/test_filter.py
r84e0606 r1a6ef2c 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 from _aubio import * 4 from aubio import fvec 4 5 from numpy import array 5 6 … … 12 13 def test_members(self): 13 14 f = digital_filter() 14 assert_equal ( [f.channels, f.order], [1, 7])15 f = digital_filter(5 , 2)16 assert_equal ( [f.channels, f.order], [2, 5])15 assert_equal (f.order, 7) 16 f = digital_filter(5) 17 assert_equal (f.order, 5) 17 18 f(fvec()) 18 19 19 20 def test_cweighting_error(self): 20 f = digital_filter (2 , 1)21 f = digital_filter (2) 21 22 self.assertRaises ( ValueError, f.set_c_weighting, 44100 ) 22 f = digital_filter (8 , 1)23 f = digital_filter (8) 23 24 self.assertRaises ( ValueError, f.set_c_weighting, 44100 ) 24 f = digital_filter (5 , 1)25 f = digital_filter (5) 25 26 self.assertRaises ( ValueError, f.set_c_weighting, 4000 ) 26 f = digital_filter (5 , 1)27 f = digital_filter (5) 27 28 self.assertRaises ( ValueError, f.set_c_weighting, 193000 ) 28 f = digital_filter (7 , 1)29 f = digital_filter (7) 29 30 self.assertRaises ( ValueError, f.set_a_weighting, 193000 ) 30 f = digital_filter (5 , 1)31 f = digital_filter (5) 31 32 self.assertRaises ( ValueError, f.set_a_weighting, 192000 ) 32 33 33 34 def test_c_weighting(self): 34 35 expected = array_from_text_file('c_weighting_test_simple.expected') 35 f = digital_filter(5 , 1)36 f = digital_filter(5) 36 37 f.set_c_weighting(44100) 37 38 v = fvec(32) 38 v[ 0][12] = .539 v[12] = .5 39 40 u = f(v) 40 41 assert_almost_equal (expected[1], u) … … 42 43 def test_a_weighting(self): 43 44 expected = array_from_text_file('a_weighting_test_simple.expected') 44 f = digital_filter(7 , 1)45 f = digital_filter(7) 45 46 f.set_a_weighting(44100) 46 47 v = fvec(32) 47 v[ 0][12] = .548 v[12] = .5 48 49 u = f(v) 49 50 assert_almost_equal (expected[1], u) … … 51 52 def test_a_weighting_parted(self): 52 53 expected = array_from_text_file('a_weighting_test_simple.expected') 53 f = digital_filter(7 , 1)54 f = digital_filter(7) 54 55 f.set_a_weighting(44100) 55 56 v = fvec(16) 56 v[ 0][12] = .557 v[12] = .5 57 58 u = f(v) 58 59 assert_almost_equal (expected[1][:16], u) -
interfaces/python/test_filterbank.py
r84e0606 r1a6ef2c 3 3 from numpy import array, shape 4 4 from _aubio import * 5 #from aubio import cvec 5 6 6 7 class aubio_filter_test_case(TestCase): … … 11 12 a = f.get_coeffs() 12 13 a.T 14 assert_equal(shape (a), (40, 512/2 + 1) ) 13 15 14 16 def test_other_slaney(self): … … 23 25 #print "sum is", sum(sum(a)) 24 26 25 def test_triangle_freqs (self):27 def test_triangle_freqs_zeros(self): 26 28 f = filterbank(9, 1024) 27 29 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] … … 29 31 f.set_triangle_bands(freqs, 48000) 30 32 f.get_coeffs().T 31 assert_equal ( f(cvec(1024)), [0] * 9) 33 assert_equal ( f(cvec(1024)), 0) 34 35 def test_triangle_freqs_ones(self): 36 f = filterbank(9, 1024) 37 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] 38 freqs = array(freq_list, dtype = 'float32') 39 f.set_triangle_bands(freqs, 48000) 40 f.get_coeffs().T 32 41 spec = cvec(1024) 33 spec[0][40:100] = 100 34 #print f(spec) 42 spec.norm[:] = 1 43 assert_almost_equal ( f(spec), 44 [ 0.02070313, 0.02138672, 0.02127604, 0.02135417, 45 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) 35 46 36 47 if __name__ == '__main__': -
interfaces/python/test_fvec.py
r84e0606 r1a6ef2c 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 from _aubio import * 4 from numpy import array 4 from aubio import fvec 5 from numpy import array, shape 5 6 6 7 class aubio_fvec_test_case(TestCase): 7 8 8 9 9 def test_vector_created_with_zeroes(self): 10 a = fvec() 10 a = fvec(10) 11 a 12 shape(a) 13 a[0] 14 #del a 11 15 assert_equal(array(a), 0.) 12 16 … … 20 24 a[-1] = 1 21 25 assert_equal(a[-1], 1) 22 assert_equal(a[ a.length-1], 1)26 assert_equal(a[len(a)-1], 1) 23 27 24 28 def test_vector(self): 25 29 a = fvec() 26 a, a.length30 a, len(a) #a.length 27 31 a[0] 28 32 array(a) 29 33 a = fvec(10) 30 34 a = fvec(1) 35 a.T 31 36 array(a).T 32 a [0] = range(a.length)37 a = range(len(a)) 33 38 34 39 def test_wrong_values(self): -
interfaces/python/test_onsetdetection.py
r84e0606 r1a6ef2c 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 # WARNING: numpy also has an fft object 4 from _aubio import cvec, specdesc4 from _aubio import specdesc, cvec 5 5 from numpy import array, shape, arange, zeros, log 6 6 from math import pi … … 10 10 def test_members(self): 11 11 o = specdesc() 12 assert_equal ([o.buf_size, o.channels, o.method], 13 [1024, 1, "default"]) 14 o = specdesc("complex", 512, 2) 15 assert_equal ([o.buf_size, o.channels, o.method], 16 [512, 2, "complex"]) 12 assert_equal ([o.buf_size, o.method], 13 [1024, "default"]) 17 14 18 15 def test_hfc(self): … … 22 19 a = arange(c.length, dtype='float32') 23 20 c.norm = a 24 assert_equal (a, c.norm [0])21 assert_equal (a, c.norm) 25 22 assert_equal ( sum(a*(a+1)), o(c)) 26 23 … … 31 28 a = arange(c.length, dtype='float32') 32 29 c.norm = a 33 assert_equal (a, c.norm [0])30 assert_equal (a, c.norm) 34 31 # the previous run was on zeros, so previous frames are still 0 35 32 # so we have sqrt ( abs ( r2 ^ 2) ) == r2 -
interfaces/python/test_phasevoc.py
r84e0606 r1a6ef2c 1 1 from numpy.testing import TestCase, run_module_suite 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 from aubio import fvec 3 4 from _aubio import * 4 5 from numpy import array, shape … … 26 27 def test_steps_two_channels(self): 27 28 """ check the resynthesis of steps is correct """ 28 f = pvoc(1024, 512 , 2)29 t1 = fvec(512 , 2)30 t2 = fvec(512 , 2)29 f = pvoc(1024, 512) 30 t1 = fvec(512) 31 t2 = fvec(512) 31 32 # positive step in first channel 32 t1[ 0][100:200] = .133 t1[100:200] = .1 33 34 # positive step in second channel 34 t1[ 1][20:50] = -.135 t1[20:50] = -.1 35 36 s1 = f(t1) 36 37 r1 = f.rdo(s1) … … 42 43 def test_steps_three_random_channels(self): 43 44 from random import random 44 f = pvoc(64, 16, 3) 45 t0 = fvec(16, 3) 46 t1 = fvec(16, 3) 47 for i in xrange(3): 48 for j in xrange(16): 49 t1[i][j] = random() * 2. - 1. 45 f = pvoc(64, 16) 46 t0 = fvec(16) 47 t1 = fvec(16) 48 for i in xrange(16): 49 t1[i] = random() * 2. - 1. 50 50 t2 = f.rdo(f(t1)) 51 51 t2 = f.rdo(f(t0))
Note: See TracChangeset
for help on using the changeset viewer.