Example #1
0
 def test_buf_size_not_power_of_two(self):
     # when compiled with fftw3, aubio supports non power of two fft sizes
     win_s = 320
     try:
         with self.assertRaises(RuntimeError):
             fft(win_s)
     except AssertionError:
         self.skipTest('creating aubio.fft with size %d did not fail' % win_s)
Example #2
0
 def test_buf_size_not_power_of_two(self):
     # when compiled with fftw3, aubio supports non power of two fft sizes
     win_s = 320
     try:
         with self.assertRaises(RuntimeError):
             fft(win_s)
     except AssertionError:
         self.skipTest('creating aubio.fft with size %d did not fail' %
                       win_s)
Example #3
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)
Example #4
0
 def compute_grain(impulse):
     win_s = 1024
     timegrain = fvec(win_s)
     timegrain[0] = impulse
     f = fft(win_s)
     fftgrain = f ( timegrain )
     return fftgrain
Example #5
0
 def test_rdo_before_do(self):
     """ check running fft.rdo before fft.do works """
     win_s = 1024
     f = fft(win_s)
     fftgrain = cvec(win_s)
     t = f.rdo( fftgrain )
     assert_equal ( t, 0 )
Example #6
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 )
Example #7
0
 def compute_grain(impulse):
     win_s = 1024
     timegrain = fvec(win_s)
     timegrain[0] = impulse
     f = fft(win_s)
     fftgrain = f(timegrain)
     return fftgrain
Example #8
0
 def test_rdo_before_do(self):
     """ check running fft.rdo before fft.do works """
     win_s = 1024
     f = fft(win_s)
     fftgrain = cvec(win_s)
     t = f.rdo(fftgrain)
     assert_equal(t, 0)
Example #9
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)
Example #10
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 )
Example #11
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
Example #12
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 )
Example #13
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)
Example #14
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 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,))
Example #16
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)
Example #17
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)
Example #18
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(abs(fftgrain.phas[1]), 0)
     assert_almost_equal(fftgrain.norm[0], impulse, decimal=6)
Example #19
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 )
Example #20
0
 def test_impulse(self):
     """ check the transform of one impulse at a random place """
     win_s = 256
     i = int(floor(random() * win_s))
     impulse = pi * random()
     f = fft(win_s)
     timegrain = fvec(win_s)
     timegrain[i] = impulse
     fftgrain = f(timegrain)
     #self.plot_this ( fftgrain.phas )
     assert_almost_equal(fftgrain.norm, impulse, decimal=6)
     assert_equal(fftgrain.phas <= pi, True)
     assert_equal(fftgrain.phas >= -pi, True)
Example #21
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)
     # could be 0 or -0 depending on fft implementation (0 for fftw3, -0 for ooura)
     assert_almost_equal ( fftgrain.phas[1], 0)
     assert_almost_equal ( fftgrain.norm[0], impulse, decimal = 6 )
Example #22
0
 def test_impulse(self):
     """ check the transform of one impulse at a random place """
     win_s = 256
     i = int(floor(random()*win_s))
     impulse = pi * random()
     f = fft(win_s)
     timegrain = fvec(win_s)
     timegrain[i] = impulse
     fftgrain = f ( timegrain )
     #self.plot_this ( fftgrain.phas )
     assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 )
     assert_equal ( fftgrain.phas <= pi, True)
     assert_equal ( fftgrain.phas >= -pi, True)
Example #23
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)
     # could be 0 or -0 depending on fft implementation (0 for fftw3, -0 for ooura)
     assert_almost_equal(fftgrain.phas[1], 0)
     assert_almost_equal(fftgrain.norm[0], impulse, decimal=6)
Example #24
0
 def test_zeros(self):
     """ check the transform of zeros is all zeros """
     win_s = 512
     timegrain = fvec(win_s)
     f = fft (win_s)
     fftgrain = f (timegrain)
     assert_equal ( fftgrain.norm, 0 )
     try:
         assert_equal ( fftgrain.phas, 0 )
     except AssertionError:
         assert_equal (fftgrain.phas[fftgrain.phas > 0], +pi)
         assert_equal (fftgrain.phas[fftgrain.phas < 0], -pi)
         assert_equal (np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0)
         self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \
                 + 'This is expected when using fftw3 on powerpc.')
Example #25
0
 def test_zeros(self):
     """ check the transform of zeros is all zeros """
     win_s = 512
     timegrain = fvec(win_s)
     f = fft(win_s)
     fftgrain = f(timegrain)
     assert_equal(fftgrain.norm, 0)
     try:
         assert_equal(fftgrain.phas, 0)
     except AssertionError:
         assert_equal(fftgrain.phas[fftgrain.phas > 0], +pi)
         assert_equal(fftgrain.phas[fftgrain.phas < 0], -pi)
         assert_equal(np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0)
         self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \
                 + 'This is expected when using fftw3 on powerpc.')
Example #26
0
def _callback(in_data, frame_count, time_info, status):
    global NEXT_FFT_TIME
    if NEXT_FFT_TIME < time.monotonic():
        NEXT_FFT_TIME = NEXT_FFT_TIME + (1 / 20)

        audio_buffer = np.frombuffer(in_data, dtype=np.float32)

        print(chr(27) + "[2J")
        print("\033[H")
        fft = aubio.fft(BUFFER_SIZE)(audio_buffer)
        fb = aubio.filterbank(400, BUFFER_SIZE)
        fb.set_power(2)
        freqs = np.linspace(0, 20_000, 402)
        fb.set_triangle_bands(aubio.fvec(freqs), SAMPLE_RATE)

        output = np.around(fb(fft), 2)
        freqs = np.around(freqs[1:-1], 2)
        # print(np.column_stack((np.around(freqs[1:-1], 2), output)))

        for bin, amplitude in np.column_stack((freqs, output)):
            if amplitude > 1:
                print(f"{bin}: {amplitude}")

    return None, pyaudio.paContinue
Example #27
0
 def test_small_input_timegrain(self):
     win_s = 1024
     f = fft(win_s)
     t = fvec(1)
     with self.assertRaises(ValueError):
         f(t)
Example #28
0
 def test_buf_size_too_small(self):
     win_s = 1
     with self.assertRaises(RuntimeError):
         fft(win_s)
Example #29
0
 def test_buf_size_too_small(self):
     win_s = 1
     with self.assertRaises(RuntimeError):
         fft(win_s)
Example #30
0
 def test_large_input_fftgrain(self):
     win_s = 1024
     f = fft(win_s)
     s = cvec(win_s + 5)
     with self.assertRaises(ValueError):
         f.rdo(s)
Example #31
0
 def test_small_input_timegrain(self):
     win_s = 1024
     f = fft(win_s)
     t = fvec(1)
     with self.assertRaises(ValueError):
         f(t)
Example #32
0
 def test_large_input_fftgrain(self):
     win_s = 1024
     f = fft(win_s)
     s = cvec(win_s + 5)
     with self.assertRaises(ValueError):
         f.rdo(s)
Example #33
0
 def test_small_input_fftgrain(self):
     win_s = 1024
     f = fft(win_s)
     s = cvec(16)
     with self.assertRaises(ValueError):
         f.rdo(s)
Example #34
0
 def test_members(self):
     """ check members are set correctly """
     win_s = 2048
     f = fft(win_s)
     assert_equal (f.win_s, win_s)
Example #35
0
 def test_wrong_buf_size(self):
     win_s = -1
     with self.assertRaises(ValueError):
         fft(win_s)
Example #36
0
 def test_members(self):
     """ check members are set correctly """
     win_s = 2048
     f = fft(win_s)
     assert_equal(f.win_s, win_s)
Example #37
0
 def test_members(self):
     f = fft()
     assert_equal(f.win_s, 1024)
Example #38
0
 def test_small_input_fftgrain(self):
     win_s = 1024
     f = fft(win_s)
     s = cvec(16)
     with self.assertRaises(ValueError):
         f.rdo(s)
Example #39
0
 def test_members(self):
   f = fft()
   assert_equal (f.win_s, 1024)
Example #40
0
 def test_wrong_buf_size(self):
     win_s = -1
     with self.assertRaises(ValueError):
         fft(win_s)