-
Notifications
You must be signed in to change notification settings - Fork 10
/
DSP Math and Psuedo Codes.txt
329 lines (280 loc) · 8.18 KB
/
DSP Math and Psuedo Codes.txt
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
Array strings for BPM divisors
1/64t,1/64,1/64d,1/32t,1/32,1/32d,1/16t,1/16,1/16d,1/8t,1/8,1/8d,1/4t,1/4,1/4d,1/2t,1/2,1/2d,1bar,2bar,4bar,8bar,16bar,32bar,64bar
-------------------------------------
Array strings for BPM divisors other way around 0-21
var divStrings = ["1/32t","1/32","1/32d","1/16t","1/16","1/16d","1/8t","1/8","1/8d","1/4t","1/4","1/4d","1/2t","1/2","1/2d","1bar","2bar","4bar","8bar","16bar","32bar","64bar"];
-------------------------------------
Tempo Division values fast to slow 1/32t to 64 bars 0-21
var divValues = [0.084,0.125,0.188,0.166,0.25,0.376,0.333,0.5,0.75,0.666,1,1.5,1.33,2,3,4,8,16,32,64,128,256]
-------------------------------------
String Array JUCE C++ 0-21
StringArray divStrings =
{
TRANS ("1/32t"),
TRANS ("1/32"),
TRANS ("1/32d"),
TRANS ("1/16t"),
TRANS ("1/16"),
TRANS ("1/16d"),
TRANS ("1/8t"),
TRANS ("1/8"),
TRANS ("1/8d"),
TRANS ("1/4t"),
TRANS ("1/4"),
TRANS ("1/4d"),
TRANS ("1/2t"),
TRANS ("1/2"),
TRANS ("1/2d"),
TRANS ("1bar"),
TRANS ("2bar"),
TRANS ("4bar"),
TRANS ("8bar"),
TRANS ("16bar"),
TRANS ("32bar"),
TRANS ("64bar")
};
-------------------------------------
Sample Rates Array JS
var sampleRates = ["8000","11025","16000","22050","32000","37800","44056","44100","48000","88200","96000","176400","192000","352800"]
-------------------------------------
Sample Rates Array Juce C++
StringArray srStrings =
{
TRANS ("8000"),
TRANS ("11025"),
TRANS ("16000"),
TRANS ("22050"),
TRANS ("32000"),
TRANS ("37800"),
TRANS ("44056"),
TRANS ("44100"),
TRANS ("48000"),
TRANS ("88200"),
TRANS ("96000"),
TRANS ("176400"),
TRANS ("192000"),
TRANS ("352800")
};
-------------------------------------
Note names Array - JS
var noteStrings = ["C0","C#0","D0","D#0","E0","F0","F#0","G0","G#0","A0","A#0","B0","C1","C#1","D1","D#1","E1","F1","F#1","G1","G#1","A1","A#1","B1","C2","C#2","D2","D#2","E2","F2","F#2","G2","G#2","A2","A#2","B2","C3","C#3","D3","D#3","E3","F3","F#3","G3","G#3","A3","A#3","B3","C4","C#4","D4","D#4","E4","F4","F#4","G4","G#4","A4","A#4","B4","C5","C#5","D5","D#5","E5","F5","F#5","G5","G#5","A5","A#5","B5","C6","C#6","D6","D#6","E6","F6","F#6","G6","G#6","A6","A#6","B6","C7","C#7","D7","D#7","E7","F7","F#7","G7","G#7","A7","A#7","B7","C8","C#8","D8","D#8","E8","F8","F#8","G8","G#8","A8","A#8","B8"]
-------------------------------------
Note names Array - JUCE C++
StringArray noteStrings =
{
TRANS ("C0"),
TRANS ("C#0"),
TRANS ("D0"),
TRANS ("D#0"),
TRANS ("E0"),
TRANS ("F0"),
TRANS ("F#0"),
TRANS ("G0"),
TRANS ("G#0"),
TRANS ("A0"),
TRANS ("A#0"),
TRANS ("B0"),
TRANS ("C1"),
TRANS ("C#1"),
TRANS ("D1"),
TRANS ("D#1"),
TRANS ("E1"),
TRANS ("F1"),
TRANS ("F#1"),
TRANS ("G1"),
TRANS ("G#1"),
TRANS ("A1"),
TRANS ("A#1"),
TRANS ("B1"),
TRANS ("C2"),
TRANS ("C#2"),
TRANS ("D2"),
TRANS ("D#2"),
TRANS ("E2"),
TRANS ("F2"),
TRANS ("F#2"),
TRANS ("G2"),
TRANS ("G#2"),
TRANS ("A2"),
TRANS ("A#2"),
TRANS ("B2"),
TRANS ("C3"),
TRANS ("C#3"),
TRANS ("D3"),
TRANS ("D#3"),
TRANS ("E3"),
TRANS ("F3"),
TRANS ("F#3"),
TRANS ("G3"),
TRANS ("G#3"),
TRANS ("A3"),
TRANS ("A#3"),
TRANS ("B3"),
TRANS ("C4"),
TRANS ("C#4"),
TRANS ("D4"),
TRANS ("D#4"),
TRANS ("E4"),
TRANS ("F4"),
TRANS ("F#4"),
TRANS ("G4"),
TRANS ("G#4"),
TRANS ("A4"),
TRANS ("A#4"),
TRANS ("B4"),
TRANS ("C5"),
TRANS ("C#5"),
TRANS ("D5"),
TRANS ("D#5"),
TRANS ("E5"),
TRANS ("F5"),
TRANS ("F#5"),
TRANS ("G5"),
TRANS ("G#5"),
TRANS ("A5"),
TRANS ("A#5"),
TRANS ("B5"),
TRANS ("C6"),
TRANS ("C#6"),
TRANS ("D6"),
TRANS ("D#6"),
TRANS ("E6"),
TRANS ("F6"),
TRANS ("F#6"),
TRANS ("G6"),
TRANS ("G#6"),
TRANS ("A6"),
TRANS ("A#6"),
TRANS ("B6"),
TRANS ("C7"),
TRANS ("C#7"),
TRANS ("D7"),
TRANS ("D#7"),
TRANS ("E7"),
TRANS ("F7"),
TRANS ("F#7"),
TRANS ("G7"),
TRANS ("G#7"),
TRANS ("A7"),
TRANS ("A#7"),
TRANS ("B7"),
TRANS ("C8"),
TRANS ("C#8"),
TRANS ("D8"),
TRANS ("D#8"),
TRANS ("E8"),
TRANS ("F8"),
TRANS ("F#8"),
TRANS ("G8"),
TRANS ("G#8"),
TRANS ("A8"),
TRANS ("A#8"),
TRANS ("B8")
};
-------------------------------------
Tuning values array
var tuningValues = [440,415,432,434,436,438,441,442,443,444,446,448]
-------------------------------------
Music Scales Arrays
var scales = ["Major","Natural Minor","Melodic Minor Asc","Melodic Minor Desc","Harmonic Minor","Major Pentatonic","Minor Pentatonic","Minor Blues","Major Blues","Ionian","Dorian","Lydian","Phrygian","Phrygian Dominant","Mixolydian","Aeolian","Aeolian Dominant","Locrian","Super Locrian","Byzantine","Balinese Pelog","Chinese","Diminished","Dominant Diminish","Egyptian","Eight Tone Spanish","Geez","Japanese","Hirajoshi","Oriental","Romanian","Yo"]
-------------------------------------
BPM
60,000 / BPM = one beat in milliseconds
BPM / 60 = 1/4 tempo division time
-------------------------------------
Keys
Black Keys are 0.6296 the height of white keys
White keys are 1.58 the height of black keys
White keys width is 0.15384 of height
Black keys width is 0.1764 of height
Black keys are ~0.5 the width of white keys
-------------------------------------
Keys in p5js
fill (0);
kbBack = rect(0, 0, 480, 101);
fill (fillC1);
c1 = rect(0, 0, 60, 100);
fill (fillD1);
d1 = rect(60, 0, 60, 100);
fill (fillE1);
e1 = rect(120, 0, 60, 100);
fill (fillF1);
f1 = rect(180, 0, 60, 100);
fill (fillG1);
g1 = rect(240, 0, 60, 100);
fill (fillA1);
a1 = rect(300, 0, 60, 100);
fill (fillB1);
b1 = rect(360, 0, 60, 100);
fill (fillC2);
c2 = rect(420, 0, 60, 100);
fill (fillCs1);
cs1 = rect(37, 0, 46, 60);
fill (fillDs1);
ds1 = rect(97, 0, 46, 60);
fill (fillFs1);
fs1 = rect(217, 0, 46, 60);
fill (fillGs1);
gs1 = rect(277, 0, 46, 60);
fill (fillAs1);
as1 = rect(337, 0, 46, 60);
-------------------------------------
Linear to Log
y = (x²/200)*log(x)
-------------------------------------
MIDI CC Chart
http://nickfever.com/music/midi-cc-list
-------------------------------------
MS to Samples
Milliseconds * sample rate = number of samples of samples
-------------------------------------
Note Frequency Chart and Math
https://pages.mtu.edu/~suits/notefreqs.html
-------------------------------------
Pan KSP
function panCalc
$panningL := (real_to_int (1000000.0 * (sqrt(1.0 - (int_to_real($pan) / 1000000.0) ))) )
$panningR := (real_to_int (1000000.0 * (sqrt(int_to_real($pan) / 1000000.0 ))) )
end function
-------------------------------------
Scaling
newVal = (((oldVal - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin
-------------------------------------
Wavetable Creation
44100/2048 ≈ 21.5332Hz use F0 – 23c ≈ 21.5387Hz
48000/2048 = 23.4375Hz use F#0 + 23c ≈ 23.4339Hz
-------------------------------------
Vector Synthesis Flowstone DSP Code
streamin xLfo;
streamin yLfo;
streamout a;
streamout b;
streamout c;
streamout d;
float sum;
float aVal;
float bVal;
float cVal;
float dVal;
aVal = (1 - xLfo)*(1 - yLfo);
bVal = (1 - (1 - xLfo))*(1 - yLfo);
cVal = (1 - xLfo)*(1-(1 - yLfo));
dVal = (1-(1 - xLfo))*(1-(1 - yLfo));
sum = aVal+bVal+cVal+dVal;
a = aVal/sum;
b = bVal/sum;
c = cVal/sum;
d = dVal/sum;
-------------------------------------
Vector Synthesis KSP
function vectorCalc
~valA := (1.0-?xy[0])*(1.0-(1.0-?xy[1]))
~valB := (1.0-(1.0-?xy[0]))*(1.0-(1.0-?xy[1]))
~valC := (1.0-?xy[0])*(1.0-?xy[1])
~valD := (1.0-(1.0-?xy[0]))*(1.0-?xy[1])
~sum := ~valA + ~valB + ~valC + ~valD
$sliderA := real_to_int(1000000.0*(~valA / ~sum))
$sliderB := real_to_int(1000000.0*(~valB / ~sum))
$sliderC := real_to_int(1000000.0*(~valC / ~sum))
$sliderD := real_to_int(1000000.0*(~valD / ~sum))
end function