| 1 |
//--------------------------------------| |
| 2 |
// Dyno demo 3: "Ducker? She didn't even throw a punch!" |
| 3 |
// Shows how to make one sound fade out when another comes up. This is |
| 4 |
// probably more often used by radio DJs than electronic musicians, but |
| 5 |
// what the hey. |
| 6 |
// |
| 7 |
// authors: Matt Hoffman (mdhoffma at cs.princeton.edu) |
| 8 |
//--------------------------------------| |
| 9 |
|
| 10 |
// A kick drum that will get quieter when the SinOsc swells. |
| 11 |
SndBuf buf => Gain g1 => Dyno dy => JCRev r => dac; |
| 12 |
me.sourceDir() + "/../data/kick.wav" => buf.read; |
| 13 |
.05 => r.mix; |
| 14 |
|
| 15 |
// A SinOsc that, when its volume swells, will make the kick drum get quieter. |
| 16 |
SinOsc s => Gain g2 => r; |
| 17 |
220 => s.freq; |
| 18 |
|
| 19 |
// Make dy go into ducker mode |
| 20 |
dy.duck(); |
| 21 |
|
| 22 |
// spork the shred that makes the kick kick. |
| 23 |
spork ~ playKick(); |
| 24 |
|
| 25 |
// th is the phase of the low-freq sine that modulates the SinOsc's gain |
| 26 |
0 => float th; |
| 27 |
// make the SinOsc a bit less annoying |
| 28 |
0.5 => g2.gain; |
| 29 |
|
| 30 |
// loop |
| 31 |
while( true ) |
| 32 |
{ |
| 33 |
// modulate the SinOsc's gain |
| 34 |
Math.sin(th) + 1.0 => s.gain; |
| 35 |
// send the SinOsc's last sample to dy (manually. yes, this is a pain.) |
| 36 |
s.last() => dy.sideInput; |
| 37 |
// advance the modulating sine's phase a tiny bit |
| 38 |
th + 0.00003 => th; |
| 39 |
// advance time by one sample. |
| 40 |
1::samp => now; |
| 41 |
} |
| 42 |
|
| 43 |
// retriggers the kick drum over and over and over and over and over. |
| 44 |
fun void playKick() |
| 45 |
{ |
| 46 |
while(true) |
| 47 |
{ |
| 48 |
0 => buf.pos; |
| 49 |
500::ms => now; |
| 50 |
} |
| 51 |
} |