The Csound Blog by Jacob Joaquin email jacobjoaquin@gmail.com web www.thumbuki.com/csound/blog (C)2006 Jacob Joaquin Licensed under Creative Commons (see below) 2006.12.22 An Experiment in Csound Blogging Welcome to my first blog entry that is simulcast both at thumbuki.com and within a Csound file. This is a personal blogging experiment. Often times, I'll finish a Csound file that isn't a composition, nor a bank of instruments, but more like a personal exercise or proof-of-concept. I never distribute these files because, as is, they aren't really helpful to anybody. Perhaps by embedding a blog entry, these files will be placed into proper context, and allow them to be useful for others in the community. I took an extensive break from Csound. By extensive, I mean years. I have recently returned to my computer music roots, with a fresh mind and new-found enthusiasm. I wouldn't say I've forgotten much while on hiatus. In fact, I'm finding it's much like riding a bike. However, I'm still without practice, and am in need of some serious honing. Despite being something I've always wanted to do, I've never gotten around to synthesizing drums. I figured this was as good a time as any to tackle this subject. I found two places on the net that were uber-helpful. The first being Hans Mikelson's Csound magazine articles[1]. The second being Sound on Sound: Synth Secrets[2]. Between these two sources, I ended up with the four electronic percussive instruments. The other thing I wanted to do was to take a new approach to tackling Csound instruments. Traditionally, I've had my individual instruments write directly to the audio stream. However, I've been aware of the advantages of using the zak opcodes for mixing for years now[3]. In this file, I use two mixers. The first is a drum mixer. The four drums instruments produce mono-streams. These streams are sent to the drum mixer, via zak, where their relative amplitudes are set, placed into a stereo field, and sent to two zak audio busses. The second mixer reads the corresponding left and right zak channels, amplifies them, and sends the audio to the dac or file. I experimented with two more zak-related techniques. The first is using a dedicated lfo instrument that writes to a zak k-rate channel. In this example, I implemented four synced LFOs, each featuring a different waveform. Including a sine, triangle, saw-down and square wave. Each waveform is assigned a unique k-rate zak bus. I'm using only one of the LFO channels, to modulate the frequency of a highpass filter in the reverb instrument 110. Note to self: learn to design better spatial processors. The second zak technique I explored was implementing a gate. Every time an "Electro Bell" event occurs, the schedule opcode is used to instantiate an instr 90 event. instr 90 is basically an attack-sustain-decay envelope with razor thin sides. The gated delay processor, instr 120, responds to the gate by briefly capturing a segment of the drums, processing this audio chunk with filters and delay lines, and mixing the resulting effects back into the stereo zak channels. The one last thing I played with was the macro system. Macros are a great thing. They dramatically reduced the difficulty of managing and adding zak channels. The one thing I'm disappointed about them is that macros defined in the orchestra aren't recognized in the score and vice-versa. Perhaps there is a Csound way that I'm just not aware of. If not, no big deal, as I still have Perl to fall back onto. I guess that's it for now. Permalink http://www.thumbuki.com/20061222/an-experiment-in-csound-blogging.html References [1] Hans Mikelson's Drum Article http://www.csounds.com/ezine/autumn1999/ http://www.csounds.com/ezine/winter2001/ [2] Sound on Sound: Synth Secrets http://www.soundonsound.com/search?PageSize=80&Keyword=%22synth%20secrets%22&Words=All&Summary=Yes [3] Zak chapter License (cc) Creative Commons Attribution-ShareAlike 2.5 You are free: * to Share -- to copy, distribute, display, and perform the work * to Remix -- to make derivative works Under the following conditions: * Attribution. You must attribute the work in the manner specified by the author or licensor. * Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. * For any reuse or distribution, you must make clear to others the license terms of this work. * Any of these conditions can be waived if you get permission from the copyright holder. http://creativecommons.org/licenses/by-sa/2.5/ sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 ; instr 1 Zak LFO ; instr 11 Kick Drum ; instr 12 Snare Drum ; instr 13 Electro Bell ; instr 14 Hi-Hat ; instr 90 Triggered Gate ; instr 100 Drum Mixer ; instr 110 Reverb ; instr 120 Gated Delay ; instr 200 Main Mixer ; instr 300 Zak Clear ; Master Volume # define VOLUME #5000# ; Zak Busses # define ZACHANNELS #6# # define ZKCHANNELS #5# zakinit $ZACHANNELS, $ZACHANNELS ; k-rate zak channels # define ZKLFO1SIN #1# # define ZDRUMR #6# # define ZKLFO1TRI #2# # define ZKLFO1SAW #3# # define ZKLFO1SQR #4# # define ZKGATE1 #5# ; a-rate zak channels # define ZKICK #1# # define ZSNARE #2# # define ZBELL #3# # define ZHIHAT #4# # define ZDRUML #5# ; ---- Zak LFO ---- instr 1 ifreq = 1 ; Get length of tables ilen1 tableng 1 ilen2 tableng 2 ilen3 tableng 3 ilen4 tableng 4 kphasor phasor ifreq kosc1 tablei kphasor * ilen1, 1 kosc2 tablei kphasor * ilen2, 2 kosc3 tablei kphasor * ilen3, 3 kosc4 tablei kphasor * ilen4, 4 zkw kosc1, $ZKLFO1SIN zkw kosc2, $ZKLFO1TRI zkw kosc3, $ZKLFO1SAW zkw kosc4, $ZKLFO1SQR endin ; ---- Kick Drum ---- instr 11 idur = 3 kenv1 expseg 900, 0.01, 50, idur - 0.01, 20 asig1 oscil3 1, kenv1, 1 kenv2 line 1, idur, 0 asig1 = asig1 * kenv2 asig2 gauss 1 kenv5 expseg 800, 0.1, 50, idur - 0.1, 20 asig2 tone asig2, kenv5 amix = asig1 + asig2 kenv5 expseg 500, 0.05, 60, idur - 0.05, 20 amix rezzy amix, kenv5, 10 kenv6 linseg 50, idur, 20 aosc oscil3 1, kenv6, 1 kenv4 expseg 2, 0.15, 1, idur - 0.15, 1 kenv4 = kenv4 - 1 amix = ( amix * 0.7 + aosc * 1.8 ) * kenv4 zaw amix, $ZKICK endin ; ---- Snare Drum ---- instr 12 idur = p3 atri oscil3 1, 111, 2 ; triange wave areal, aimag hilbert atri ifshift = 175 asin oscil3 1, ifshift, 1 acos oscil3 1, ifshift, 1, .25 amod1 = areal * acos amod2 = aimag * asin ashift1 = ( amod1 + amod2 ) * 0.7 ifshift2 = 224 asin oscil3 1, ifshift2, 1 acos oscil3 1, ifshift2, 1, .25 amod1 = areal * acos amod2 = aimag * asin ashift2 = ( amod1 + amod2 ) * 0.7 kenv1 linseg 1, 0.15, 0, idur - 0.15, 0 ashiftmix = ( ashift1 + ashift2 ) * kenv1 aosc1 oscil3 1, 180, 1 aosc2 oscil3 1, 330, 1 kenv2 linseg 1, 0.08, 0, idur - 0.08, 0 aoscmix = ( aosc1 + aosc2 ) * kenv2 anoise gauss 1 anoise butterhp anoise, 2000 anoise butterlp anoise, 8000 anoise butterbr anoise, 4000, 200 kenv3 expseg 2, 0.15, 1, idur - 0.15, 1 anoise = anoise * ( kenv3 - 1 ) amix = aoscmix + ashiftmix + anoise * 4 kenv4 linseg 0, 0.01, 1, idur - 0.02, 1, 0.01, 0 amix = amix * kenv4 zaw amix, $ZSNARE endin ; ---- Electro Bell ---- instr 13 idur = p3 kenv expseg 2, 0.1, 1.15, idur - 0.1, 1 kenv = kenv - 1 aosc1 oscil3 kenv, 587, 4 aosc2 oscil3 kenv, 845, 4 amix = ( aosc1 + aosc2 ) amix butterbp amix, 2600, 800 ; trigger zak gate ktempo tempoval schedule 90, 0, 60 / 85 * 2.5 zaw amix, $ZBELL endin ; ---- Hi-Hat ---- instr 14 idur = p3 ifreq = 50 a1 oscil 1, ifreq * 1, 4 a2 oscil 1, ifreq * 2.333, 4 a3 oscil 1, ifreq * 3.578, 4 a4 oscil 1, ifreq * 5.123, 4 a5 oscil 1, ifreq * 7.632, 4 a6 oscil 1, ifreq * 9.843, 4 amix = a1 + a2 + a3 + a4 + a5 + a6 kenv1 linseg 0, 0.01, 1, 0.08, 0, idur - 0.09, 0 amix = amix * kenv1 kenv2 linseg 1, 0.12, 0, idur - 0.12, 0 anoise gauss 1 amix = ( anoise * kenv2 ) * 3.5 + amix amix butterhp amix, 7000 amix = amix + rnd( .05 ) zaw amix, $ZHIHAT endin ; ---- Triggered Gate ---- instr 90 kenv linseg 0, 0.001, 1, p3 - 0.002, 1, 0.001, 0 zkw kenv, $ZKGATE1 endin ; ---- Drum Mixer ---- instr 100 a1 zar $ZKICK a2 zar $ZSNARE a3 zar $ZBELL a4 zar $ZHIHAT a1 = a1 * 3 a2 = a2 * 2.5 a3 = a3 * 6 a4 = a4 * .8 a2l = a2 a2r delay a2, 0.0005 a3l = a3 * sin( .7 ) a3r = a3 * sin( .3 ) irnd = 0.6 + rnd( 0.2 ) a4l = a4 * sin( 1 - irnd ) a4r = a4 * sin( irnd ) aleft = a1 + a2l + a3l + a4l aright = a1 + a2r + a3r + a4r zaw aleft, $ZDRUML zaw aright, $ZDRUMR endin ; ---- Reverb ---- instr 110 aleft zar $ZDRUML aright zar $ZDRUMR klfo zkr $ZKLFO1SIN awet = 0.1 arevl delay aleft, 0.0015 arevr delay aright, 0.0012 arevl butterhp arevl, 2200 + ( klfo * 900 ) arevr butterhp arevr, 2300 + ( klfo * 900 ) arevl butterlp arevl, 3000 arevr butterlp arevr, 3200 arevl reverb arevl, 1 arevr reverb arevr, 1.02 amixl = aleft * sin( 1 - awet ) + arevr * sin( awet ) amixr = aright * sin( 1 - awet ) + arevl * sin( awet ) zaw amixl, $ZDRUML zaw amixr, $ZDRUMR endin ; ---- Gated Delay ---- instr 120 kgate zkr $ZKGATE1 aleft zar $ZDRUML aright zar $ZDRUMR adelayl1 butterhp aleft, 600 adelayl1 butterlp adelayl1, 8000 adelayl1 delay adelayl1, 60/85 * 1 adelayl2 butterlp adelayl1, 4000 adelayl2 delay adelayl1, 60/85 * 3.5 adelayl3 butterlp adelayl2, 2000 adelayl3 delay adelayl2, 60/85 * 5 adelayl = ( adelayl1 + adelayl2 + adelayl3 ) * 0.6 * kgate adelayr1 butterhp aright, 600 adelayr1 butterlp adelayr1, 7000 adelayr1 delay adelayr1, 60/85 * 2 adelayr2 butterlp adelayr1, 3500 adelayr2 delay adelayr1, 60/85 * 4 adelayr3 butterlp adelayr2, 1750 adelayr3 delay adelayr2, .60/85 * 6 adelayr = ( adelayr1 + adelayr2 + adelayr3 ) * 0.6 * kgate zaw aleft + adelayl, $ZDRUML zaw aright + adelayr, $ZDRUMR endin ; ---- Main Mixer ---- instr 200 aleft zar $ZDRUML aright zar $ZDRUMR outs aleft * $VOLUME, aright * $VOLUME endin ; ---- Zak Clear ---- instr 300 zacl 0, $ZACHANNELS zkcl 0, $ZKCHANNELS endin f1 0 65536 10 1 f2 0 8192 -7 -1 4096 1 4096 -1 f3 0 8192 -7 1 8192 -1 f4 0 8192 -7 1 2048 1 0 -1 2048 -1 t 0 85 i1 0 20 i100 0 20 i110 0 20 i120 0 20 i200 0 20 i300 0 20 i11 0.0000 1 i11 0.5000 1 i11 1.5000 1 i11 2.5000 1 i11 2.7500 1 i11 3.5000 1 i12 1.0000 1 i12 1.7500 1 i12 2.2500 1 i12 3.0000 1 i12 3.7500 1 i14 0.0000 1 i14 0.5000 1 i14 1.0000 1 i14 1.5000 1 i14 2.0000 1 i14 2.5000 1 i14 3.0000 1 i14 3.5000 1 i13 3.5000 1 i11 4.0000 1 i11 4.5000 1 i11 5.5000 1 i11 6.5000 1 i11 6.7500 1 i11 7.5000 1 i12 5.0000 1 i12 5.7500 1 i12 6.2500 1 i12 7.0000 1 i12 7.7500 1 i14 4.0000 1 i14 4.5000 1 i14 5.0000 1 i14 5.5000 1 i14 6.0000 1 i14 6.5000 1 i14 7.0000 1 i14 7.5000 1 i13 7.5000 1 i11 8.0000 1 i11 8.5000 1 i11 9.5000 1 i11 10.5000 1 i11 10.7500 1 i11 11.5000 1 i12 9.0000 1 i12 9.7500 1 i12 10.2500 1 i12 11.0000 1 i12 11.7500 1 i14 8.0000 1 i14 8.5000 1 i14 9.0000 1 i14 9.5000 1 i14 10.0000 1 i14 10.5000 1 i14 11.0000 1 i14 11.5000 1 i13 11.5000 1 i11 12.0000 1 i11 12.5000 1 i11 13.5000 1 i11 14.5000 1 i11 14.7500 1 i11 15.5000 1 i12 13.0000 1 i12 13.7500 1 i12 14.2500 1 i12 15.0000 1 ;i12 15.7500 1 i14 12.0000 1 i14 12.5000 1 i14 13.0000 1 i14 13.5000 1 i14 14.0000 1 i14 14.5000 1 i14 15.0000 1 i14 15.5000 1 i13 15.5000 1 e