Changeset 1594d49 for tests


Ignore:
Timestamp:
Oct 8, 2009, 2:00:52 AM (15 years ago)
Author:
Paul Brossier <piem@piem.org>
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
Message:

tests/python: updated filterbank test

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 *
     1from template import aubio_unit_template
     2from localaubio import *
    43
    54win_size = 2048
     
    76n_filters = 40
    87samplerate = 44100
    9 zerodb = -96.015602111816406
    108
    119class filterbank_test_case(unittest.TestCase):
     
    2220
    2321  def testzeroes(self):
    24       """ check the output of the filterbank is -96 when input spectrum is 0 """
     22      """ check the output of the filterbank is 0 when input spectrum is 0 """
    2523      aubio_filterbank_do(self.filterbank,self.input_spectrum,
    2624        self.output_banks)
    2725      for channel in range(channels):
    2826        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)
    3028
    3129  def testphase(self):
    32       """ check the output of the filterbank is -96 when input phase is pi """
     30      """ check the output of the filterbank is 0 when input phase is pi """
    3331      from math import pi
    3432      for channel in range(channels):
     
    3937      for channel in range(channels):
    4038        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)
    4240
    4341  def testones(self):
    44       """ check the output of the filterbank is -96 when input norm is 1
     42      """ check the output of the filterbank is 0 when input norm is 1
    4543          (the filterbank is currently set to 0).
    4644      """
     
    5250      for channel in range(channels):
    5351        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)
    5553
    5654  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,
     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,
    6058        self.output_banks)
    6159      for channel in range(channels):
    6260        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)
    6462
    6563  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)
    6867      from math import pi
    6968      for channel in range(channels):
     
    7473      for channel in range(channels):
    7574        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)
    7776
    7877  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)
    8181      for channel in range(channels):
    8282        for index in range(win_size/2+1):
     
    8787        for index in range(n_filters):
    8888          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 )
    9191
    9292  def testmfcc_channels(self):
    9393      """ check the values of each filters in the mfcc filterbank """
    9494      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)
    99101      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),
    103104            filterbank_mfcc[channel][index])
    104       aubio_filterbank_do(self.filterbank,self.input_spectrum,
     105      aubio_filterbank_do(self.filterbank, self.input_spectrum,
    105106        self.output_banks)
    106107      for channel in range(channels):
    107108        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)
    109110
    110111if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.