History

python/tests/test_phasevoc.py: cleanup, start using nose2

Paul Brossier committed 10 years ago

Commit fb434c41 parent 7498e481 file · +58 −8Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/test_phasevoc.py+58−8
@@ -4,13 +4,17 @@ from numpy.testing import TestCase, assert_equal, assert_array_less · 3 unmodified lines
4from aubio import fvec, cvec, pvoc, float_type4from aubio import fvec, cvec, pvoc, float_type
5from numpy import array, shape5from numpy import array, shape
6from numpy.random import random6from numpy.random import random
7from nose2.tools import params
7import numpy as np8import numpy as np
8 9
9max_sq_error = 1.e-1210if float_type == 'float32':
11 max_sq_error = 1.e-12
12else:
13 max_sq_error = 1.e-29
10 14
11def create_sine(hop_s, freq, samplerate):15def create_sine(hop_s, freq, samplerate):
12 t = np.arange(hop_s).astype(float_type)16 t = np.arange(hop_s).astype(float_type)
13 return np.sin( 2. * np.pi * t * freq / samplerate)17 return np.sin( 2. * np.pi * freq * t / float(samplerate))
14 18
15def create_noise(hop_s):19def create_noise(hop_s):
16 return np.random.rand(hop_s).astype(float_type) * 2. - 1.20 return np.random.rand(hop_s).astype(float_type) * 2. - 1.
@@ -41,10 +45,10 @@ class aubio_pvoc_test_case(TestCase): · 24 unmodified lines
41 for time in range( int ( 4 * win_s / hop_s ) ):45 for time in range( int ( 4 * win_s / hop_s ) ):
42 s = f(t)46 s = f(t)
43 r = f.rdo(s)47 r = f.rdo(s)
44 assert_equal ( array(t), 0)48 assert_equal ( t, 0.)
45 assert_equal ( s.norm, 0)49 assert_equal ( s.norm, 0.)
46 assert_equal ( s.phas, 0)50 assert_equal ( s.phas, 0.)
47 assert_equal ( r, 0)51 assert_equal ( r, 0.)
48 52
49 def test_resynth_8_steps_sine(self):53 def test_resynth_8_steps_sine(self):
50 """ check the resynthesis of is correct with 87.5% overlap """54 """ check the resynthesis of is correct with 87.5% overlap """
@@ -91,6 +95,52 @@ class aubio_pvoc_test_case(TestCase): · 40 unmodified lines
91 sigin = create_noise(hop_s)95 sigin = create_noise(hop_s)
92 self.reconstruction(sigin, hop_s, ratio)96 self.reconstruction(sigin, hop_s, ratio)
93 97
98 @params(
99 ( 256, 8),
100 ( 256, 4),
101 ( 256, 2),
102 ( 512, 8),
103 ( 512, 4),
104 ( 512, 2),
105 (1024, 8),
106 (1024, 4),
107 (1024, 2),
108 (2048, 8),
109 (2048, 4),
110 (2048, 2),
111 (4096, 8),
112 (4096, 4),
113 (4096, 2),
114 (8192, 8),
115 (8192, 4),
116 (8192, 2),
117 )
118 def test_resynth_steps_noise(self, hop_s, ratio):
119 """ check the resynthesis of a random signal is correct """
120 sigin = create_noise(hop_s)
121 self.reconstruction(sigin, hop_s, ratio)
122
123 @params(
124 (44100, 256, 8, 441),
125 (44100, 256, 4, 1203),
126 (44100, 256, 2, 3045),
127 (44100, 512, 8, 445),
128 (44100, 512, 4, 445),
129 (44100, 512, 2, 445),
130 (44100, 1024, 8, 445),
131 (44100, 1024, 4, 445),
132 (44100, 1024, 2, 445),
133 ( 8000, 1024, 2, 445),
134 (22050, 1024, 2, 445),
135 (22050, 256, 8, 445),
136 (96000, 1024, 8, 47000),
137 (96000, 1024, 8, 20),
138 )
139 def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
140 """ check the resynthesis of a sine is correct """
141 sigin = create_sine(hop_s, freq, samplerate)
142 self.reconstruction(sigin, hop_s, ratio)
143
94 def reconstruction(self, sigin, hop_s, ratio):144 def reconstruction(self, sigin, hop_s, ratio):
95 buf_s = hop_s * ratio145 buf_s = hop_s * ratio
96 f = pvoc(buf_s, hop_s)146 f = pvoc(buf_s, hop_s)
@@ -104,6 +154,6 @@ class aubio_pvoc_test_case(TestCase): · 7 unmodified lines
104 assert_array_less(sq_error, max_sq_error)154 assert_array_less(sq_error, max_sq_error)
105 155
106if __name__ == '__main__':156if __name__ == '__main__':
107 from unittest import main157 from nose2 import main
108 main()158 main()
109 159

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t