blob: 667d9289fa72aa5b65878c3141eb2e3cacfe075b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import os
import numpy as np
from nose.tools import assert_almost_equals
import simpl.base as base
float_precision = 5
frame_size = 512
hop_size = 512
audio_path = os.path.join(
os.path.dirname(__file__), 'audio/flute.wav'
)
class TestFrame(object):
def test_buffers(self):
N = 256
f = base.Frame(N)
f.synth_size = N
assert f.size == N
assert f.synth_size == N
a = np.random.rand(N)
f.audio = a
assert np.all(f.audio == a)
a = np.random.rand(N)
f.synth = a
assert np.all(f.synth == a)
a = np.random.rand(N)
f.residual = a
assert np.all(f.residual == a)
a = np.random.rand(N)
f.synth_residual = a
assert np.all(f.synth_residual == a)
def test_peaks(self):
p = base.Peak()
p.amplitude = 0.5
p.frequency = 220.0
p.phase = 0.0
f = base.Frame()
assert len(f.peaks) == 0
assert f.max_peaks > 0
f.peaks = [p]
assert_almost_equals(f.peaks[0].amplitude, p.amplitude,
float_precision)
assert_almost_equals(f.peaks[0].frequency, p.frequency,
float_precision)
assert_almost_equals(f.peaks[0].phase, p.phase,
float_precision)
f.clear()
assert len(f.peaks) == 0
def test_partials(self):
N = 256
f = base.Frame(N)
f.max_partials = 10
p = base.Peak()
p.amplitude = 0.5
p.frequency = 220.0
p.phase = 0.0
f.partial(0, p)
assert_almost_equals(f.partial(0).amplitude, p.amplitude,
float_precision)
assert_almost_equals(f.partial(0).frequency, p.frequency,
float_precision)
|