forked from pichenettes/eurorack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookup_tables.py
executable file
·153 lines (117 loc) · 4.78 KB
/
lookup_tables.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/python2.5
#
# Copyright 2014 Emilie Gillet.
#
# Author: Emilie Gillet ([email protected])
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# See http://creativecommons.org/licenses/MIT/ for more information.
#
# -----------------------------------------------------------------------------
#
# Lookup table definitions.
import numpy
"""----------------------------------------------------------------------------
LFO and envelope increments.
----------------------------------------------------------------------------"""
lookup_tables = []
lookup_tables_32 = []
sample_rate = 31089
excursion = 1 << 32
num_values = 257
# Create lookup table for envelope times (x^0.25).
max_time = 12.0 # seconds
min_time = 0.0005
gamma = 0.25
min_increment = excursion / (max_time * sample_rate)
max_increment = excursion / (min_time * sample_rate)
rates = numpy.linspace(numpy.power(max_increment, -gamma),
numpy.power(min_increment, -gamma), num_values)
values = numpy.power(rates, -1/gamma).astype(int)
lookup_tables_32.append(
('env_increments', values)
)
"""----------------------------------------------------------------------------
Envelope curves
-----------------------------------------------------------------------------"""
env_linear = numpy.arange(0, 257.0) / 256.0
env_linear[-1] = env_linear[-2]
env_quartic = env_linear ** 3.32
env_expo = 1.0 - numpy.exp(-4 * env_linear)
lookup_tables.append(('env_linear', env_linear / env_linear.max() * 65535.0))
lookup_tables.append(('env_expo', env_expo / env_expo.max() * 65535.0))
lookup_tables.append(('env_quartic', env_quartic / env_quartic.max() * 65535.0))
lookup_tables.append(('square_root', (env_linear ** 0.5) * 65535.0))
"""----------------------------------------------------------------------------
SVF coefficients
----------------------------------------------------------------------------"""
cutoff = 440.0 * 2 ** ((numpy.arange(0, 257) - 69) / 12.0)
f = cutoff / sample_rate
f[f > 1 / 8.0] = 1 / 8.0
f = 2 * numpy.sin(numpy.pi * f)
resonance = numpy.arange(0, 257) / 257.0
damp = numpy.minimum(2 * (1 - resonance ** 0.25),
numpy.minimum(2, 2 / f - f * 0.5))
lookup_tables.append(
('svf_cutoff', f * 32767.0)
)
lookup_tables.append(
('svf_damp', damp * 32767.0)
)
"""----------------------------------------------------------------------------
Vactrol attack/decay time
----------------------------------------------------------------------------"""
vactrol_time = 0.001 * 10 ** (numpy.arange(0, 128 * 5) / 128.0)
vactrol_time[0] = 0.0001
vactrol_time[1] = 0.0002
vactrol_time[2] = 0.0005
vactrol_time[3] = 0.001
filter_coefficients = 1.0 - numpy.exp(-1 / (vactrol_time * sample_rate))
lookup_tables_32.append(
('lp_coefficients', excursion / 2 * filter_coefficients)
)
"""----------------------------------------------------------------------------
2164 gain
----------------------------------------------------------------------------"""
gains = (numpy.arange(0, 257) / 256.0) * 3.3
gains =10 ** (-1.5 * gains)
lookup_tables.append(
('2164_gain', gains * 32767.0)
)
"""----------------------------------------------------------------------------
Compressor tables
----------------------------------------------------------------------------"""
t = (numpy.arange(0, 257) / 256.0)
lookup_tables_32 += [
('exp2', 65536.0 * 2 ** t),
('log2', 65536.0 * numpy.log2(256 + 256 * t))]
lookup_tables += [
('compressor_ratio', 256 / (24 * t * t + 1)),
('soft_knee', (t ** 3.0) * 65535.0)
]
"""----------------------------------------------------------------------------
Rate control
----------------------------------------------------------------------------"""
t = numpy.arange(0, 257) / 256.0
t /= (20 / 100.0 / 3.3)
f = 2.0 ** t
f /= f[-1]
f *= 0.02 * (1 << 24)
lookup_tables_32.append(('lorenz_rate', f))