The Csound Blog by Jacob Joaquin email jacobjoaquin@gmail.com web www.thumbuki.com/csound/blog (C)2007 Jacob Joaquin Licensed under Creative Commons (see below) 2007.04.10 Adding Zak to the Mix It has been too long since the last Csound Blog. This is why I'm personally excited to announce this newest edition, "Adding Zak to the Mix." Today's topic is how to model a studio mixer in Csound using Robin Whittle's zak opcodes.[1] I will actually be stretching this subject over an unspecified number of blog entries, as I couldn't possibly cover every significant nuance in one write-up. What I'm presenting here today is merely an overview, while in the following issues I will break down everything into its respective modular components. Not only will I cover the design of this zak mixer, I will present new ways in which you can organize your orchestras, along with how to unlock the potential of your patches using control instruments. "...all composers should be as lazy as possible when writing scores." - Max V. Mathews [2] Being a lazy person myself, I'm always trying to find shortcuts || better methods to speed up the process of writing music with Csound, whether it's designing step sequencers that cycle through stored note patterns, hacking perl scripts that generate score code, or taking advantage of under-utilized features of the Csound language. For sometime, I've had a few ideas stirring in the background of my thought processes about how I could utilize the zak opcodes to design a more efficient and speedier work flow within Csound's core syntax, while at the same time improving the production value of future compositions. The opportunity to realize and explore some of these ideas recently presented itself when I was invited to be a guest speaker at Jean-Luc Cohen's Csound class at NYU.[3] Thus, this zak mixer was born. The mixer is a network of instruments that pass streams to each other using the zak opcode system in conjunction with Csound macros. There is a sub-mixer for drums, two auxilary sends for effects, a master mixer, and a series of control instruments. The orchestra is organized in a fashion that creating and patching new instruments into this work flow is quicker and less painful than usual. You can download the flow chart of how everything is wired here: http://www.thumbuki.com/csound/files/images/AddingZakToTheMix.gif But is it just a mixer? At the core of this design is an environment for implementing and organizing a manageable audio/control signal routing system built on top of zak opcodes and macros. For example, parameter control has been consolidated into a few universal control instruments. The following score code demonstrates how instrument 10 can independently modify the values for the pan position of the snare drum, the duration of the reverb in Fx1 and the volume of the master mixer. i10 0 $I 0.4 $cSnarePan i10 0 $I 1.0 $cFx1ReverbTime i10 0 $I 5000 $cMasterAmp I'm getting a little ahead of myself. I promise to explain in greater detail how everything works in the upcoming issues. For now, feel free to modify, explore and study this file. I also recommend reading Hans Mikelson's chapter "Modeling a Multieffects Processor in Csound" in the Csound Book.[4] I want to thank Jean-Luc Cohen and his students for having me as a guest speaker at NYU. I would also like to thank Michael Gogins for hosting the Csound Users Group in his home, and for the tip of using a duration of -1.[5] Best, Jake Permalink http://www.thumbuki.com/20070410/adding-zak-to-the-mix.html References [1] Robin Whittle's Zak Opcodes http://cara.gsu.edu/courses/Csound_Users_Seminar/csound/3.46/CsZak.html [2] Mathews, Max V., The Technology of Computer Music Pg. 62 Cambridge, Massachussetts: The Massachussetts Institute of Technology, 1969-1981 [3] Jean-Luc Cohen http://www.jeanluccohen.com/ [4] Boulanger, Richard C. (Editor) and Mikelson, Hans The Csound Book Ch. 30 Cambridge, Massachussetts: The MIT Press, 2000 [5] Michael Gogins @ ruccas.org http://ruccas.org/wiki.pl?Michael%20Gogins 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 Clear ; instr 10 Instance Parameter Control ; instr 11 Linear Fader ; instr 12 Exponential Fader ; instr 20 Phasor ; instr 200 Synth Bass ; instr 210 Kick Drum ; instr 211 Snare Drum ; instr 212 Hihat ; instr 300 Drum Mixer ; instr 400 Fx1 - Reverb ; instr 410 Fx2 - Delay ; instr 600 Main Mixer ;---- Zak Busses ---- zakinit 100, 100 ; k-rate zak channels # define cPhasorCPS # 1 # # define cPhasorSend # 2 # # define cSynthBassFx1 # 3 # # define cSynthBassFx2 # 4 # # define cKickAmp # 5 # # define cKickPan # 6 # # define cKickFx1 # 7 # # define cKickFx2 # 8 # # define cSnareAmp # 9 # # define cSnarePan # 10 # # define cSnareFx1 # 11 # # define cSnareFx2 # 12 # # define cHihatAmp # 13 # # define cHihatPan # 14 # # define cHihatFx1 # 15 # # define cHihatFx2 # 16 # # define cFx1ReverbTime # 17 # # define cFx1ReverbDecay # 18 # # define cMasterAmp # 19 # # define cMasterSynthAmp # 20 # # define cMasterDrumAmp # 21 # # define cMasterFx1Amp # 22 # # define cMasterFx2Amp # 23 # ; a-rate zak channels # define zSynthBassSend # 1 # # define zKickSend # 2 # # define zSnareSend # 3 # # define zHihatSend # 4 # # define zDrumLeftSend # 5 # # define zDrumRightSend # 6 # # define zFx1Receive # 7 # # define zFx1Send # 8 # # define zFx2Receive # 9 # # define zFx2Send # 10 # # define zFx2Receive # 11 # # define zMixLeft # 12 # # define zMixRight # 13 # ; ---- Zak Clear Range ---- # define zClear # zacl 1, 13 # # define cClear # # ; ---- Zak Clear ---- instr 1 $zClear $cClear endin ; ---- Instance Parameter Control ---- instr 10 ziw p4, p5 endin ; ---- Linear Fader ---- instr 11 idur = p3 ival zir p5 kenv line ival, idur, p4 zkw kenv, p5 endin ; ---- Exponential Fader ---- instr 12 ; This fader assumes the value will never be zero or cross the zero line idur = p3 ival zir p5 kenv expon ival, idur, p4 zkw kenv, p5 endin ; ---- Phasor ---- instr 20 kin zkr $cPhasorCPS k1 phasor kin zkw k1, $cPhasorSend endin ; ---- Synth Bass ---- instr 200 idur = p3 iamp = p4 ipch = cpspch( p5 ) krev zkr $cSynthBassFx1 kfx2 zkr $cSynthBassFx2 kphasor zkr $cPhasorSend ilength = ftlen( 1 ) klfo2 tablei kphasor * ilength, 1 klfo2 = ( klfo2 * .5 ) + .5 klfo3 = 1 - klfo2 klfo oscil 1, 2.5, 1, -1 a1 vco2 1, ipch, 2, 0.2, 0.5, 0.5 a2 vco2 1, ipch * 2^(7/12) + klfo * ipch * .01, 2, 0.15, 0.5, 0.5 amix = ( a1 + a2 ) kenv expon ipch * 16, idur, ipch amix moogladder amix, kenv, 0.5 kamt = 50 + klfo2 * 4000 abp butterbp amix, kamt, kamt * ( .1 + klfo3 * .5 ) amix balance abp, amix aenv linseg 0, 0.01, 1, idur - 0.06, 0, 0.05, 0 amix = amix * aenv zawm amix, $zSynthBassSend zawm amix * krev, $zFx1Receive zawm amix * kfx2, $zFx2Receive endin ; ---- Kick Drum ---- instr 210 idur = p3 iamp = p4 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.8 + aosc * 1.2 ) * kenv4 * iamp zaw amix, $zKickSend endin ; ---- Snare Drum ---- instr 211 idur = p3 idynamic = p4 atri oscil3 1, 111 + idynamic * 5, 2 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, 3000 + idynamic * 3000 anoise butterbr anoise, 4000, 200 kenv3 expseg 2, 0.15, 1, idur - 0.15, 1 anoise = anoise * ( kenv3 - 1 ) amix = aoscmix + ashiftmix + anoise * 4 zaw amix * idynamic, $zSnareSend endin ; ---- Hihat ---- instr 212 idur = p3 idynamic = p4 ifreq = 125 + ( 2 * idynamic ) a1 oscil 1, ifreq * 1, 5 a2 oscil 1, ifreq * 2.333, 5 a3 oscil 1, ifreq * 3.578, 5 a4 oscil 1, ifreq * 5.123, 5 a5 oscil 1, ifreq * 7.632, 5 a6 oscil 1, ifreq * 9.843, 5 amix = a1 + a2 + a3 + a4 + a5 + a6 idecay1 = 0.08 + ( 0.03 * ( 1 - idynamic ) ) kenv1 expseg 1, 0.01, 2, idecay1, 1, idur - idecay1 - 0.01, 1 kenv1 = kenv1 - 1 amix = amix * kenv1 idecay2 = 0.11 + 0.05 * idynamic kenv2 linseg 1, idecay2, 0, idur - idecay2, 0 anoise gauss 1 amix = ( anoise * kenv2 ) + amix * 0.5 amix butterhp amix, 7000 amix butterlp amix, 9000 + idynamic * 3000 zaw amix * idynamic, $zHihatSend endin ; ---- Drum Mixer ---- instr 300 kKickAmp zkr $cKickAmp kKickPan zkr $cKickPan kKickFx1 zkr $cKickFx1 kKickFx2 zkr $cKickFx2 kSnareAmp zkr $cSnareAmp kSnarePan zkr $cSnarePan kSnareFx1 zkr $cSnareFx1 kSnareFx2 zkr $cSnareFx2 kHihatAmp zkr $cHihatAmp kHihatPan zkr $cHihatPan kHihatFx1 zkr $cHihatFx1 kHihatFx2 zkr $cHihatFx2 akick zar $zKickSend asnare zar $zSnareSend ahihat zar $zHihatSend akick = akick * kKickAmp asnare = asnare * kSnareAmp ahihat = ahihat * kHihatAmp aleft = akick * ( 1 - kKickPan ) aright = akick * kKickPan aleft = aleft + ( asnare * ( 1 - kSnarePan ) ) aright = aright + ( asnare * kSnarePan ) aleft = aleft + ( ahihat * ( 1 - kHihatPan ) ) aright = aright + ( ahihat * kHihatPan ) zawm aleft, $zDrumLeftSend zawm aright, $zDrumRightSend afx1 = akick * kKickFx1 + asnare * kSnareFx1 + ahihat * kHihatFx1 afx2 = akick * kKickFx2 + asnare * kSnareFx2 + ahihat * kHihatFx2 zawm afx1, $zFx1Receive zawm afx2, $zFx2Receive endin ; ---- Fx1 - Reverb ---- instr 400 ktime zkr $cFx1ReverbTime kfdecay zkr $cFx1ReverbDecay ain zar $zFx1Receive arev nreverb ain, ktime, kfdecay zawm arev, $zFx1Send endin ; ---- Fx2 - Delay ---- instr 410 idelay = p4 ain zar $zFx2Receive amix delay ain, idelay zaw amix, $zFx2Send endin ; ---- Master Mixer ---- instr 600 idur = p3 kamp zkr $cMasterAmp ksynthAmp zkr $cMasterSynthAmp kdrumAmp zkr $cMasterDrumAmp kFx1Amp zkr $cMasterFx1Amp kFx2Amp zkr $cMasterFx2Amp aSynthBass zar $zSynthBassSend aDrumLeft zar $zDrumLeftSend aDrumRight zar $zDrumRightSend aFx1 zar $zFx1Send aFx2 zar $zFx2Send aleft = aSynthBass * ksynthAmp + aDrumLeft * kdrumAmp + aFx1 * kFx1Amp aright = aSynthBass * ksynthAmp + aDrumRight * kdrumAmp + aFx1 * kFx1Amp aleft = aleft + aFx2 * kFx2Amp aright = aright + aFx2 * kFx2Amp outs aleft * kamp, aright * kamp endin ; ---- Control Parameters ---- # define cPhasorCPS # 1 # # define cPhasorSend # 2 # # define cSynthBassFx1 # 3 # # define cSynthBassFx2 # 4 # # define cKickAmp # 5 # # define cKickPan # 6 # # define cKickFx1 # 7 # # define cKickFx2 # 8 # # define cSnareAmp # 9 # # define cSnarePan # 10 # # define cSnareFx1 # 11 # # define cSnareFx2 # 12 # # define cHihatAmp # 13 # # define cHihatPan # 14 # # define cHihatFx1 # 15 # # define cHihatFx2 # 16 # # define cFx1ReverbTime # 17 # # define cFx1ReverbDecay # 18 # # define cMasterAmp # 19 # # define cMasterSynthAmp # 20 # # define cMasterDrumAmp # 21 # # define cMasterFx1Amp # 22 # # define cMasterFx2Amp # 23 # # define end # 16 # # define I # 0.001 # f1 0 65536 10 1 f2 0 8192 -7 -1 4096 1 4096 -1 f3 0 8192 -7 -1 8192 1 f5 0 8192 -7 1 200 1 0 -1 7912 -1 # define tempo # 83 # t 0 $tempo ; ---- Init Parameters ---- i10 0 $I 0.333 $cPhasorCPS i10 0 $I 0.01 $cSynthBassFx1 i10 0 $I 0.5 $cSynthBassFx2 i10 0 $I 6 $cKickAmp i10 0 $I 0.5 $cKickPan i10 0 $I 0 $cKickFx1 i10 0 $I 0 $cKickFx2 i10 0 $I 2 $cSnareAmp i10 0 $I 0.4 $cSnarePan i10 0 $I 0.3 $cSnareFx1 i10 0 $I 0.5 $cSnareFx2 i10 0 $I 2 $cHihatAmp i10 0 $I 0.7 $cHihatPan i10 0 $I 0.2 $cHihatFx1 i10 0 $I 0.0 $cHihatFx2 i10 0 $I 1.0 $cFx1ReverbTime i10 0 $I 0.5 $cFx1ReverbDecay i10 0 $I 5000 $cMasterAmp i10 0 $I 1.2 $cMasterSynthAmp i10 0 $I 1.0 $cMasterDrumAmp i10 0 $I 0.333 $cMasterFx1Amp i10 0 $I 0.25 $cMasterFx2Amp ; ---- Running Instruments ---- i1 0 -1 i20 0 -1 i300 0 -1 i400 0 -1 i410 0 -1 [60 / $tempo * 0.5] i600 0 -1 ; ---- Fader Controlled Snare Reverb ---- i11 4 4 0 $cSnareFx1 i11 10 4 0.3 $cSnareFx1 ; ---- Fader Controlled Bass Reverb ---- i12 4 4 0.75 $cSynthBassFx1 i12 10 4 0.01 $cSynthBassFx1 ; ---- Synth Bass Notes ---- i200 0 .25 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 8.00 i200 + . 1 6.00 i200 + . 1 7.00 i200 + . 1 7.07 i200 + . 1 7.02 i200 + . 1 7.03 i200 14 .25 .8 8.00 i200 14 .5 .5 7.00 i200 14 1 1 6.00 ; ---- Drums ---- i212 0.0000 1 0.8000 i212 0.5000 1 0.6667 i212 1.0000 1 0.8000 i212 1.5000 1 0.6667 i212 2.0000 1 0.8000 i212 2.5000 1 0.6667 i212 2.7500 1 0.8000 i212 2.8750 1 0.8000 i212 3.0000 1 0.8000 i212 3.2500 1 0.8667 i212 3.5000 1 0.6667 i211 0.2500 1 0.5333 i211 1.0000 1 0.5333 i211 1.7500 1 0.8000 i211 2.2500 1 0.5333 i211 3.0000 1 0.8000 i211 3.7500 1 0.4000 i210 0.5000 1 0.5333 i210 1.2500 1 0.5333 i210 2.5000 1 0.5333 i210 3.2500 1 0.5333 i10 0 $I 0.6 $cHihatPan i10 3 $I 0.4 $cHihatPan i212 4.0000 1 0.8000 i212 4.5000 1 0.6667 i212 5.0000 1 0.8000 i212 5.5000 1 0.6667 i212 6.0000 1 0.8000 i212 6.5000 1 0.6667 i212 7.0000 1 0.8000 i212 7.2500 1 0.8000 i212 7.3750 1 1.0000 i212 7.6250 1 0.6667 i212 7.7500 1 0.8000 i212 7.8750 1 0.6000 i211 4.2500 1 1.0000 i211 5.0000 1 0.8000 i211 5.7500 1 0.5333 i211 6.2500 1 0.5333 i211 7.0000 1 0.6667 i211 7.5000 1 0.8000 i211 7.7500 1 0.8667 i210 4.0000 1 0.8000 i210 4.5000 1 0.5333 i210 5.2500 1 0.5333 i210 6.5000 1 0.5333 i210 7.2500 1 0.8000 i10 4 $I 0.6 $cHihatPan i10 7 $I 0.4 $cHihatPan i10 7.5 $I 0.9 $cHihatPan i10 7.7 $I 0.1 $cHihatPan i212 8.0000 1 0.8000 i212 8.5000 1 0.6667 i212 9.0000 1 0.8000 i212 9.5000 1 0.6667 i212 10.0000 1 0.8000 i212 10.5000 1 0.6667 i212 10.7500 1 0.8000 i212 10.8750 1 0.8000 i212 11.0000 1 0.8000 i212 11.2500 1 0.8667 i212 11.5000 1 0.6667 i211 8.2500 1 0.5333 i211 9.0000 1 0.5333 i211 9.7500 1 0.8000 i211 10.2500 1 0.5333 i211 11.0000 1 0.8000 i211 11.7500 1 0.4000 i210 8.5000 1 0.5333 i210 9.2500 1 0.5333 i210 10.5000 1 0.5333 i210 11.2500 1 0.5333 i10 8 $I 0.6 $cHihatPan i10 11 $I 0.25 $cHihatPan i10 11.5 $I 0.45 $cHihatPan i212 12.0000 1 0.8000 i212 12.5000 1 0.6667 i212 13.0000 1 0.8000 i212 13.5000 1 0.6667 i212 14.0000 1 0.8000 i212 14.5000 1 0.6667 i212 15.0000 1 0.8000 i212 15.5000 1 0.6667 i211 12.2500 1 1.0000 i211 13.0000 1 0.8000 i211 13.7500 1 0.5333 i211 14.2500 1 0.5333 i211 15.0000 1 0.6667 i210 12.0000 1 0.8000 i210 12.5000 1 0.5333 i210 13.2500 1 0.5333 i210 14.5000 1 0.8000 i210 15.0000 1 0.5333 i10 12 $I 0.6 $cHihatPan i10 15 $I 0.7 $cHihatPan e $end