Changeset 038852a


Ignore:
Timestamp:
Nov 7, 2007, 4:33:43 PM (16 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:
d57d1de, e86676b
Parents:
49407f3
Message:

updated fft.py tests, added template for assertCloseEnough

Location:
tests/python
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • tests/python/fft.py

    r49407f3 r038852a  
    1 import unittest
    21import math
     2
     3from template import aubio_unit_template
    34
    45from aubio.aubiowrapper import *
    56
    6 buf_size = 8092
     7buf_size = 1024
    78channels = 4
    89
    9 precision = 6
    10 
    11 class aubio_mfft_test_case(unittest.TestCase):
     10class fft_unit(aubio_unit_template):
    1211
    1312  def setUp(self):
    14     self.o = new_aubio_mfft(buf_size, channels)
     13    self.o = new_aubio_fft(buf_size, channels)
    1514
    1615  def tearDown(self):
    17     del_aubio_mfft(self.o)
     16    del_aubio_fft(self.o)
    1817
    1918  def test_create(self):
     
    2120    pass
    2221
    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 """
    2524    input    = new_fvec(buf_size, channels)
    2625    fftgrain = new_cvec(buf_size, channels)
    2726    for index in range(buf_size):
    2827      for channel in range(channels):
    29         self.assertEqual(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)
    3130    for index in range(buf_size/2+1):
    3231      for channel in range(channels):
    33         self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
     32        self.assertCloseEnough(0., cvec_read_norm(fftgrain, channel, index))
    3433    for index in range(buf_size/2+1):
    3534      for channel in range(channels):
    36         self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
     35        self.assertCloseEnough(0., cvec_read_phas(fftgrain, channel, index))
    3736    del fftgrain
    3837    del input
    3938
    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 """
    4241    fftgrain = new_cvec(buf_size, channels)
    4342    output    = new_fvec(buf_size, channels)
    44     aubio_mfft_rdo(self.o, fftgrain, output)
     43    aubio_fft_rdo(self.o, fftgrain, output)
    4544    # check output
    4645    for index in range(buf_size):
     
    5049    del output
    5150
    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 """
    5453    input    = new_fvec(buf_size, channels)
    5554    fftgrain = new_cvec(buf_size, channels)
     
    5756    some_constant = 0.3412432456
    5857    fvec_write_sample(input, some_constant, 0, 0)
    59     aubio_mfft_do(self.o, input, fftgrain)
     58    aubio_fft_do(self.o, input, fftgrain)
    6059    # check norm
    6160    for index in range(buf_size/2+1):
    62       self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)
     61      self.assertCloseEnough(some_constant, cvec_read_norm(fftgrain, 0, index))
    6362    for index in range(buf_size/2+1):
    6463      for channel in range(1, channels):
     
    7170    del input
    7271
    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 """
    7574    input    = new_fvec(buf_size, channels)
    7675    fftgrain = new_cvec(buf_size, channels)
     
    7978    for index in range(1,buf_size):
    8079      fvec_write_sample(input, some_constant, 0, index)
    81     aubio_mfft_do(self.o, input, fftgrain)
     80    aubio_fft_do(self.o, input, fftgrain)
    8281    # check norm and phase == 0 in all other channels
    8382    for index in range(buf_size/2+1):
     
    8584        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
    8685    # check norm and phase == 0 in first first and last bin of first channel
    87     self.assertAlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision)
    88     self.assertEqual(0., cvec_read_phas(fftgrain, 0, 0))
    89     self.assertEqual(0., cvec_read_norm(fftgrain, 0, buf_size/2+1))
    90     self.assertEqual(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))
    9190    # check unwrap2pi(phas) ~= pi everywhere but in first bin
    9291    for index in range(1,buf_size/2+1):
    93        self.assertAlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision)
    94        self.assertAlmostEqual(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))
    9594    del fftgrain
    9695    del input
    9796
    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 "
    10099    input    = new_fvec(buf_size, channels)
    101100    fftgrain = new_cvec(buf_size, channels)
     
    103102    fvec_write_sample(input, 1., 0, 0)
    104103    fvec_write_sample(input, 1., channels-1, 0)
    105     aubio_mfft_do(self.o, input, fftgrain)
     104    aubio_fft_do(self.o, input, fftgrain)
    106105    # check the norm
    107106    for index in range(buf_size/2+1):
     
    119118    del input
    120119
    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 """
    123122    fftgrain  = new_cvec(buf_size, channels)
    124123    for channel in range(channels):
    125124      cvec_write_norm(fftgrain, 1., channel, 0)
    126125    output    = new_fvec(buf_size, channels)
    127     aubio_mfft_rdo(self.o, fftgrain, output)
     126    aubio_fft_rdo(self.o, fftgrain, output)
    128127    for index in range(buf_size/2+1):
    129128      for channel in range(channels):
    130         self.assertAlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)
     129        self.assertCloseEnough(fvec_read_sample(output, channel, index), 1./buf_size)
    131130    del fftgrain
    132131    del output
    133132
    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 """
    136135    input    = new_fvec(buf_size, channels)
    137136    output   = new_fvec(buf_size, channels)
     
    140139      for channel in range(channels):
    141140        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)
    144143    for index in range(buf_size/2+1):
    145144      for channel in range(channels):
    146         self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision)
     145        self.assertCloseEnough(0.67, fvec_read_sample(output, channel, index))
    147146    del fftgrain
    148147    del output
Note: See TracChangeset for help on using the changeset viewer.