source: tests/python/src/spectral/filterbank.py @ 6913434

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 6913434 was 66a150a2, checked in by Paul Brossier <piem@piem.org>, 17 years ago

move around files in tests/python according to src/ changes

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