4 // Harmonics objects are convenient factories for creating Arrays that
5 // are used to fill buffers using the b_gen sine fill commands on the server.
8 ^super.newCopyArgs(size)
11 // decays with frequency
13 ^Array.fill(size) {|i| 1.0 / ((i+1) ** k) }
16 ^Array.fill(size) {|i| 1.0 / (k ** i) }
20 rand { arg lo=0.0, hi=1.0;
21 ^Array.rand(size, lo, hi)
23 exprand { arg lo=0.01, hi=1.0;
24 ^Array.exprand(size, lo, hi)
26 linrand { arg lo=0.0, hi=1.0;
27 ^Array.linrand(size, lo, hi)
30 ^Array.rand2(size, val)
32 coin { arg prob = 0.5;
33 ^Array.fill(size) { if (prob.coin, 1.0, -1.0) }
36 // other useful shapes
37 formant { arg center=12, width = 3;
39 start = center - (width/2);
40 end = center + (width/2);
41 ^Array.fill(size) {|i|
42 if (i <= start) { 0.0 } {
43 if (i >= end) { 0.0 } {
44 hanWindow((i - start) / width);
49 teeth { arg spacing = 2, start = 0;
50 ^Array.fill(size) {|i|
51 if (i < start) { 0.0 } {
53 if ((i % spacing) == 0, 1.0, 0.0)
58 ^Array.fill(size) {|i| if (i <= n, 1.0, 0.0) }
60 shelf { arg start, end, startLevel = 1.0, endLevel = 0.0;
61 ^Array.fill(size) {|i|
62 if (i <= start) { startLevel } {
63 if (i >= end) { endLevel } {
64 ((i - start) / (end - start)) * (endLevel - startLevel) + startLevel;
70 sine { arg wavelength=4, iphase=0.5pi, mul=1.0, add=0.0;
71 ^Array.fill(size) {|i| sin(2pi/wavelength * i + iphase) * mul + add }
73 pulse { arg wavelength=4, iphase=0, duty = 0.5, mul=1.0, add=0.0;
74 ^Array.fill(size) {|i| if (((i - iphase) % wavelength) < duty, 1.0, 0.0) * mul + add }
77 ramp { arg start=1.0, step;
78 step = step ? size.reciprocal;
79 ^Array.series(size, start, step)