Changeset 038852a
- Timestamp:
- Nov 7, 2007, 4:33:43 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:
- d57d1de, e86676b
- Parents:
- 49407f3
- Location:
- tests/python
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/python/fft.py
r49407f3 r038852a 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): … … 85 84 self.assertEqual(0., cvec_read_norm(fftgrain, channel, index)) 86 85 # check norm and phase == 0 in first first and last bin of first channel 87 self.assert AlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision)88 self.assert Equal(0., cvec_read_phas(fftgrain, 0, 0))89 self.assert Equal(0., cvec_read_norm(fftgrain, 0, buf_size/2+1))90 self.assert Equal(0., cvec_read_phas(fftgrain, 0, buf_size/2+1))86 self.assertCloseEnough((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0)) 87 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, 0)) 88 self.assertCloseEnough(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) 89 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) 91 90 # check unwrap2pi(phas) ~= pi everywhere but in first bin 92 91 for index in range(1,buf_size/2+1): 93 self.assert AlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision)94 self.assert AlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)92 self.assertCloseEnough(math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index))) 93 self.assertCloseEnough(some_constant, cvec_read_norm(fftgrain, 0, index)) 95 94 del fftgrain 96 95 del input 97 96 98 def test_ aubio_mfft_do_impulse_multichannel(self):99 " test aubio_ mfft_do on impulse two channels "97 def test_do_impulse_multichannel(self): 98 " test aubio_fft_do on impulse two channels " 100 99 input = new_fvec(buf_size, channels) 101 100 fftgrain = new_cvec(buf_size, channels) … … 103 102 fvec_write_sample(input, 1., 0, 0) 104 103 fvec_write_sample(input, 1., channels-1, 0) 105 aubio_ mfft_do(self.o, input, fftgrain)104 aubio_fft_do(self.o, input, fftgrain) 106 105 # check the norm 107 106 for index in range(buf_size/2+1): … … 119 118 del input 120 119 121 def test_ aubio_mfft_rdo_impulse(self):122 """ test aubio_ mfft_rdo on impulse """120 def test_rdo_impulse(self): 121 """ test aubio_fft_rdo on impulse """ 123 122 fftgrain = new_cvec(buf_size, channels) 124 123 for channel in range(channels): 125 124 cvec_write_norm(fftgrain, 1., channel, 0) 126 125 output = new_fvec(buf_size, channels) 127 aubio_ mfft_rdo(self.o, fftgrain, output)126 aubio_fft_rdo(self.o, fftgrain, output) 128 127 for index in range(buf_size/2+1): 129 128 for channel in range(channels): 130 self.assert AlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)129 self.assertCloseEnough(fvec_read_sample(output, channel, index), 1./buf_size) 131 130 del fftgrain 132 131 del output 133 132 134 def test_ aubio_mfft_do_back_and_forth(self):135 """ test aubio_ mfft_rdo on a constant """133 def test_do_back_and_forth(self): 134 """ test aubio_fft_rdo on a constant """ 136 135 input = new_fvec(buf_size, channels) 137 136 output = new_fvec(buf_size, channels) … … 140 139 for channel in range(channels): 141 140 fvec_write_sample(input, 0.67, channel, index) 142 aubio_ mfft_do(self.o, input, fftgrain)143 aubio_ mfft_rdo(self.o, fftgrain, output)141 aubio_fft_do(self.o, input, fftgrain) 142 aubio_fft_rdo(self.o, fftgrain, output) 144 143 for index in range(buf_size/2+1): 145 144 for channel in range(channels): 146 self.assert AlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision)145 self.assertCloseEnough(0.67, fvec_read_sample(output, channel, index)) 147 146 del fftgrain 148 147 del output
Note: See TracChangeset
for help on using the changeset viewer.