-
Notifications
You must be signed in to change notification settings - Fork 3
/
Presets.cpp
465 lines (434 loc) · 16 KB
/
Presets.cpp
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
//
// Presets.cpp
// Evaluator
//
// Created by Damien Quartz on 10/9/17
//
//
#include "Presets.h"
#include "Evaluator.h" // for the TimeType enum
#define CR "\n"
namespace Presets
{
#if SA_API
const RunMode kRunModeProjectTime = kRunModeAlways;
#endif
const Data kPresets[] =
{
{
"the sierpinsky harmony",
50, 8, kRunModeProjectTime, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// t is automatically incremented before generating a sample frame." CR
"// this program was originally written to run at 8000kHz" CR
"// so we reduce the rate of t to be closer to that rate" CR
"t = t/5;" CR
"// assigning to [*] sends the value to all output channels of the program." CR
"[*] = t&t>>8;",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"the forty-two melody",
50, 8, kRunModeProjectTime, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// t is automatically incremented before generating a sample frame." CR
"// this program was originally written to run at 8000kHz" CR
"// so we reduce the rate of t to be closer to that rate" CR
"t = t/5;" CR
"// assigning to [*] sends the value to all output channels of the program." CR
"[*] = t*(42&t>>10);",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"visy's tune",
50, 8, kRunModeProjectTime, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// this program is one shown in viznut's first bytebeat video" CR
"// https://www.youtube.com/watch?v=GtQdIYUtAHg" CR
"// it was originally written to run at 8000kHz" CR
"// so we reduce the rate of t to be closer to that rate" CR
"t = t/5;" CR
"// assigning to [*] sends the value to all output channels of the program." CR
"[*] = t*((t>>9|t>>13)&25&t>>6);",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"little ditty",
50, 15, kRunModeProjectTime, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// here we make a rhythmic ditty by combining three signals:" CR
"// a frequency modulated saw wave (try changing the frequency of modulation)" CR
"a = (t * 128 + $(t));" CR
"// >> is a bit-shift operator that shifts all bits to the right" CR
"// by the number of bits indicated by the right hand side." CR
"// try changing the hard-coded 8 in here." CR
"b = t >> (t % (8 * w)) / w;" CR
"// the right hand side of >> is wrapped to 64 before the shift," CR
"// so this line is the same as 'c = t;'" CR
"c = t >> 128;" CR
"// finally, we use bitwise OR to combine the three values." CR
"// this is similar to summing floating point signals." CR
"[*] = a | b | c;",
// watches
"a", "b", "c", "", "", "", "", "", "", "",
},
{
"overtone waterfall",
50, 17, kRunModeProjectTime, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// here is another example of combining multiple signals with bitwise OR." CR
"// first a vanilla low frequency saw" CR
"a = t*128;" CR
"// then a saw that descends through the overtone series," CR
"// changing pitch every 50 milliseconds" CR
"b = a*(32-(m/50)%32);" CR
"// and then a saw that ascends through the overtone series," CR
"// changing pitch every 100 milliseconds" CR
"c = a*((m/100)%64);" CR
"[*] = a | b | c;",
// watches
"a", "b", "c", "", "", "", "", "", "", "",
},
{
"aggressive texture",
50, 15, kRunModeProjectTime, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// a low frequency sine wave" CR
"s = $(m/2000);" CR
"// ^ is bitwise XOR" CR
"a = $(t^s);" CR
"// you can cleary hear the held low frequency t*32 here" CR
"// whereas the left side of the OR is sweeping wildly" CR
"[*] = (t*64 + a*s) | t*32;",
// watches
"s", "a", "", "", "", "", "", "", "", "",
},
// this maybe takes too long to get interesting and is just unpleasant noise mostly, might want to ditch it.
{
"blurp",
50, 15, kRunModeAlways, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// if you can stand the noise, let this one run for a long time." CR
"// << shifts the bits of the left hand side" CR
"// by the number on the right hand side modulo 64" CR
"a = t<<t/(1024*8);" CR
"b = t>>t/16;" CR
"c = t>>t/32;" CR
"// & is bitwise AND" CR
"e = (a | b & c);" CR
"// we add 1 in two places here to prevent divide-by-zero errors" CR
"d = t%(t/512+1) + 1;" CR
"// remember that a is divided by d and then multiplied by 32" CR
"[*] = e/d * 32;",
// watches
"a", "b", "c", "d", "e", "", "", "", "", "",
},
{
"garbage trash",
50, 15, kRunModeAlways, false,
16, 0, 0, 0, 0, 0, 0, 0,
"// let this one run for a while, it subtly changes over time." CR
"// r will increase by one every V0+1 milliseconds." CR
"// we add one to V0 to prevent divide-by-zero." CR
"r = m/(V0+1);" CR
"// s will cycle through [0,15] at the same rate." CR
"s = r%16;" CR
"// note here that due to operator precedence," CR
"// t is multiplied by s and then the modulo is applied" CR
"[*] = (256*s + t*s%(512*s+1)) * r;",
// watches
"r", "s", "", "", "", "", "", "", "", "",
},
{
"nonsense can",
50, 15, kRunModeAlways, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// this demonstrates using the previous value of the program" CR
"// in the calculation for output value" CR
"a = 1 + $(m)%32;" CR
"b = t*128 & t*64 & t*32;" CR
"c = (p/16) << p%4;" CR
"d = $(p/128) >> p%4;" CR
"p = a ^ b | c | d;" CR
"[*] = p;",
// watches
"a", "b", "c", "d", "p", "", "", "", "", "",
},
{
"oink oink ribbit",
30, 18, kRunModeProjectTime, false,
17, 2, 45, 5, 3, 0, 0, 0,
"// another example of using the previous value as part of the program," CR
"// with several V knobs incorporated" CR
"o = t*128;" CR
"a = t*V0 >> V1;" CR
"b = t - V2*100;" CR
"c = b*64 | b*V3>>V4;" CR
"p = (o | a) | c | p<<12;" CR
"[*] = p;",
// watches
"a", "b", "c", "p", "V0", "V1", "V2", "V3", "V4", "",
},
{
"moving average",
50, 17, kRunModeAlways, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// this sonifies the cumulative moving average for the function" CR
"// f(x) = x*256 ^ x*64 & x*32" CR
"// see https://en.wikipedia.org/wiki/Moving_average" CR
"x = t+1;" CR
"f = x*256 ^ x*64 & x*32;" CR
"p = p + (f - p)/x;" CR
"[*] = p;",
// watches
"x", "f", "p", "", "", "", "", "", "", "",
},
{
"stereo ellipse",
50, 22, kRunModeAlways, false,
20, 100, 0, 0, 0, 0, 0, 0,
"// this sonifies the parametric equations for an ellipse." CR
"// the x-coordinate is sent to the left output channel." CR
"// the y-coordinate is sent to the right output channel." CR
"// V0 and V1 can be used to control the radii of the ellipse" CR
"a = V0+1;" CR
"b = V1+1;" CR
"// the cosine of t*128" CR
"c = $((t+w/2)*128);" CR
"// the sine of t*128;" CR
"s = $(t*128);" CR
"// assigning to [0] sets only the first output channel (left)" CR
"[0] = a*c;" CR
"// assigning to [1] sets only the second output channel (right)" CR
"[1] = b*s;",
// watches
"a", "b", "c", "s", "", "", "", "", "", "",
},
{
"sample and hold effect",
100, 16, kRunModeAlways, false,
36, 0, 0, 0, 0, 0, 0, 0,
"// this modifies the audio coming into the program" CR
"// to create a sample and hold effect, with V0 controlling the intensity." CR
"// s is how many samples to wait before grabbing a new value from the input" CR
"s = V0 + 2;" CR
"// r holds a 'bool' to indicate whether or not we should sample the input" CR
"r = p==0 & p<t%s;" CR
"p = t%s;" CR
"// when r is 'true' we sample the input," CR
"// otherwise we keep the value we already have" CR
"r ? a = [0];" CR
"r ? b = [1];" CR
"// and now we output our result" CR
"[0] = a; [1] = b;",
// watches
"V0", "s", "r", "a", "b", "", "", "", "", "",
},
// name, volume, bit depth, t-mode, program text
{
"saw wave",
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// t is incremented only when there is at least one active Midi Note." CR
"// n is set to the most recent MIDI Note On value." CR
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// F is a unary operator that converts its operand to a 'frequency'." CR
"// If F's operand is a MIDI note number," CR
"// the result can be multiplied with t to create an oscillator" CR
"// whose pitch will be the same the MIDI note's pitch." CR
"// increasing BIT will lower the octave, decreasing BIT will raise the octave." CR
"// since t increases linearly, this oscillator creates a saw wave." CR
"// assigning to [*] sends the value to all output channels of the program." CR
"[*] = t*Fn;",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"square wave",
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// # is a unary operator that creates a 'square' of its operand." CR
"// it does this by taking the operand modulo w" CR
"// and returning 0 if the result is less than w/2" CR
"// or w-1 if greater than or equal to w/2." CR
"// ie: #a == a%w < w/2 ? 0 : w-1" CR
"// this lets us turn a saw wave into a square wave" CR
"[*] = #(t*Fn);",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"sine wave",
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// $ is a unary operator that returns the 'sine' of its operand." CR
"// the 'sine' is calculated in relation to the current value of w." CR
"// this lets us turn a saw wave into a sine wave" CR
"[*] = $(t*Fn);",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"triangle wave",
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// T is a unary operator that returns the 'triangle' of its operand." CR
"// like $ and #, the operation uses the current value of w." CR
"// this lets us easily turn a saw wave into a triangle wave" CR
"[*] = T(t*Fn);",
// watches
"", "", "", "", "", "", "", "", "", "",
},
{
"pulse wave",
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// a pulse wave is a square wave that spends longer" CR
"// on one of the two values every cycle." CR
"// we use a modified version of the square formula to do this:" CR
"// first we create our wrapped saw wave and save it in a variable" CR
"// (any lowercase letter can be used as a variable)." CR
"a = (t*Fn)%w;" CR
"// we want the high part of the wave to last longer than the low part" CR
"// so we use the less-than operator to create a 0 or 1 value" CR
"b = a < 8800;" CR
"// we then multiply w-1 by our 0 or 1 value to create the pulse wave" CR
"[*] = (w-1)*b;",
// watches
"a", "b", "", "", "", "", "", "", "", "",
},
{
"ternary arp",
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// the ternary operator '?:' can be used to create expressions" CR
"// that will resolve to one of two values." CR
"// here we use it to modify n every other sixteenth note." CR
"// q is incremented every 128th note, so we can divide by 32" CR
"// to get a number that increments every sixteenth note." CR
"s = q/32;" CR
"// if s is odd, we want to increase the note by an octave." CR
"a = n + (s%2 ? 12 : 0);" CR
"// finally, we can create our oscillator" CR
"[*] = t*Fa;",
// watches
"s", "a", "", "", "", "", "", "", "", "",
},
{
"frequency modulation",
50, 16, kRunModeMIDI, false,
2, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// a saw wave can be frequency modulated by adding a sine wave to it." CR
"// we use the value of the V0 knob to control the modulation frequency." CR
"[*] = t*Fn + $(t*V0);",
// watches
"V0", "", "", "", "", "", "", "", "", "",
},
{
"amplitude modulation",
50, 16, kRunModeAlways, true,
12, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// to amplitude modulate we need to scale the range up and down," CR
"// but keep the values 'centered' around w/2." CR
"// so we wrap to [0, w) before scaling with our modulator." CR
"o = (t*Fn) % w;" CR
"// we step the phase of our modulator forward every 8 milliseconds," CR
"// which lets us smoothly control the frequency with the V0 knob." CR
"m % 8 == 0 ? p = p + V0 * 2;" CR
"// if there isn't a note on, we reset the phase so that $p will be 0." CR
"n == 0 ? p = 3 * w / 4;" CR
"m = $p;" CR
"// m is a [0,w) value, so we decrease o by that ratio" CR
"o = o * m/w;" CR
"// then to center, we offset by how much w/2 is changed by this ratio" CR
"[*] = o + ((w/2) - (w/2) * m/w);",
// watches
"V0", "o", "p", "", "", "", "", "", "", "",
},
{
"midi pitch sweep",
15, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// the C operator allows us to access incoming midi control change values." CR
"// here we use the modwheel to control the pitch of an oscillator." CR
"// in order to have the pitch change smoothly, we step the phase explicitly" CR
"// instead of using a multiple of t as in other presets." CR
"// we want the modwheel to sweep up an octave so we add in" CR
"// a fraction of the distance to the note an octave above n." CR
"// by doing this after converting to 'frequency' we get a smoother sweep." CR
"a = Fn + (F(n+12) - Fn)*C1/127;" CR
"o = n>0 ? o + a : w/2;" CR
"[*] = o;",
// watches
"a", "o", "C1", "", "", "", "", "", "", "",
},
{
"computer music" ,
50, 16, kRunModeMIDI, false,
0, 0, 0, 0, 0, 0, 0, 0,
"// connect a MIDI device or use the computer keyboard to generate notes." CR
"// here we create a random note sequence" CR
"// based on the incoming MIDI note." CR
"// r is how often the note changes - every 125 milliseconds" CR
"r = 125;" CR
"// R is a unary operator that produces a random value using the operand." CR
"// R22 will range between 0 and 21." CR
"// we choose a new value when p equals zero and is less than m%r" CR
"p==0 & p<m%r ? a = R22;" CR
"p = m%r;" CR
"[*] = $(t*F(n + a));",
// watches
"s", "a", "", "", "", "", "", "", "", "",
},
{
"rhythmic glitch sine",
50, 16, kRunModeMIDI, true,
0, 0, 0, 0, 0, 0, 0, 0,
"// programs have a large 'user' memory space that can be accessed with '@'." CR
"// this allows us to store many previous values of the program." CR
"// c is how many values to store (try changing this number)" CR
"c = 1024*4;" CR
"// s is where to save the current value" CR
"s = t%c;" CR
"// r is which previous value to read" CR
"r = (t+512)%c;" CR
"// we write into the address s and incorporate address r," CR
"// but only if there is an active midi note." CR
"// otherwise we 'reset' @s to w/2, which will produce silence" CR
"@s = n>0 ? $(t*Fn) + @r : w/2;" CR
"[*] = @s;",
// watches
"r", "s", "@r", "@s", "", "", "", "", "", "",
},
{
"memory sequence",
50, 16, kRunModeMIDI, true,
0, 0, 0, 0, 0, 0, 0, 0,
"// another way to use 'user' memory could be to store values of a sequence." CR
"// here we create an arpeggiator" CR
"// that uses the midi note as the root of a major chord." CR
"// we can store a list of values to consecutive memory addresses like this:" CR
"@0 = { 0, 4, 7, 12 };" CR CR
"// we want advance through the sequence every sixteenth note," CR
"// wrapping around to the beginning of the sequence when it reaches the end." CR
"i = q/32 % 4;" CR
"[*] = n>0 ? t*F(n+@i) : w/2;",
// watches
"@0", "@1", "@2", "@3", "i", "@i", "", "", "", "",
},
};
const int kCount = sizeof(kPresets) / sizeof(Data);
int Count() { return kCount; }
const Data& Get(int idx) { return kPresets[idx]; }
};