-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_processor.py
77 lines (58 loc) · 2.05 KB
/
test_processor.py
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
74
75
76
77
# pylint: skip-file
import pytest
import numpy as np
import dsp
@pytest.mark.parametrize("tc", [
({'sr': 44100.0, 'bs': 128, 'ch': 1}),
({'sr': 48000.0, 'bs': 512, 'ch': 1}),
({'sr': 88200.0, 'bs': 1024, 'ch': 2}),
({'sr': 96000.0, 'bs': 32, 'ch': 4}),
])
def test_processor_spec(tc):
spec = dsp.ProcessorSpec(
sample_rate=tc['sr'],
block_size=tc['bs'],
channels=tc['ch'],
)
assert spec.sample_rate == tc['sr']
assert spec.block_size == tc['bs']
assert spec.channels == tc['ch']
class TestProcessor(dsp.AudioProcessor):
'''Base class for all audio effects & analyzers
'''
def prepare(self, spec: dsp.ProcessorSpec) -> None:
'''Needs to be implemented in the child class
'''
def process(self, buffer: np.ndarray) -> np.ndarray:
'''Needs to be implemented in the child class
'''
return buffer
def release(self) -> None:
'''Needs to be implemented in the child class
'''
def test_audio_processor():
effect = TestProcessor()
assert effect.spec.sample_rate == 44100.0
assert effect.spec.block_size == 1024
assert effect.spec.channels == 1
param = dsp.AudioParameterBool('1', 'name', False)
effect.add_parameter(parameter=param)
assert len(effect.parameters) == 1
assert effect.parameters['1'].identifier == '1'
assert effect.parameters['1'].name == 'name'
assert not effect.parameters['1'].value
assert not effect.parameters['1'].default_value
effect.prepare(dsp.ProcessorSpec())
assert effect.process(None) is None
buffer = np.zeros((1024,), dtype=np.float64)
assert type(effect.process(buffer)) == np.ndarray
state = effect.state
assert not effect.parameters['1'].value
effect.parameters['1'].value = True
assert effect.parameters['1'].value
effect.state = {'1': False}
assert not effect.parameters['1'].value
effect.parameters['1'].value = True
assert effect.parameters['1'].value
effect.state = state
assert not effect.parameters['1'].value