Ejemplo n.º 1
0
def blob(image, data: Tuple[List, List], opts: Opts):
    height, width, _ = image.shape

    cx = width // 2
    cy = height // 2

    d1, d2 = data

    f = fft(len(d1))
    s1 = f.rdo(f(fvec(d1)))
    s2 = f.rdo(f(fvec(d2)))

    level = level_lin(fvec(d1 + d2))

    for i, j, k, n, rk, rn in zip(d1, d2, s1, s2, reversed(s1), reversed(s2)):

        x = cx + int(j * width) - int(i * width)
        y = cy + int(height * k) - int(rk * height)

        radius = level * opts.radius
        r1 = int(k * radius)
        r2 = int(n * radius)

        blur_x = 5
        blur_y = 5

        if r1 > 0 and r2 > 0:
            cv2.ellipse(image, (x, y), (r1, r2), 0, 0, 360, (255, 255, 255))
            image = cv2.GaussianBlur(image, (blur_x, blur_y), 0)

    return image
def test_match(config):
    config = config(
        textwrap.dedent("""\
            [stream]
            url = foo
            threshold = 10.0
            """))
    matcher = _matchers.SoundPressureLevelRateOfChangeMatcher(
        config.stream_config("stream"))

    sample_count = 256
    samples = aubio.fvec(numpy.ones(sample_count))

    value, match = matcher.process_samples(samples, sample_count)
    assert math.isnan(value)
    assert not match

    assert matcher.process_samples(samples, sample_count) == (0.0, True)

    samples = aubio.fvec(2 * numpy.ones(sample_count))
    value, match = matcher.process_samples(samples, sample_count)
    assert 6 <= value <= 7
    assert match

    samples = aubio.fvec(10 * numpy.ones(sample_count))
    value, match = matcher.process_samples(samples, sample_count)
    assert 13 <= value <= 14
    assert not match
Ejemplo n.º 3
0
 def test_vector(self):
     a = fvec()
     len(a)
     _ = a[0]
     np.array(a)
     a = fvec(1)
     a = fvec(10)
     _ = a.T
Ejemplo n.º 4
0
 def test_vector(self):
     a = fvec()
     len(a)
     _ = a[0]
     np.array(a)
     a = fvec(1)
     a = fvec(10)
     _ = a.T
Ejemplo n.º 5
0
 def test_vector(self):
     a = fvec()
     a, len(a) #a.length
     a[0]
     array(a)
     a = fvec(10)
     a = fvec(1)
     a.T
     array(a).T
     a = range(len(a))
Ejemplo n.º 6
0
 def test_vector(self):
     a = fvec()
     a, len(a)  # a.length
     a[0]
     array(a)
     a = fvec(10)
     a = fvec(1)
     a.T
     array(a).T
     a = range(len(a))
Ejemplo n.º 7
0
 def test_pass_to_numpy(self):
     a = fvec(10)
     a[:] = 1.
     b = a
     del a
     assert_equal(b, 1.)
     c = fvec(10)
     c = b
     del b
     assert_equal(c, 1.)
     del c
Ejemplo n.º 8
0
 def test_pass_to_numpy(self):
     a = fvec(10)
     a[:] = 1.
     b = a
     del a
     assert_equal(b, 1.)
     c = fvec(10)
     c = b
     del b
     assert_equal(c, 1.)
     del c
Ejemplo n.º 9
0
 def test_steps_three_random_channels(self):
   from random import random
   f = pvoc(64, 16)
   t0 = fvec(16)
   t1 = fvec(16)
   for i in xrange(16):
       t1[i] = random() * 2. - 1.
   t2 = f.rdo(f(t1))
   t2 = f.rdo(f(t0))
   t2 = f.rdo(f(t0))
   t2 = f.rdo(f(t0))
   assert_almost_equal( t1, t2, decimal = 6 )
Ejemplo n.º 10
0
 def test_triangle_freqs_with_power(self):
     f = filterbank(9, 1024)
     freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000,
         24000])
     f.set_power(2)
     f.set_triangle_bands(freqs, 48000)
     spec = cvec(1024)
     spec.norm[:] = .1
     expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417,
         0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
     expected /= 100.
     assert_almost_equal(f(spec), expected)
Ejemplo n.º 11
0
 def test_triangle_freqs_without_norm(self):
     """make sure set_triangle_bands works without """
     samplerate = 22050
     freq_list = fvec([0, 100, 1000, 10000])
     f = filterbank(len(freq_list) - 2, 1024)
     f.set_norm(0)
     f.set_triangle_bands(freq_list, samplerate)
     expected = f.get_coeffs()
     f.set_norm(1)
     f.set_triangle_bands(fvec(freq_list), samplerate)
     assert_almost_equal(f.get_coeffs().T,
             expected.T * 2. / (freq_list[2:] - freq_list[:-2]))
Ejemplo n.º 12
0
 def test_steps_three_random_channels(self):
     from random import random
     f = pvoc(64, 16)
     t0 = fvec(16)
     t1 = fvec(16)
     for i in xrange(16):
         t1[i] = random() * 2. - 1.
     t2 = f.rdo(f(t1))
     t2 = f.rdo(f(t0))
     t2 = f.rdo(f(t0))
     t2 = f.rdo(f(t0))
     assert_almost_equal(t1, t2, decimal=6)
Ejemplo n.º 13
0
 def test_a_weighting_parted(self):
     expected = array_from_text_file('a_weighting_test_simple.expected')
     f = digital_filter(7)
     f.set_a_weighting(44100)
     v = fvec(16)
     v[12] = .5
     u = f(v)
     assert_almost_equal (expected[1][:16], u)
     # one more time
     v = fvec(16)
     u = f(v)
     assert_almost_equal (expected[1][16:], u)
Ejemplo n.º 14
0
 def test_a_weighting_parted(self):
   expected = array_from_text_file('a_weighting_test_simple.expected')
   f = digital_filter(7)
   f.set_a_weighting(44100)
   v = fvec(16)
   v[12] = .5
   u = f(v)
   assert_almost_equal (expected[1][:16], u)
   # one more time
   v = fvec(16)
   u = f(v)
   assert_almost_equal (expected[1][16:], u)
Ejemplo n.º 15
0
 def test_resynth_three_steps(self):
     """ check the resynthesis of steps is correct with 25% overlap """
     hop_s = 16
     buf_s = hop_s * 4
     sigin = fvec(hop_s)
     zeros = fvec(hop_s)
     f = pvoc(buf_s, hop_s)
     for i in range(hop_s):
         sigin[i] = random() * 2. - 1.
     t2 = f.rdo(f(sigin))
     t2 = f.rdo(f(zeros))
     t2 = f.rdo(f(zeros))
     t2 = f.rdo(f(zeros))
     assert_almost_equal(sigin, t2, decimal=precision)
 def test_resynth_three_steps(self):
     """ check the resynthesis of steps is correct with 25% overlap """
     hop_s = 16
     buf_s = hop_s * 4
     sigin = fvec(hop_s)
     zeros = fvec(hop_s)
     f = pvoc(buf_s, hop_s)
     for i in xrange(hop_s):
         sigin[i] = random() * 2. - 1.
     t2 = f.rdo( f(sigin) )
     t2 = f.rdo( f(zeros) )
     t2 = f.rdo( f(zeros) )
     t2 = f.rdo( f(zeros) )
     assert_almost_equal( sigin, t2, decimal = precision )
Ejemplo n.º 17
0
 def test_steps_two_channels(self):
     """ check the resynthesis of steps is correct """
     f = pvoc(1024, 512)
     t1 = fvec(512)
     t2 = fvec(512)
     # positive step in first channel
     t1[100:200] = .1
     # positive step in second channel
     t1[20:50] = -.1
     s1 = f(t1)
     r1 = f.rdo(s1)
     s2 = f(t2)
     r2 = f.rdo(s2)
     #self.plot_this ( s1.norm.T )
     assert_almost_equal(t1, r2, decimal=6)
Ejemplo n.º 18
0
 def test_steps_two_channels(self):
   """ check the resynthesis of steps is correct """
   f = pvoc(1024, 512)
   t1 = fvec(512)
   t2 = fvec(512)
   # positive step in first channel
   t1[100:200] = .1
   # positive step in second channel
   t1[20:50] = -.1
   s1 = f(t1)
   r1 = f.rdo(s1)
   s2 = f(t2)
   r2 = f.rdo(s2)
   #self.plot_this ( s1.norm.T )
   assert_almost_equal ( t1, r2, decimal = 6 )
Ejemplo n.º 19
0
 def test_triangle_freqs_with_not_enough_filters(self):
     """make sure set_triangle_bands warns when not enough filters"""
     samplerate = 22050
     freq_list = [0, 100, 1000, 4000, 8000, 10000]
     f = filterbank(len(freq_list)-3, 1024)
     with assert_warns(UserWarning):
         f.set_triangle_bands(fvec(freq_list), samplerate)
Ejemplo n.º 20
0
 def test_triangle_freqs_with_triple(self):
     """make sure set_triangle_bands works with 3 duplicate freqs"""
     samplerate = 22050
     freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
     f = filterbank(len(freq_list) - 2, 1024)
     # TODO add assert_warns
     f.set_triangle_bands(fvec(freq_list), samplerate)
Ejemplo n.º 21
0
 def test_triangle_freqs_with_large_freq(self):
     """make sure set_triangle_bands warns when freq > nyquist"""
     samplerate = 22050
     freq_list = [0, samplerate // 4, samplerate // 2 + 1]
     f = filterbank(len(freq_list) - 2, 1024)
     # TODO add assert_warns
     f.set_triangle_bands(fvec(freq_list), samplerate)
Ejemplo n.º 22
0
 def test_triangle_freqs_with_too_many_filters(self):
     """make sure set_triangle_bands warns when too many filters"""
     samplerate = 22050
     freq_list = [0, 100, 1000, 4000, 8000, 10000]
     f = filterbank(len(freq_list) - 1, 1024)
     # TODO add assert_warns
     f.set_triangle_bands(fvec(freq_list), samplerate)
Ejemplo n.º 23
0
 def test_vector_created_with_zeroes(self):
     a = fvec(10)
     a
     shape(a)
     a[0]
     #del a
     assert_equal(array(a), 0.)
Ejemplo n.º 24
0
def aubio_f0yin(y, sr, nwind=1024, hop=512,
                method='yin', tolerance=None):
    ''' Applies f0 detection to a numpy vector using aubio
    '''
    from aubio import pitch, fvec

    po = pitch(method, nwind, hop, sr)
    vs = fvec(nwind)

    if tolerance is not None:
        if tolerance > 0.0 and tolerance < 1.0:
            po.set_tolerance(tolerance)
        else:
            sys.stderr.write('Tolerance not set: Out of bounds\n')

    nsamples = y.shape[0]

    freq = []
    time = []
    conf = []

    for ii in xrange(0,nsamples-nwind, hop):
        thisy = y[ii:ii+nwind]
        vs[:] = thisy
        time.append(float(ii+nwind/2)/sr)
        freq.append(po(vs))
        conf.append(po.get_confidence())
    return np.array(freq).squeeze(), np.array(time), np.array(conf)
Ejemplo n.º 25
0
 def test_read_with(self):
     samplerate = 44100
     sink_path = get_tmp_sink_path()
     vec = fvec(128)
     with sink(sink_path, samplerate) as g:
         for _ in range(10):
             g(vec, 128)
Ejemplo n.º 26
0
 def test_triangle_freqs_with_double_value(self):
     """make sure set_triangle_bands works with 2 duplicate freqs"""
     samplerate = 22050
     freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
     f = filterbank(len(freq_list)-2, 1024)
     with assert_warns(UserWarning):
         f.set_triangle_bands(fvec(freq_list), samplerate)
Ejemplo n.º 27
0
 def test_impulse_negative(self):
   """ check the transform of one impulse at a random place """
   from random import random
   from math import floor
   win_s = 256
   i = 0 
   impulse = -10. 
   f = fft(win_s)
   timegrain = fvec(win_s)
   timegrain[i] = impulse 
   fftgrain = f ( timegrain )
   #self.plot_this ( fftgrain.phas )
   assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 )
   if impulse < 0:
     # phase can be pi or -pi, as it is not unwrapped
     assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
     assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)
     assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)
   else:
     assert_equal ( fftgrain.phas[1:-1] == 0, True)
     assert_equal ( fftgrain.phas[0] == 0, True)
     assert_equal ( fftgrain.phas[-1] == 0, True)
   # now check the resynthesis
   synthgrain = f.rdo ( fftgrain )
   #self.plot_this ( fftgrain.phas.T )
   assert_equal ( fftgrain.phas <= pi, True)
   assert_equal ( fftgrain.phas >= -pi, True)
   #self.plot_this ( synthgrain - timegrain )
   assert_almost_equal ( synthgrain, timegrain, decimal = 6 )
Ejemplo n.º 28
0
 def test_read_with(self):
     samplerate = 44100
     sink_path = get_tmp_sink_path()
     vec = fvec(128)
     with sink(sink_path, samplerate) as g:
         for _ in range(10):
             g(vec, 128)
Ejemplo n.º 29
0
 def compute_grain(impulse):
     win_s = 1024
     timegrain = fvec(win_s)
     timegrain[0] = impulse
     f = fft(win_s)
     fftgrain = f ( timegrain )
     return fftgrain
Ejemplo n.º 30
0
def aubio_f0yin(y, sr, nwind=1024, hop=512, method='yin', tolerance=None):
    ''' Applies f0 detection to a numpy vector using aubio
    '''
    from aubio import pitch, fvec

    po = pitch(method, nwind, hop, sr)
    vs = fvec(nwind)

    if tolerance is not None:
        if tolerance > 0.0 and tolerance < 1.0:
            po.set_tolerance(tolerance)
        else:
            sys.stderr.write('Tolerance not set: Out of bounds\n')

    nsamples = y.shape[0]

    freq = []
    time = []
    conf = []

    for ii in xrange(0, nsamples - nwind, hop):
        thisy = y[ii:ii + nwind]
        vs[:] = thisy
        time.append(float(ii + nwind / 2) / sr)
        freq.append(po(vs))
        conf.append(po.get_confidence())
    return np.array(freq).squeeze(), np.array(time), np.array(conf)
Ejemplo n.º 31
0
 def test_fvec_min_removal_of_fvec(self):
     a = fvec(3)
     a = array([20, 1, 19], dtype="float32")
     b = min_removal(a)
     assert_equal(array(b), [19, 0, 18])
     assert_equal(b, [19, 0, 18])
     assert_equal(a, b)
Ejemplo n.º 32
0
 def test_run_on_ones(self):
     " running on ones gives 0 "
     p = pitch('default', 2048, 512, 32000)
     f = fvec(512)
     f[:] = 1
     for _ in range(10):
         assert_equal(p(f), 0.)
Ejemplo n.º 33
0
 def compute_grain(impulse):
     win_s = 1024
     timegrain = fvec(win_s)
     timegrain[0] = impulse
     f = fft(win_s)
     fftgrain = f(timegrain)
     return fftgrain
Ejemplo n.º 34
0
 def test_impulse_negative(self):
     """ check the transform of a negative impulse at a random place """
     win_s = 256
     i = int(floor(random() * win_s))
     impulse = -.1
     f = fft(win_s)
     timegrain = fvec(win_s)
     timegrain[0] = 0
     timegrain[i] = impulse
     fftgrain = f(timegrain)
     #self.plot_this ( fftgrain.phas )
     assert_almost_equal(fftgrain.norm, abs(impulse), decimal=5)
     if impulse < 0:
         # phase can be pi or -pi, as it is not unwrapped
         #assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
         assert_almost_equal(fftgrain.phas[0], pi, decimal=6)
         assert_almost_equal(np.fmod(fftgrain.phas[-1], pi), 0, decimal=6)
     else:
         #assert_equal ( fftgrain.phas[1:-1] == 0, True)
         assert_equal(fftgrain.phas[0], 0)
         assert_almost_equal(np.fmod(fftgrain.phas[-1], pi), 0, decimal=6)
     # now check the resynthesis
     synthgrain = f.rdo(fftgrain)
     #self.plot_this ( fftgrain.phas.T )
     assert_equal(fftgrain.phas <= pi, True)
     assert_equal(fftgrain.phas >= -pi, True)
     #self.plot_this ( synthgrain - timegrain )
     assert_almost_equal(synthgrain, timegrain, decimal=6)
Ejemplo n.º 35
0
 def test_impulse_negative(self):
     """ check the transform of one impulse at a random place """
     from random import random
     from math import floor
     win_s = 256
     i = 0
     impulse = -10.
     f = fft(win_s)
     timegrain = fvec(win_s)
     timegrain[i] = impulse
     fftgrain = f(timegrain)
     #self.plot_this ( fftgrain.phas )
     assert_almost_equal(fftgrain.norm, abs(impulse), decimal=6)
     if impulse < 0:
         # phase can be pi or -pi, as it is not unwrapped
         assert_almost_equal(abs(fftgrain.phas[1:-1]), pi, decimal=6)
         assert_almost_equal(fftgrain.phas[0], pi, decimal=6)
         assert_almost_equal(fftgrain.phas[-1], pi, decimal=6)
     else:
         assert_equal(fftgrain.phas[1:-1] == 0, True)
         assert_equal(fftgrain.phas[0] == 0, True)
         assert_equal(fftgrain.phas[-1] == 0, True)
     # now check the resynthesis
     synthgrain = f.rdo(fftgrain)
     #self.plot_this ( fftgrain.phas.T )
     assert_equal(fftgrain.phas <= pi, True)
     assert_equal(fftgrain.phas >= -pi, True)
     #self.plot_this ( synthgrain - timegrain )
     assert_almost_equal(synthgrain, timegrain, decimal=6)
Ejemplo n.º 36
0
 def test_impulse_negative(self):
     """ check the transform of a negative impulse at a random place """
     win_s = 256
     i = int(floor(random()*win_s))
     impulse = -.1
     f = fft(win_s)
     timegrain = fvec(win_s)
     timegrain[0] = 0
     timegrain[i] = impulse
     fftgrain = f ( timegrain )
     #self.plot_this ( fftgrain.phas )
     assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 5 )
     if impulse < 0:
         # phase can be pi or -pi, as it is not unwrapped
         #assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
         assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)
         assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6)
     else:
         #assert_equal ( fftgrain.phas[1:-1] == 0, True)
         assert_equal ( fftgrain.phas[0], 0)
         assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6)
     # now check the resynthesis
     synthgrain = f.rdo ( fftgrain )
     #self.plot_this ( fftgrain.phas.T )
     assert_equal ( fftgrain.phas <= pi, True)
     assert_equal ( fftgrain.phas >= -pi, True)
     #self.plot_this ( synthgrain - timegrain )
     assert_almost_equal ( synthgrain, timegrain, decimal = 6 )
Ejemplo n.º 37
0
 def test_vector_created_with_zeroes(self):
     a = fvec(10)
     a
     shape(a)
     a[0]
     #del a
     assert_equal(array(a), 0.)
Ejemplo n.º 38
0
 def test_fvec_min_removal_of_fvec(self):
     a = fvec(3)
     a = array([20, 1, 19], dtype = 'float32')
     b = min_removal(a)
     assert_equal (array(b), [19, 0, 18])
     assert_equal (b, [19, 0, 18])
     assert_equal (a, b)
Ejemplo n.º 39
0
 def test_all_methods(self):
     for method in [
             'default', 'energy', 'hfc', 'complexdomain', 'complex',
             'phase', 'wphase', 'mkl', 'kl', 'specflux', 'specdiff',
             'old_default'
     ]:
         o = onset(method=method, buf_size=512, hop_size=256)
         o(fvec(256))
Ejemplo n.º 40
0
 def test_zeros(self):
     """ check the transform of zeros """
     win_s = 512
     timegrain = fvec(win_s)
     f = fft(win_s)
     fftgrain = f(timegrain)
     assert_equal(fftgrain.norm == 0, True)
     assert_equal(fftgrain.phas == 0, True)
Ejemplo n.º 41
0
 def test_many_sinks(self):
     for i in range(100):
         g = sink('/tmp/f.wav', 0)
         write = 256
         for n in range(200):
             vec = fvec(write)
             g(vec, write)
         del g
Ejemplo n.º 42
0
 def test_some_ones(self):
     """ test that dct(somevector) is computed correctly """
     a_dct = aubio.dct(16)
     a_in = np.ones(16).astype(aubio.float_type)
     a_in[1] = 0
     a_in[3] = np.pi
     a_expected = aubio.fvec(precomputed_some_ones)
     assert_almost_equal(a_dct(a_in), a_expected, decimal=6)
Ejemplo n.º 43
0
 def test_output_dimensions(self):
     """ check the dimensions of output """
     win_s = 1024
     timegrain = fvec(win_s)
     f = fft (win_s)
     fftgrain = f (timegrain)
     assert_equal (shape(fftgrain.norm), (win_s/2+1,))
     assert_equal (shape(fftgrain.phas), (win_s/2+1,))
Ejemplo n.º 44
0
 def test_resynth_two_steps(self):
     """ check the resynthesis of steps is correct with 50% overlap """
     hop_s = 512
     buf_s = hop_s * 2
     f = pvoc(buf_s, hop_s)
     sigin = fvec(hop_s)
     zeros = fvec(hop_s)
     # negative step
     sigin[20:50] = -.1
     # positive step
     sigin[100:200] = .1
     s1 = f(sigin)
     r1 = f.rdo(s1)
     s2 = f(zeros)
     r2 = f.rdo(s2)
     #self.plot_this ( s2.norm.T )
     assert_almost_equal(r2, sigin, decimal=precision)
Ejemplo n.º 45
0
 def test_output_dimensions(self):
     """ check the dimensions of output """
     win_s = 1024
     timegrain = fvec(win_s)
     f = fft(win_s)
     fftgrain = f(timegrain)
     assert_equal(shape(fftgrain.norm), (win_s / 2 + 1, ))
     assert_equal(shape(fftgrain.phas), (win_s / 2 + 1, ))
def run_pitch(p, input_vec):
  f = fvec (p.hop_size)
  cands = []
  count = 0
  for vec_slice in input_vec.reshape((-1, p.hop_size)):
    f[:] = vec_slice
    cands.append(p(f))
  return cands
Ejemplo n.º 47
0
 def test_no_overlap(self):
     win_s, hop_s = 1024, 1024
     f = pvoc (win_s, hop_s)
     t = fvec (hop_s)
     for _ in range(4):
         s = f(t)
         r = f.rdo(s)
         assert_equal ( t, 0.)
 def test_resynth_two_steps(self):
     """ check the resynthesis of steps is correct with 50% overlap """
     hop_s = 512
     buf_s = hop_s * 2
     f = pvoc(buf_s, hop_s)
     sigin = fvec(hop_s)
     zeros = fvec(hop_s)
     # negative step
     sigin[20:50] = -.1
     # positive step
     sigin[100:200] = .1
     s1 = f(sigin)
     r1 = f.rdo(s1)
     s2 = f(zeros)
     r2 = f.rdo(s2)
     #self.plot_this ( s2.norm.T )
     assert_almost_equal ( r2, sigin, decimal = precision )
Ejemplo n.º 49
0
 def test_zeros(self):
   """ check the transform of zeros """
   win_s = 512
   timegrain = fvec(win_s)
   f = fft(win_s)
   fftgrain = f(timegrain)
   assert_equal ( fftgrain.norm == 0, True )
   assert_equal ( fftgrain.phas == 0, True )
Ejemplo n.º 50
0
 def test_a_weighting(self):
   expected = array_from_text_file('a_weighting_test_simple.expected')
   f = digital_filter(7)
   f.set_a_weighting(44100)
   v = fvec(32)
   v[12] = .5
   u = f(v)
   assert_almost_equal (expected[1], u)
Ejemplo n.º 51
0
 def test_a_weighting(self):
     expected = array_from_text_file('a_weighting_test_simple.expected')
     f = digital_filter(7)
     f.set_a_weighting(44100)
     v = fvec(32)
     v[12] = .5
     u = f(v)
     assert_almost_equal (expected[1], u)
Ejemplo n.º 52
0
 def test_c_weighting_8000(self):
     expected = array_from_text_file('c_weighting_test_simple_8000.expected')
     f = digital_filter(5)
     f.set_c_weighting(8000)
     v = fvec(32)
     v[12] = .5
     u = f(v)
     assert_almost_equal (expected[1], u)
Ejemplo n.º 53
0
 def test_alpha_norm_of_fvec(self):
     a = fvec(2)
     self.assertEquals (alpha_norm(a, 1), 0)
     a[0] = 1
     self.assertEquals (alpha_norm(a, 1), 0.5)
     a[1] = 1
     self.assertEquals (alpha_norm(a, 1), 1)
     a = array([0, 1], dtype='float32')
     from math import sqrt
     assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
Ejemplo n.º 54
0
 def recontruct(self, win_s, skipMessage):
     try:
         f = fft(win_s)
     except RuntimeError:
         self.skipTest(skipMessage)
     input_signal = fvec(win_s)
     input_signal[win_s//2] = 1
     c = f(input_signal)
     output_signal = f.rdo(c)
     assert_almost_equal(input_signal, output_signal)
Ejemplo n.º 55
0
 def test_zeros(self):
   win_s, hop_s = 1024, 256
   f = pvoc (win_s, hop_s)
   t = fvec (hop_s)
   for time in range( 4 * win_s / hop_s ):
     s = f(t)
     r = f.rdo(s)
     assert_equal ( array(t), 0)
     assert_equal ( s.norm, 0)
     assert_equal ( s.phas, 0)
     assert_equal ( r, 0)
Ejemplo n.º 56
0
 def reconstruction(self, sigin, hop_s, ratio):
     buf_s = hop_s * ratio
     f = pvoc(buf_s, hop_s)
     zeros = fvec(hop_s)
     r2 = f.rdo( f(sigin) )
     for _ in range(1, ratio):
         r2 = f.rdo( f(zeros) )
     # compute square errors
     sq_error = (r2 - sigin)**2
     # make sure all square errors are less than desired precision
     assert_array_less(sq_error, max_sq_error)
Ejemplo n.º 57
0
 def test_impulse_at_zero(self):
   """ check the transform of one impulse at a index 0 """
   win_s = 1024
   impulse = pi
   f = fft(win_s)
   timegrain = fvec(win_s)
   timegrain[0] = impulse 
   fftgrain = f ( timegrain )
   #self.plot_this ( fftgrain.phas )
   assert_equal ( fftgrain.phas[0], 0)
   assert_equal ( fftgrain.phas[1], 0)
   assert_almost_equal (fftgrain.norm[0], impulse, decimal = 6 )
 def test_zeros(self):
     """ check the resynthesis of zeros gives zeros """
     win_s, hop_s = 1024, 256
     f = pvoc (win_s, hop_s)
     t = fvec (hop_s)
     for time in range( 4 * win_s / hop_s ):
         s = f(t)
         r = f.rdo(s)
         assert_equal ( array(t), 0)
         assert_equal ( s.norm, 0)
         assert_equal ( s.phas, 0)
         assert_equal ( r, 0)
Ejemplo n.º 59
0
    def test_arange(self):
        """ test that dct(arange(8)) is computed correctly

        >>> from scipy.fftpack import dct
        >>> a_in = np.arange(8).astype(aubio.float_type)
        >>> precomputed = dct(a_in, norm='ortho')
        """
        N = len(precomputed_arange)
        a_dct = aubio.dct(8)
        a_in = np.arange(8).astype(aubio.float_type)
        a_expected = aubio.fvec(precomputed_arange)
        assert_almost_equal(a_dct(a_in), a_expected, decimal=5)