Changeset 1594d49 for tests/python/src
- Timestamp:
- Oct 8, 2009, 2:00:52 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:
- 8fe9c10
- Parents:
- db62622
- Location:
- tests/python/src/spectral
- Files:
-
- 1 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/python/src/spectral/filterbank.py
rdb62622 r1594d49 1 2 import unittest 3 from aubio.aubiowrapper import * 1 from template import aubio_unit_template 2 from localaubio import * 4 3 5 4 win_size = 2048 … … 7 6 n_filters = 40 8 7 samplerate = 44100 9 zerodb = -96.01560211181640610 8 11 9 class filterbank_test_case(unittest.TestCase): … … 22 20 23 21 def testzeroes(self): 24 """ check the output of the filterbank is -96when input spectrum is 0 """22 """ check the output of the filterbank is 0 when input spectrum is 0 """ 25 23 aubio_filterbank_do(self.filterbank,self.input_spectrum, 26 24 self.output_banks) 27 25 for channel in range(channels): 28 26 for index in range(n_filters): 29 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), zerodb)27 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0) 30 28 31 29 def testphase(self): 32 """ check the output of the filterbank is -96when input phase is pi """30 """ check the output of the filterbank is 0 when input phase is pi """ 33 31 from math import pi 34 32 for channel in range(channels): … … 39 37 for channel in range(channels): 40 38 for index in range(n_filters): 41 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), zerodb)39 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0) 42 40 43 41 def testones(self): 44 """ check the output of the filterbank is -96when input norm is 142 """ check the output of the filterbank is 0 when input norm is 1 45 43 (the filterbank is currently set to 0). 46 44 """ … … 52 50 for channel in range(channels): 53 51 for index in range(n_filters): 54 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), zerodb)52 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0) 55 53 56 54 def testmfcc_zeroes(self): 57 """ check the mfcc filterbank output is -96when input is 0 """58 self.filterbank = new_aubio_filterbank _mfcc(n_filters, win_size, samplerate, 0., samplerate)59 aubio_filterbank_do(self.filterbank, self.input_spectrum,55 """ check the mfcc filterbank output is 0 when input is 0 """ 56 self.filterbank = new_aubio_filterbank(n_filters, win_size) 57 aubio_filterbank_do(self.filterbank, self.input_spectrum, 60 58 self.output_banks) 61 59 for channel in range(channels): 62 60 for index in range(n_filters): 63 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), zerodb)61 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0) 64 62 65 63 def testmfcc_phasepi(self): 66 """ check the mfcc filterbank output is -96 when input phase is pi """ 67 self.filterbank = new_aubio_filterbank_mfcc(n_filters, win_size, samplerate, 0., samplerate) 64 """ check the mfcc filterbank output is 0 when input phase is pi """ 65 self.filterbank = new_aubio_filterbank(n_filters, win_size) 66 aubio_filterbank_set_mel_coeffs_slaney(self.filterbank, samplerate) 68 67 from math import pi 69 68 for channel in range(channels): … … 74 73 for channel in range(channels): 75 74 for index in range(n_filters): 76 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), zerodb)75 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0) 77 76 78 77 def testmfcc_ones(self): 79 """ check setting the input spectrum to 1 gives something between -3. and -4. """ 80 self.filterbank = new_aubio_filterbank_mfcc(n_filters, win_size, samplerate, 0., samplerate) 78 """ check setting the input spectrum to 1 gives something between 0. and 1. """ 79 self.filterbank = new_aubio_filterbank(n_filters, win_size) 80 aubio_filterbank_set_mel_coeffs_slaney(self.filterbank, samplerate) 81 81 for channel in range(channels): 82 82 for index in range(win_size/2+1): … … 87 87 for index in range(n_filters): 88 88 val = fvec_read_sample(self.output_banks,channel,index) 89 self.failIf(val > -2.5, val )90 self.failIf(val < -4. , val )89 self.failIf(val < 0. , val ) 90 self.failIf(val > 1. , val ) 91 91 92 92 def testmfcc_channels(self): 93 93 """ check the values of each filters in the mfcc filterbank """ 94 94 import os.path 95 self.filterbank = new_aubio_filterbank_mfcc(n_filters, win_size, samplerate, 96 0., samplerate) 97 filterbank_mfcc = [ [float(f) for f in line.strip().split()] 98 for line in open(os.path.join('src','spectral','filterbank_mfcc.txt')).readlines()] 95 win_size = 512 96 self.filterbank = new_aubio_filterbank(n_filters, win_size) 97 aubio_filterbank_set_mel_coeffs_slaney(self.filterbank, 16000) 98 filterbank_mfcc = array_from_text_file ( 99 os.path.join('src','spectral','filterbank_mfcc_16000_512.txt') ) 100 vec = aubio_filterbank_get_coeffs(self.filterbank) 99 101 for channel in range(n_filters): 100 vec = aubio_filterbank_getchannel(self.filterbank,channel) 101 for index in range(win_size): 102 self.assertAlmostEqual(fvec_read_sample(vec,0,index), 102 for index in range(win_size/2+1): 103 self.assertAlmostEqual(fvec_read_sample(vec,channel,index), 103 104 filterbank_mfcc[channel][index]) 104 aubio_filterbank_do(self.filterbank, self.input_spectrum,105 aubio_filterbank_do(self.filterbank, self.input_spectrum, 105 106 self.output_banks) 106 107 for channel in range(channels): 107 108 for index in range(n_filters): 108 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), zerodb)109 self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0) 109 110 110 111 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.