Changeset d57d1de for tests


Ignore:
Timestamp:
Nov 7, 2007, 4:51:42 PM (17 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:
4368223
Parents:
e00f769 (diff), 038852a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

update fft.py tests, merge from banane

Location:
tests/python
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • tests/python/fft.py

    re00f769 rd57d1de  
    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):
    8483      for channel in range(1, channels):
    8584        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
     85        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
     86
    8687    # 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))
    91     # check unwrap2pi(phas) ~= pi everywhere but in first bin
     88    # check unwrap2pi(phas) ~= pi everywhere but in first and last bin
     89    self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, 0))
     90    for index in range(1,buf_size/2):
     91       self.assertCloseEnough(math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)))
     92    self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2))
     93    self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2+1))
     94
     95    self.assertCloseEnough((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0))
    9296    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)
     97       self.assertCloseEnough(some_constant, abs(cvec_read_norm(fftgrain, 0, index)))
     98    self.assertCloseEnough(0., cvec_read_norm(fftgrain, 0, buf_size/2+1))
     99
    95100    del fftgrain
    96101    del input
    97102
    98   def test_aubio_mfft_do_impulse_multichannel(self):
    99     " test aubio_mfft_do on impulse two channels "
     103  def test_do_impulse_multichannel(self):
     104    " test aubio_fft_do on impulse two channels "
    100105    input    = new_fvec(buf_size, channels)
    101106    fftgrain = new_cvec(buf_size, channels)
     
    103108    fvec_write_sample(input, 1., 0, 0)
    104109    fvec_write_sample(input, 1., channels-1, 0)
    105     aubio_mfft_do(self.o, input, fftgrain)
     110    aubio_fft_do(self.o, input, fftgrain)
    106111    # check the norm
    107112    for index in range(buf_size/2+1):
     
    119124    del input
    120125
    121   def test_aubio_mfft_rdo_impulse(self):
    122     """ test aubio_mfft_rdo on impulse """
     126  def test_rdo_impulse(self):
     127    """ test aubio_fft_rdo on impulse """
    123128    fftgrain  = new_cvec(buf_size, channels)
    124129    for channel in range(channels):
    125130      cvec_write_norm(fftgrain, 1., channel, 0)
    126131    output    = new_fvec(buf_size, channels)
    127     aubio_mfft_rdo(self.o, fftgrain, output)
     132    aubio_fft_rdo(self.o, fftgrain, output)
    128133    for index in range(buf_size/2+1):
    129134      for channel in range(channels):
    130         self.assertAlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)
     135        self.assertCloseEnough(fvec_read_sample(output, channel, index), 1./buf_size)
    131136    del fftgrain
    132137    del output
    133138
    134   def test_aubio_mfft_do_back_and_forth(self):
    135     """ test aubio_mfft_rdo on a constant """
     139  def test_do_back_and_forth(self):
     140    """ test aubio_fft_rdo on a constant """
    136141    input    = new_fvec(buf_size, channels)
    137142    output   = new_fvec(buf_size, channels)
     
    140145      for channel in range(channels):
    141146        fvec_write_sample(input, 0.67, channel, index)
    142     aubio_mfft_do(self.o, input, fftgrain)
    143     aubio_mfft_rdo(self.o, fftgrain, output)
     147    aubio_fft_do(self.o, input, fftgrain)
     148    aubio_fft_rdo(self.o, fftgrain, output)
    144149    for index in range(buf_size/2+1):
    145150      for channel in range(channels):
    146         self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision)
     151        self.assertCloseEnough(0.67, fvec_read_sample(output, channel, index))
    147152    del fftgrain
    148153    del output
Note: See TracChangeset for help on using the changeset viewer.