Changeset 1a6ef2c


Ignore:
Timestamp:
Dec 25, 2009, 4:57:49 AM (14 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:
9c9cd54
Parents:
84e0606
Message:

test_*.py: switch to mono, add tests for cvec

Location:
interfaces/python
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • interfaces/python/test_fft.py

    r84e0606 r1a6ef2c  
    22from numpy.testing import assert_equal, assert_almost_equal
    33# WARNING: numpy also has an fft object
    4 from _aubio import fft, fvec, cvec
     4from _aubio import fft, cvec
     5from aubio import fvec
    56from numpy import array, shape
    67from math import pi
     
    1011  def test_members(self):
    1112    f = fft()
    12     assert_equal ([f.win_s, f.channels], [1024, 1])
    13     f = fft(2048, 4)
    14     assert_equal ([f.win_s, f.channels], [2048, 4])
     13    assert_equal (f.win_s, 1024)
    1514
    1615  def test_output_dimensions(self):
    1716    """ check the dimensions of output """
    18     win_s, chan = 1024, 3
    19     timegrain = fvec(win_s, chan)
    20     f = fft(win_s, chan)
     17    win_s = 1024
     18    timegrain = fvec(win_s)
     19    f = fft(win_s)
    2120    fftgrain = f (timegrain)
    22     assert_equal (array(fftgrain), 0)
    23     assert_equal (shape(fftgrain), (chan * 2, win_s/2+1))
    2421    assert_equal (fftgrain.norm, 0)
    25     assert_equal (shape(fftgrain.norm), (chan, win_s/2+1))
     22    assert_equal (shape(fftgrain.norm), (win_s/2+1,))
    2623    assert_equal (fftgrain.phas, 0)
    27     assert_equal (shape(fftgrain.phas), (chan, win_s/2+1))
     24    assert_equal (shape(fftgrain.phas), (win_s/2+1,))
    2825
    2926  def test_zeros(self):
    3027    """ check the transform of zeros """
    31     win_s, chan = 512, 3
    32     timegrain = fvec(win_s, chan)
    33     f = fft(win_s, chan)
     28    win_s = 512
     29    timegrain = fvec(win_s)
     30    f = fft(win_s)
    3431    fftgrain = f(timegrain)
    3532    assert_equal ( fftgrain.norm == 0, True )
     
    4037    from random import random
    4138    from math import floor
    42     win_s, chan = 256, 1
     39    win_s = 256
    4340    i = floor(random()*win_s)
    4441    impulse = pi * random()
    45     f = fft(win_s, chan)
    46     timegrain = fvec(win_s, chan)
    47     timegrain[0][i] = impulse
     42    f = fft(win_s)
     43    timegrain = fvec(win_s)
     44    timegrain[i] = impulse
    4845    fftgrain = f ( timegrain )
    49     #self.plot_this ( fftgrain.phas[0] )
     46    #self.plot_this ( fftgrain.phas )
    5047    assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 )
    5148    assert_equal ( fftgrain.phas <= pi, True)
     
    5653    from random import random
    5754    from math import floor
    58     win_s, chan = 256, 1
     55    win_s = 256
    5956    i = 0
    6057    impulse = -10.
    61     f = fft(win_s, chan)
    62     timegrain = fvec(win_s, chan)
    63     timegrain[0][i] = impulse
     58    f = fft(win_s)
     59    timegrain = fvec(win_s)
     60    timegrain[i] = impulse
    6461    fftgrain = f ( timegrain )
    65     #self.plot_this ( fftgrain.phas[0] )
     62    #self.plot_this ( fftgrain.phas )
    6663    assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 )
    6764    if impulse < 0:
    6865      # phase can be pi or -pi, as it is not unwrapped
    69       assert_almost_equal ( abs(fftgrain.phas[0][1:-1]) , pi, decimal = 6 )
    70       assert_almost_equal ( fftgrain.phas[0][0], pi, decimal = 6)
    71       assert_almost_equal ( fftgrain.phas[0][-1], pi, decimal = 6)
     66      assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
     67      assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)
     68      assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)
    7269    else:
    73       assert_equal ( fftgrain.phas[0][1:-1] == 0, True)
    74       assert_equal ( fftgrain.phas[0][0] == 0, True)
    75       assert_equal ( fftgrain.phas[0][-1] == 0, True)
     70      assert_equal ( fftgrain.phas[1:-1] == 0, True)
     71      assert_equal ( fftgrain.phas[0] == 0, True)
     72      assert_equal ( fftgrain.phas[-1] == 0, True)
    7673    # now check the resynthesis
    7774    synthgrain = f.rdo ( fftgrain )
     
    8380
    8481  def test_impulse_at_zero(self):
    85     """ check the transform of one impulse at a index 0 in one channel """
    86     win_s, chan = 1024, 2
     82    """ check the transform of one impulse at a index 0 """
     83    win_s = 1024
    8784    impulse = pi
    88     f = fft(win_s, chan)
    89     timegrain = fvec(win_s, chan)
    90     timegrain[0][0] = impulse
     85    f = fft(win_s)
     86    timegrain = fvec(win_s)
     87    timegrain[0] = impulse
    9188    fftgrain = f ( timegrain )
    9289    #self.plot_this ( fftgrain.phas )
    9390    assert_equal ( fftgrain.phas[0], 0)
    9491    assert_equal ( fftgrain.phas[1], 0)
    95     assert_almost_equal ( fftgrain.norm[0], impulse, decimal = 6 )
    96     assert_equal ( fftgrain.norm[0], impulse)
     92    assert_almost_equal (fftgrain.norm[0], impulse, decimal = 6 )
    9793
    9894  def test_rdo_before_do(self):
    9995    """ check running fft.rdo before fft.do works """
    100     win_s, chan = 1024, 2
     96    win_s = 1024
    10197    impulse = pi
    102     f = fft(win_s, chan)
    103     fftgrain = cvec(win_s, chan)
     98    f = fft(win_s)
     99    fftgrain = cvec(win_s)
    104100    t = f.rdo( fftgrain )
    105101    assert_equal ( t, 0 )
  • interfaces/python/test_filter.py

    r84e0606 r1a6ef2c  
    22from numpy.testing import assert_equal, assert_almost_equal
    33from _aubio import *
     4from aubio import fvec
    45from numpy import array
    56
     
    1213  def test_members(self):
    1314    f = digital_filter()
    14     assert_equal ([f.channels, f.order], [1, 7])
    15     f = digital_filter(5, 2)
    16     assert_equal ([f.channels, f.order], [2, 5])
     15    assert_equal (f.order, 7)
     16    f = digital_filter(5)
     17    assert_equal (f.order, 5)
    1718    f(fvec())
    1819 
    1920  def test_cweighting_error(self):
    20     f = digital_filter (2, 1)
     21    f = digital_filter (2)
    2122    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
    22     f = digital_filter (8, 1)
     23    f = digital_filter (8)
    2324    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
    24     f = digital_filter (5, 1)
     25    f = digital_filter (5)
    2526    self.assertRaises ( ValueError, f.set_c_weighting, 4000 )
    26     f = digital_filter (5, 1)
     27    f = digital_filter (5)
    2728    self.assertRaises ( ValueError, f.set_c_weighting, 193000 )
    28     f = digital_filter (7, 1)
     29    f = digital_filter (7)
    2930    self.assertRaises ( ValueError, f.set_a_weighting, 193000 )
    30     f = digital_filter (5, 1)
     31    f = digital_filter (5)
    3132    self.assertRaises ( ValueError, f.set_a_weighting, 192000 )
    3233
    3334  def test_c_weighting(self):
    3435    expected = array_from_text_file('c_weighting_test_simple.expected')
    35     f = digital_filter(5, 1)
     36    f = digital_filter(5)
    3637    f.set_c_weighting(44100)
    3738    v = fvec(32)
    38     v[0][12] = .5
     39    v[12] = .5
    3940    u = f(v)
    4041    assert_almost_equal (expected[1], u)
     
    4243  def test_a_weighting(self):
    4344    expected = array_from_text_file('a_weighting_test_simple.expected')
    44     f = digital_filter(7, 1)
     45    f = digital_filter(7)
    4546    f.set_a_weighting(44100)
    4647    v = fvec(32)
    47     v[0][12] = .5
     48    v[12] = .5
    4849    u = f(v)
    4950    assert_almost_equal (expected[1], u)
     
    5152  def test_a_weighting_parted(self):
    5253    expected = array_from_text_file('a_weighting_test_simple.expected')
    53     f = digital_filter(7, 1)
     54    f = digital_filter(7)
    5455    f.set_a_weighting(44100)
    5556    v = fvec(16)
    56     v[0][12] = .5
     57    v[12] = .5
    5758    u = f(v)
    5859    assert_almost_equal (expected[1][:16], u)
  • interfaces/python/test_filterbank.py

    r84e0606 r1a6ef2c  
    33from numpy import array, shape
    44from _aubio import *
     5#from aubio import cvec
    56
    67class aubio_filter_test_case(TestCase):
     
    1112    a = f.get_coeffs()
    1213    a.T
     14    assert_equal(shape (a), (40, 512/2 + 1) )
    1315
    1416  def test_other_slaney(self):
     
    2325      #print "sum is", sum(sum(a))
    2426
    25   def test_triangle_freqs(self):
     27  def test_triangle_freqs_zeros(self):
    2628    f = filterbank(9, 1024)
    2729    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
     
    2931    f.set_triangle_bands(freqs, 48000)
    3032    f.get_coeffs().T
    31     assert_equal ( f(cvec(1024)), [0] * 9)
     33    assert_equal ( f(cvec(1024)), 0)
     34
     35  def test_triangle_freqs_ones(self):
     36    f = filterbank(9, 1024)
     37    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
     38    freqs = array(freq_list, dtype = 'float32')
     39    f.set_triangle_bands(freqs, 48000)
     40    f.get_coeffs().T
    3241    spec = cvec(1024)
    33     spec[0][40:100] = 100
    34     #print f(spec)
     42    spec.norm[:] = 1
     43    assert_almost_equal ( f(spec),
     44            [ 0.02070313,  0.02138672,  0.02127604,  0.02135417,
     45        0.02133301, 0.02133301,  0.02133311,  0.02133334,  0.02133345])
    3546
    3647if __name__ == '__main__':
  • interfaces/python/test_fvec.py

    r84e0606 r1a6ef2c  
    22from numpy.testing import assert_equal, assert_almost_equal
    33from _aubio import *
    4 from numpy import array
     4from aubio import fvec
     5from numpy import array, shape
    56
    67class aubio_fvec_test_case(TestCase):
    78
    8 
    99    def test_vector_created_with_zeroes(self):
    10         a = fvec()
     10        a = fvec(10)
     11        a
     12        shape(a)
     13        a[0]
     14        #del a
    1115        assert_equal(array(a), 0.)
    1216
     
    2024        a[-1] = 1
    2125        assert_equal(a[-1], 1)
    22         assert_equal(a[a.length-1], 1)
     26        assert_equal(a[len(a)-1], 1)
    2327
    2428    def test_vector(self):
    2529        a = fvec()
    26         a, a.length
     30        a, len(a) #a.length
    2731        a[0]
    2832        array(a)
    2933        a = fvec(10)
    3034        a = fvec(1)
     35        a.T
    3136        array(a).T
    32         a[0] = range(a.length)
     37        a = range(len(a))
    3338
    3439    def test_wrong_values(self):
  • interfaces/python/test_onsetdetection.py

    r84e0606 r1a6ef2c  
    22from numpy.testing import assert_equal, assert_almost_equal
    33# WARNING: numpy also has an fft object
    4 from _aubio import cvec, specdesc
     4from _aubio import specdesc, cvec
    55from numpy import array, shape, arange, zeros, log
    66from math import pi
     
    1010    def test_members(self):
    1111        o = specdesc()
    12         assert_equal ([o.buf_size, o.channels, o.method],
    13             [1024, 1, "default"])
    14         o = specdesc("complex", 512, 2)
    15         assert_equal ([o.buf_size, o.channels, o.method],
    16             [512, 2, "complex"])
     12        assert_equal ([o.buf_size, o.method],
     13            [1024, "default"])
    1714
    1815    def test_hfc(self):
     
    2219        a = arange(c.length, dtype='float32')
    2320        c.norm = a
    24         assert_equal (a, c.norm[0])
     21        assert_equal (a, c.norm)
    2522        assert_equal ( sum(a*(a+1)), o(c))
    2623
     
    3128        a = arange(c.length, dtype='float32')
    3229        c.norm = a
    33         assert_equal (a, c.norm[0])
     30        assert_equal (a, c.norm)
    3431        # the previous run was on zeros, so previous frames are still 0
    3532        # so we have sqrt ( abs ( r2 ^ 2) ) == r2
  • interfaces/python/test_phasevoc.py

    r84e0606 r1a6ef2c  
    11from numpy.testing import TestCase, run_module_suite
    22from numpy.testing import assert_equal, assert_almost_equal
     3from aubio import fvec
    34from _aubio import *
    45from numpy import array, shape
     
    2627  def test_steps_two_channels(self):
    2728    """ check the resynthesis of steps is correct """
    28     f = pvoc(1024, 512, 2)
    29     t1 = fvec(512, 2)
    30     t2 = fvec(512, 2)
     29    f = pvoc(1024, 512)
     30    t1 = fvec(512)
     31    t2 = fvec(512)
    3132    # positive step in first channel
    32     t1[0][100:200] = .1
     33    t1[100:200] = .1
    3334    # positive step in second channel
    34     t1[1][20:50] = -.1
     35    t1[20:50] = -.1
    3536    s1 = f(t1)
    3637    r1 = f.rdo(s1)
     
    4243  def test_steps_three_random_channels(self):
    4344    from random import random
    44     f = pvoc(64, 16, 3)
    45     t0 = fvec(16, 3)
    46     t1 = fvec(16, 3)
    47     for i in xrange(3):
    48       for j in xrange(16):
    49         t1[i][j] = random() * 2. - 1.
     45    f = pvoc(64, 16)
     46    t0 = fvec(16)
     47    t1 = fvec(16)
     48    for i in xrange(16):
     49        t1[i] = random() * 2. - 1.
    5050    t2 = f.rdo(f(t1))
    5151    t2 = f.rdo(f(t0))
Note: See TracChangeset for help on using the changeset viewer.