source: tests/python/src/utils/scale.py @ 4e3723d

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 4e3723d was db62622, checked in by Paul Brossier <piem@piem.org>, 15 years ago

tests/python: update imports

  • Property mode set to 100644
File size: 2.8 KB
Line 
1from template import aubio_unit_template
2from localaubio import *
3
4buf_size = 2000
5channels = 2
6
7ilow = .40
8ihig = 40.00
9olow = 100.0
10ohig = 1000.
11
12class scale_unit(aubio_unit_template):
13
14  def setUp(self):
15    self.o = new_aubio_scale(ilow, ihig, olow, ohig)
16
17  def tearDown(self):
18    del_aubio_scale(self.o)
19
20  def test(self):
21    """ create and delete scale """
22    pass
23
24  def test_zeroes(self):
25    """ test scale on zeroes """
26    input = new_fvec(buf_size, channels)
27    aubio_scale_do(self.o, input)
28    for index in range(buf_size):
29      for channel in range(channels):
30        expval = (- ilow) * (ohig - olow) / \
31          (ihig - ilow) + olow
32        val = fvec_read_sample(input, channel, index)
33        self.assertCloseEnough(expval, val)
34    del_fvec(input)
35
36  def test_ilow(self):
37    """ test scale on ilow """
38    input = new_fvec(buf_size, channels)
39    for index in range(buf_size):
40      for channel in range(channels):
41        fvec_write_sample(input, ilow, channel, index)
42    aubio_scale_do(self.o, input)
43    for index in range(buf_size):
44      for channel in range(channels):
45        val = fvec_read_sample(input, channel, index)
46        self.assertAlmostEqual(olow, val)
47    del_fvec(input)
48
49  def test_ihig(self):
50    """ test scale on ihig """
51    input = new_fvec(buf_size, channels)
52    for index in range(buf_size):
53      for channel in range(channels):
54        fvec_write_sample(input, ihig, channel, index)
55    aubio_scale_do(self.o, input)
56    for index in range(buf_size):
57      for channel in range(channels):
58        val = fvec_read_sample(input, channel, index)
59        self.assertCloseEnough(ohig, val)
60    del_fvec(input)
61
62  def test_climbing_ramp(self):
63    """ test scale on climbing ramp """
64    input = new_fvec(buf_size, channels)
65    for index in range(buf_size):
66      for channel in range(channels):
67        rampval = index*(ihig-ilow)/buf_size + ilow
68        fvec_write_sample(input, rampval, channel, index)
69    aubio_scale_do(self.o, input)
70    for index in range(buf_size):
71      for channel in range(channels):
72        expval = index*(ohig-olow)/buf_size + olow
73        self.assertCloseEnough(expval, \
74          fvec_read_sample(input, channel, index))
75    del_fvec(input)
76
77  def test_falling_ramp(self):
78    """ test scale on falling ramp """
79    input = new_fvec(buf_size, channels)
80    for index in range(buf_size):
81      for channel in range(channels):
82        fvec_write_sample(input, ihig \
83          - index*(ihig-ilow)/buf_size, \
84          channel, index)
85    aubio_scale_do(self.o, input)
86    for index in range(buf_size):
87      for channel in range(channels):
88        expval = ohig - index*(ohig-olow)/buf_size
89        self.assertCloseEnough(expval, \
90          fvec_read_sample(input, channel, index))
91    del_fvec(input)
92
93if __name__ == '__main__': unittest.main()
Note: See TracBrowser for help on using the repository browser.