forked from VCVRack/VCV-Prototype
/
rack.lib
63 lines (40 loc) · 2.01 KB
/
rack.lib
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
/* ----------------------------------------------------------------------------
ProtoFaust
==========
DSP prototyping in Faust for VCV Rack
Copyright (c) 2019-2020 Martin Zuther (http://www.mzuther.de/) and
contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Thank you for using free software!
---------------------------------------------------------------------------- */
// Converts 1 V/oct to frequency in Hertz.
//
// The conversion formula is: 440 * 2 ^ (volts - 0.75)
// The factor 0.75 shifts 0 V to C-4 (261.6256 Hz)
cv_pitch2freq(cv_pitch) = 440 * 2 ^ (cv_pitch - 0.75);
// Converts frequency in Hertz to 1 V/oct.
//
// The conversion formula is: log2(hertz / 440) + 0.75
// The factor 0.75 shifts 0 V to C-4 (261.6256 Hz)
freq2cv_pitch(freq) = ma.log2(freq / 440) + 0.75;
// Converts 200 mV/oct to frequency in Hertz.
i_cv_pitch2freq(i_cv_pitch) = i_cv_pitch : internal2cv_pitch : cv_pitch2freq;
// Converts frequency in Hertz to 200 mV/oct.
freq2i_cv_pitch(freq) = freq : freq2cv_pitch : cv_pitch2internal;
// Converts Eurorack's 1 V/oct to internal 200 mv/oct.
cv_pitch2internal(cv_pitch) = cv_pitch / 5;
// Converts internal 200 mv/oct to Eurorack's 1 V/oct.
internal2cv_pitch(i_cv_pitch) = i_cv_pitch * 5;
// Converts Eurorack's CV (range of 10V) to internal CV (range of 1V)
cv2internal(cv) = cv / 10;
// Converts internal CV (range of 1V) to Eurorack's CV (range of 10V)
internal2cv(i_cv) = i_cv * 10;