source: tests/python/src/spectral/filterbank.py @ 47f17fc

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 47f17fc was 1594d49, checked in by Paul Brossier <piem@piem.org>, 15 years ago

tests/python: updated filterbank test

  • Property mode set to 100644
File size: 4.6 KB
Line 
1from template import aubio_unit_template
2from localaubio import *
3
4win_size = 2048 
5channels = 1
6n_filters = 40
7samplerate = 44100
8
9class filterbank_test_case(unittest.TestCase):
10 
11  def setUp(self):
12      self.input_spectrum = new_cvec(win_size,channels)
13      self.output_banks = new_fvec(n_filters,channels)
14      self.filterbank = new_aubio_filterbank(n_filters,win_size)
15
16  def tearDown(self):
17      del_aubio_filterbank(self.filterbank)
18      del_cvec(self.input_spectrum)
19      del_fvec(self.output_banks)
20
21  def testzeroes(self):
22      """ check the output of the filterbank is 0 when input spectrum is 0 """
23      aubio_filterbank_do(self.filterbank,self.input_spectrum,
24        self.output_banks) 
25      for channel in range(channels):
26        for index in range(n_filters): 
27          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
28
29  def testphase(self):
30      """ check the output of the filterbank is 0 when input phase is pi """
31      from math import pi
32      for channel in range(channels):
33        for index in range(win_size/2+1): 
34          cvec_write_phas(self.input_spectrum,pi,channel,index)
35      aubio_filterbank_do(self.filterbank,self.input_spectrum,
36        self.output_banks) 
37      for channel in range(channels):
38        for index in range(n_filters): 
39          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
40
41  def testones(self):
42      """ check the output of the filterbank is 0 when input norm is 1
43          (the filterbank is currently set to 0).
44      """
45      for channel in range(channels):
46        for index in range(win_size/2+1): 
47          cvec_write_norm(self.input_spectrum,1.,channel,index)
48      aubio_filterbank_do(self.filterbank,self.input_spectrum,
49        self.output_banks) 
50      for channel in range(channels):
51        for index in range(n_filters): 
52          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
53
54  def testmfcc_zeroes(self):
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,
58        self.output_banks) 
59      for channel in range(channels):
60        for index in range(n_filters): 
61          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
62
63  def testmfcc_phasepi(self):
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)
67      from math import pi
68      for channel in range(channels):
69        for index in range(win_size/2+1): 
70          cvec_write_phas(self.input_spectrum,pi,channel,index)
71      aubio_filterbank_do(self.filterbank,self.input_spectrum,
72        self.output_banks) 
73      for channel in range(channels):
74        for index in range(n_filters): 
75          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
76
77  def testmfcc_ones(self):
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      for channel in range(channels):
82        for index in range(win_size/2+1): 
83          cvec_write_norm(self.input_spectrum,1.,channel,index)
84      aubio_filterbank_do(self.filterbank,self.input_spectrum,
85        self.output_banks) 
86      for channel in range(channels):
87        for index in range(n_filters): 
88          val = fvec_read_sample(self.output_banks,channel,index)
89          self.failIf(val < 0. , val )
90          self.failIf(val > 1. , val )
91
92  def testmfcc_channels(self):
93      """ check the values of each filters in the mfcc filterbank """
94      import os.path
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)
101      for channel in range(n_filters):
102        for index in range(win_size/2+1): 
103          self.assertAlmostEqual(fvec_read_sample(vec,channel,index),
104            filterbank_mfcc[channel][index])
105      aubio_filterbank_do(self.filterbank, self.input_spectrum,
106        self.output_banks) 
107      for channel in range(channels):
108        for index in range(n_filters): 
109          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
110
111if __name__ == '__main__':
112    unittest.main()
Note: See TracBrowser for help on using the repository browser.