source: tests/python/fft.py @ 685412e

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 685412e was 398c1c5, checked in by Paul Brossier <piem@piem.org>, 17 years ago

add test for fft (which appears to reveal a bug in fftw on powerpc\!)

  • Property mode set to 100644
File size: 3.6 KB
Line 
1import unittest
2import math
3
4from aubio.aubiowrapper import *
5
6buf_size = 2048 
7channels = 1
8
9class aubio_mfft_test_case(unittest.TestCase):
10
11  def setUp(self):
12    self.o = new_aubio_mfft(buf_size, channels)
13
14  def tearDown(self):
15    del_aubio_mfft(self.o)
16
17  def test_aubio_mfft(self):
18    """ create and delete mfft """
19    pass
20
21  def test_aubio_mfft_do_zeroes(self):
22    """ test aubio_mfft_do on zeroes """
23    input    = new_fvec(buf_size, channels)
24    fftgrain = new_cvec(buf_size, channels)
25    for index in range(buf_size):
26      for channel in range(channels):
27        self.assertEqual(0., fvec_read_sample(input, channel, index))
28    aubio_mfft_do(self.o, input, fftgrain)
29    for index in range(buf_size/2+1):
30      for channel in range(channels):
31        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
32    for index in range(buf_size/2+1):
33      for channel in range(channels):
34        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
35    del fftgrain
36    del input
37
38  def test_aubio_mfft_rdo_zeroes(self):
39    """ test aubio_mfft_rdo on zeroes """
40    fftgrain = new_cvec(buf_size, channels)
41    output    = new_fvec(buf_size, channels)
42    aubio_mfft_rdo(self.o, fftgrain, output)
43    # check output
44    for index in range(buf_size):
45      for channel in range(channels):
46        self.assertEqual(0., fvec_read_sample(output, channel, index))
47    del fftgrain
48    del output
49
50  def test_aubio_mfft_do_impulse(self):
51    """ test aubio_mfft_do on impulse one channel """
52    input    = new_fvec(buf_size, channels)
53    fftgrain = new_cvec(buf_size, channels)
54    # write impulse in channel 0, sample 0.
55    fvec_write_sample(input, 1., 0, 0)
56    aubio_mfft_do(self.o, input, fftgrain)
57    # check norm
58    for index in range(buf_size/2+1):
59      self.assertEqual(1., cvec_read_norm(fftgrain, 0, index), index)
60    for index in range(buf_size/2+1):
61      for channel in range(1, channels):
62        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
63    # check phas
64    for index in range(buf_size/2+1):
65      for channel in range(channels):
66        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
67    del fftgrain
68    del input
69
70  def test_aubio_mfft_do_impulse_multichannel(self):
71    " test aubio_mfft_do on impulse two channels "
72    input    = new_fvec(buf_size, channels)
73    fftgrain = new_cvec(buf_size, channels)
74    # put an impulse in first an last channel, at first and last index
75    fvec_write_sample(input, 1., 0, 0)
76    fvec_write_sample(input, 1., channels-1, 0)
77    aubio_mfft_do(self.o, input, fftgrain)
78    # check the norm
79    for index in range(buf_size/2+1):
80      self.assertEqual(1., cvec_read_norm(fftgrain, 0, index))
81    for index in range(buf_size/2+1):
82      for channel in range(1, channels-1):
83        self.assertEqual(0., cvec_read_norm(fftgrain, channel, index))
84    for index in range(buf_size/2+1):
85      self.assertEqual(1., cvec_read_norm(fftgrain, channels-1, index))
86    # check the phase
87    for index in range(buf_size/2+1):
88      for channel in range(channels):
89        self.assertEqual(0., cvec_read_phas(fftgrain, channel, index))
90    del fftgrain
91    del input
92
93  def test_aubio_mfft_rdo_impulse(self):
94    """ test aubio_mfft_rdo on impulse """
95    fftgrain  = new_cvec(buf_size, channels)
96    cvec_write_norm(fftgrain, 1., 0, 0)
97    output    = new_fvec(buf_size, channels)
98    aubio_mfft_rdo(self.o, fftgrain, output)
99    for index in range(buf_size/2+1):
100      for channel in range(channels):
101        self.assertEqual(fvec_read_sample(output, channel, index),1./buf_size)
102    del fftgrain
103    del output
104
105if __name__ == '__main__': unittest.main()
Note: See TracBrowser for help on using the repository browser.