- Timestamp:
- Nov 7, 2007, 4:51:42 PM (17 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:
- 4368223
- Parents:
- e00f769 (diff), 038852a (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:
- tests/python
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/python/fft.py
re00f769 rd57d1de 1 import unittest2 1 import math 2 3 from template import aubio_unit_template 3 4 4 5 from aubio.aubiowrapper import * 5 6 6 buf_size = 80927 buf_size = 1024 7 8 channels = 4 8 9 9 precision = 6 10 11 class aubio_mfft_test_case(unittest.TestCase): 10 class fft_unit(aubio_unit_template): 12 11 13 12 def setUp(self): 14 self.o = new_aubio_ mfft(buf_size, channels)13 self.o = new_aubio_fft(buf_size, channels) 15 14 16 15 def tearDown(self): 17 del_aubio_ mfft(self.o)16 del_aubio_fft(self.o) 18 17 19 18 def test_create(self): … … 21 20 pass 22 21 23 def test_ aubio_mfft_do_zeroes(self):24 """ test aubio_ mfft_do on zeroes """22 def test_do_zeroes(self): 23 """ test aubio_fft_do on zeroes """ 25 24 input = new_fvec(buf_size, channels) 26 25 fftgrain = new_cvec(buf_size, channels) 27 26 for index in range(buf_size): 28 27 for channel in range(channels): 29 self.assert Equal(0., fvec_read_sample(input, channel, index))30 aubio_ mfft_do(self.o, input, fftgrain)28 self.assertCloseEnough(0., fvec_read_sample(input, channel, index)) 29 aubio_fft_do(self.o, input, fftgrain) 31 30 for index in range(buf_size/2+1): 32 31 for channel in range(channels): 33 self.assert Equal(0., cvec_read_norm(fftgrain, channel, index))32 self.assertCloseEnough(0., cvec_read_norm(fftgrain, channel, index)) 34 33 for index in range(buf_size/2+1): 35 34 for channel in range(channels): 36 self.assert Equal(0., cvec_read_phas(fftgrain, channel, index))35 self.assertCloseEnough(0., cvec_read_phas(fftgrain, channel, index)) 37 36 del fftgrain 38 37 del input 39 38 40 def test_ aubio_mfft_rdo_zeroes(self):41 """ test aubio_ mfft_rdo on zeroes """39 def test_rdo_zeroes(self): 40 """ test aubio_fft_rdo on zeroes """ 42 41 fftgrain = new_cvec(buf_size, channels) 43 42 output = new_fvec(buf_size, channels) 44 aubio_ mfft_rdo(self.o, fftgrain, output)43 aubio_fft_rdo(self.o, fftgrain, output) 45 44 # check output 46 45 for index in range(buf_size): … … 50 49 del output 51 50 52 def test_ aubio_mfft_do_impulse(self):53 """ test aubio_ mfft_do with an impulse on one channel """51 def test_do_impulse(self): 52 """ test aubio_fft_do with an impulse on one channel """ 54 53 input = new_fvec(buf_size, channels) 55 54 fftgrain = new_cvec(buf_size, channels) … … 57 56 some_constant = 0.3412432456 58 57 fvec_write_sample(input, some_constant, 0, 0) 59 aubio_ mfft_do(self.o, input, fftgrain)58 aubio_fft_do(self.o, input, fftgrain) 60 59 # check norm 61 60 for index in range(buf_size/2+1): 62 self.assert AlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)61 self.assertCloseEnough(some_constant, cvec_read_norm(fftgrain, 0, index)) 63 62 for index in range(buf_size/2+1): 64 63 for channel in range(1, channels): … … 71 70 del input 72 71 73 def test_ aubio_mfft_do_constant(self):74 """ test aubio_ mfft_do with a constant on one channel """72 def test_do_constant(self): 73 """ test aubio_fft_do with a constant on one channel """ 75 74 input = new_fvec(buf_size, channels) 76 75 fftgrain = new_cvec(buf_size, channels) … … 79 78 for index in range(1,buf_size): 80 79 fvec_write_sample(input, some_constant, 0, index) 81 aubio_ mfft_do(self.o, input, fftgrain)80 aubio_fft_do(self.o, input, fftgrain) 82 81 # check norm and phase == 0 in all other channels 83 82 for index in range(buf_size/2+1): 84 83 for channel in range(1, channels): 85 84 self.assertEqual(0., cvec_read_norm(fftgrain, channel, index)) 85 self.assertEqual(0., cvec_read_phas(fftgrain, channel, index)) 86 86 87 # check norm and phase == 0 in first first and last bin of first channel 87 self.assertAlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision) 88 self.assertEqual(0., cvec_read_phas(fftgrain, 0, 0)) 89 self.assertEqual(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) 90 self.assertEqual(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) 91 # check unwrap2pi(phas) ~= pi everywhere but in first bin 88 # check unwrap2pi(phas) ~= pi everywhere but in first and last bin 89 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, 0)) 90 for index in range(1,buf_size/2): 91 self.assertCloseEnough(math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index))) 92 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2)) 93 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) 94 95 self.assertCloseEnough((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0)) 92 96 for index in range(1,buf_size/2+1): 93 self.assertAlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision) 94 self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision) 97 self.assertCloseEnough(some_constant, abs(cvec_read_norm(fftgrain, 0, index))) 98 self.assertCloseEnough(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) 99 95 100 del fftgrain 96 101 del input 97 102 98 def test_ aubio_mfft_do_impulse_multichannel(self):99 " test aubio_ mfft_do on impulse two channels "103 def test_do_impulse_multichannel(self): 104 " test aubio_fft_do on impulse two channels " 100 105 input = new_fvec(buf_size, channels) 101 106 fftgrain = new_cvec(buf_size, channels) … … 103 108 fvec_write_sample(input, 1., 0, 0) 104 109 fvec_write_sample(input, 1., channels-1, 0) 105 aubio_ mfft_do(self.o, input, fftgrain)110 aubio_fft_do(self.o, input, fftgrain) 106 111 # check the norm 107 112 for index in range(buf_size/2+1): … … 119 124 del input 120 125 121 def test_ aubio_mfft_rdo_impulse(self):122 """ test aubio_ mfft_rdo on impulse """126 def test_rdo_impulse(self): 127 """ test aubio_fft_rdo on impulse """ 123 128 fftgrain = new_cvec(buf_size, channels) 124 129 for channel in range(channels): 125 130 cvec_write_norm(fftgrain, 1., channel, 0) 126 131 output = new_fvec(buf_size, channels) 127 aubio_ mfft_rdo(self.o, fftgrain, output)132 aubio_fft_rdo(self.o, fftgrain, output) 128 133 for index in range(buf_size/2+1): 129 134 for channel in range(channels): 130 self.assert AlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)135 self.assertCloseEnough(fvec_read_sample(output, channel, index), 1./buf_size) 131 136 del fftgrain 132 137 del output 133 138 134 def test_ aubio_mfft_do_back_and_forth(self):135 """ test aubio_ mfft_rdo on a constant """139 def test_do_back_and_forth(self): 140 """ test aubio_fft_rdo on a constant """ 136 141 input = new_fvec(buf_size, channels) 137 142 output = new_fvec(buf_size, channels) … … 140 145 for channel in range(channels): 141 146 fvec_write_sample(input, 0.67, channel, index) 142 aubio_ mfft_do(self.o, input, fftgrain)143 aubio_ mfft_rdo(self.o, fftgrain, output)147 aubio_fft_do(self.o, input, fftgrain) 148 aubio_fft_rdo(self.o, fftgrain, output) 144 149 for index in range(buf_size/2+1): 145 150 for channel in range(channels): 146 self.assert AlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision)151 self.assertCloseEnough(0.67, fvec_read_sample(output, channel, index)) 147 152 del fftgrain 148 153 del output
Note: See TracChangeset
for help on using the changeset viewer.