| 1 |
// WinFunEnv is an Attack/Release envelope built around window functions! |
| 2 |
|
| 3 |
// ~options |
| 4 |
// |
| 5 |
// .set (duration, duration), default (0.0, 0.0) |
| 6 |
// sets duration for attack and release phase |
| 7 |
// |
| 8 |
// .attackTime (duration), default 0.0 |
| 9 |
// sets length for the attack phase |
| 10 |
// |
| 11 |
// .releaseTime (duration), default 0.0 |
| 12 |
// sets length for the release phase |
| 13 |
// |
| 14 |
// ~ the following window functions are available to use as envelopes |
| 15 |
// ~ certain functions allow for custom coefficient values (ie setBlackman(0.64) ) |
| 16 |
// |
| 17 |
// setBlackman() |
| 18 |
// setBlackman(float a) |
| 19 |
// setBlackmanHarris() |
| 20 |
// setBlackmanDerivative (float a0, float a1, float a2, float a3); |
| 21 |
// setBlackmanNutall() |
| 22 |
// setExponential() |
| 23 |
// setExponential(a) |
| 24 |
// setHann() |
| 25 |
// setHannPoisson() |
| 26 |
// setHannPoisson(a) |
| 27 |
// setNutall() |
| 28 |
// setParzen() |
| 29 |
// setPoisson() |
| 30 |
// setPoisson(float a) |
| 31 |
// setTukey() |
| 32 |
// setTukey(float a) |
| 33 |
// setWelch |
| 34 |
// |
| 35 |
// ~ hopefully further updates will see more windows being added (Kaiser, etc) |
| 36 |
|
| 37 |
Noise nois => WinFuncEnv win1 => dac; |
| 38 |
|
| 39 |
fun void playWindow(WinFuncEnv @ win, dur attack, dur release) { |
| 40 |
win.attackTime(attack); |
| 41 |
win.releaseTime(release); |
| 42 |
win.keyOn(); |
| 43 |
attack => now; |
| 44 |
win.keyOff(); |
| 45 |
release => now; |
| 46 |
} |
| 47 |
|
| 48 |
// sets Blackman Envelope with a default value of 0.16 |
| 49 |
win1.setBlackman(); |
| 50 |
<<< "Blackman Envelope with default value of 0.16 on white noise", "" >>>; |
| 51 |
playWindow(win1, 2.5::second, 2.5::second); |
| 52 |
|
| 53 |
// sets Blackman Envelope with a custom value |
| 54 |
win1.setBlackman(Math.random2f(0.05, 0.25)); |
| 55 |
<<< "Blackman Envelope with a random custom value on white noise.", "" >>>; |
| 56 |
playWindow(win1, 2.5::second, 2.5::second); |
| 57 |
|
| 58 |
<<< "Blackman Envelope with a short attack and a long release..", "" >>>; |
| 59 |
playWindow(win1, 100::ms, 3::second); |
| 60 |
|
| 61 |
<<< "Blackman Envelope with a long attack and a short release..", "" >>>; |
| 62 |
playWindow(win1, 3::second, 100::ms); |
| 63 |
|
| 64 |
// sets BlackmanHarris Envelope |
| 65 |
win1.setBlackmanHarris(); |
| 66 |
<<< "BlackmanHarris Envelope on white noise.", "" >>>; |
| 67 |
playWindow(win1, 2.5::second, 2.5::second); |
| 68 |
|
| 69 |
// replacing noise with a sine wave |
| 70 |
nois =< win1; |
| 71 |
SinOsc sin => win1; |
| 72 |
|
| 73 |
// sets Parzen Envelope |
| 74 |
win1.setParzen(); |
| 75 |
<<< "Parzen Window used for amplitude modulation on a sine wave", "" >>>; |
| 76 |
for (int i; i < 25000; i++) { |
| 77 |
playWindow(win1, 0.1::ms, 0.1::ms); |
| 78 |
} |
| 79 |
|
| 80 |
// sets Hann Envelope |
| 81 |
win1.setHann(); |
| 82 |
<<< "Hann Window used for amplitude modulation on a sine wave", "" >>>; |
| 83 |
for (int i; i < 25000; i++) { |
| 84 |
playWindow(win1, 0.1::ms, 0.1::ms); |
| 85 |
} |
| 86 |
|
| 87 |
// removing sine wave, adding noise and a second envelope to be in series with the first |
| 88 |
sin =< win1; |
| 89 |
nois => win1 =< dac; |
| 90 |
win1 => WinFuncEnv win2 => dac; |
| 91 |
|
| 92 |
<<< "Two envelopes, one Parzen and one Welch in series with each other with slightly different envelope times.", "" >>>; |
| 93 |
win1.setParzen(); |
| 94 |
win2.setWelch(); |
| 95 |
|
| 96 |
fun void loop(WinFuncEnv @ win, dur envTime) { |
| 97 |
repeat(500) { |
| 98 |
playWindow(win, envTime, envTime); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
spork ~ loop(win1, 70::ms); |
| 103 |
loop(win2, 73::ms); |