;------------------------------------------------------------------------- ; ; Combination Study 2 / Drift Dhikr ; by Dave Seidel (dave at mysterybear dot com) ; ; Copyright 2005, Dave Seidel. Some rights reserved. ; This work is licensed under a Creative Commons "Attribution" License. ; http://creativecommons.org/licenses/by/2.0/ ; ; Tested with canonical Csound version 4.23f12 (c0nsound64.exe) ; on Windows XP. ; ;------------------------------------------------------------------------- ;-o devaudio -W -o DriftDhikr.wav ;------------------------------------------------------------------------- ; globals ;------------------------------------------------------------------------- sr = 44100 kr = 441 ksmps = 100 nchnls = 2 ;------------------------------------------------------------------------- ; global reverb sends ;------------------------------------------------------------------------- gaL init 0 gaR init 0 ;------------------------------------------------------------------------- ; function tables for waveforms ;------------------------------------------------------------------------- giTblSz init 262144 ; sine giFn1 ftgen 1, 0, giTblSz, 10, 1 ;------------------------------------------------------------------------- ; Istvan Varga's UDO version of Sean Costello's reverb ;------------------------------------------------------------------------- opcode SCReverb, aa, aakkjpo setksmps 1 ainL, ainR, kFeedBack, kLPFreq, iSRate, iPitchMod, iSkip xin iSRate = (iSRate <= 0 ? 1 : (sr / iSRate)) if (iSkip != 0) igoto SkipInit ; 8 delay line FDN reverb, with feedback matrix based upon ; physical modeling scattering junction of 8 lossless waveguides ; of equal characteristic impedance. Based on Julius O. Smith III, ; "A New Approach to Digital Reverberation using Closed Waveguide ; Networks," Proceedings of the International Computer Music ; Conference 1985, p. 47-53 (also available as a seperate ; publication from CCRMA), as well as some more recent papers by ; Smith and others. ; ; Coded by Sean Costello, October 1999 afilt1 init 0 afilt2 init 0 afilt3 init 0 afilt4 init 0 afilt5 init 0 afilt6 init 0 afilt7 init 0 afilt8 init 0 ; Delay times chosen to be prime numbers. ; Works with sr=44100 ONLY. If you wish to ; use a different delay time, find some new ; prime numbers that will give roughly the ; same delay times for the new sampling rate. ; Or adjust to taste. idel1 = 2473.000 / (iSRate * 44100) idel2 = 2767.000 / (iSRate * 44100) idel3 = 3217.000 / (iSRate * 44100) idel4 = 3557.000 / (iSRate * 44100) idel5 = 3907.000 / (iSRate * 44100) idel6 = 4127.000 / (iSRate * 44100) idel7 = 2143.000 / (iSRate * 44100) idel8 = 1933.000 / (iSRate * 44100) ; kFeedBack: ; gain of reverb. Adjust empirically ; for desired reverb time. .6 gives ; a good small "live" room sound, .8 ; a small hall, .9 a large hall, ; .99 an enormous stone cavern. ; iPitchMod: ; amount of random pitch modulation ; for the delay lines. 1 is the "normal" ; amount, but this may be too high for ; held pitches such as piano tones. ; Adjust to taste. ; kLPFreq: ; Cutoff frequency of lowpass filters ; in feedback loops of delay lines, ; in Hz. Lower cutoff frequencies results ; in a sound with more high-frequency ; damping. ; k1-k8 are used to add random pitch modulation to the ; delay lines. Helps eliminate metallic overtones ; in the reverb sound. iPitchMod = iPitchMod / iSRate k1 randi 0.0010 * iPitchMod, 3.100 * iSRate, 0.06 k2 randi 0.0011 * iPitchMod, 3.500 * iSRate, 0.90 k3 randi 0.0017 * iPitchMod, 1.110 * iSRate, 0.70 k4 randi 0.0006 * iPitchMod, 3.973 * iSRate, 0.30 k5 randi 0.0010 * iPitchMod, 2.341 * iSRate, 0.63 k6 randi 0.0011 * iPitchMod, 1.897 * iSRate, 0.70 k7 randi 0.0017 * iPitchMod, 0.891 * iSRate, 0.90 k8 randi 0.0006 * iPitchMod, 3.221 * iSRate, 0.44 ; apj is used to calculate "resultant junction pressure" for ; the scattering junction of 8 lossless waveguides ; of equal characteristic impedance. If you wish to ; add more delay lines, simply add them to the following ; equation, and replace the .25 by 2/N, where N is the ; number of delay lines. apj = .25 * (afilt1+afilt2+afilt3+afilt4+afilt5+afilt6+afilt7+afilt8) adum1 delayr 1 adel1 deltap3 idel1 + k1 delayw ainL + apj - afilt1 adum2 delayr 1 adel2 deltap3 idel2 + k2 delayw ainR + apj - afilt2 adum3 delayr 1 adel3 deltap3 idel3 + k3 delayw ainL + apj - afilt3 adum4 delayr 1 adel4 deltap3 idel4 + k4 delayw ainR + apj - afilt4 adum5 delayr 1 adel5 deltap3 idel5 + k5 delayw ainL + apj - afilt5 adum6 delayr 1 adel6 deltap3 idel6 + k6 delayw ainR + apj - afilt6 adum7 delayr 1 adel7 deltap3 idel7 + k7 delayw ainL + apj - afilt7 adum8 delayr 1 adel8 deltap3 idel8 + k8 delayw ainR + apj - afilt8 ; 1st order lowpass filters in feedback ; loops of delay lines. kLPFreq = kLPFreq * iSRate afilt1 tone adel1 * kFeedBack, kLPFreq afilt2 tone adel2 * kFeedBack, kLPFreq afilt3 tone adel3 * kFeedBack, kLPFreq afilt4 tone adel4 * kFeedBack, kLPFreq afilt5 tone adel5 * kFeedBack, kLPFreq afilt6 tone adel6 * kFeedBack, kLPFreq afilt7 tone adel7 * kFeedBack, kLPFreq afilt8 tone adel8 * kFeedBack, kLPFreq ; The outputs of the delay lines are summed ; and sent to the stereo outputs. This could ; easily be modified for a 4 or 8-channel ; sound system. aoutL = 0.35 * (afilt1 + afilt3 + afilt5 + afilt7) aoutR = 0.35 * (afilt2 + afilt4 + afilt6 + afilt8) SkipInit: xout aoutL, aoutR endop ;--------------------------------------------------------------------------- ; global reverb instrument ;--------------------------------------------------------------------------- instr 100 aL, aR SCReverb gaL, gaR, p4, p5, sr/1.5, p6, 0 outs gaL+aL, gaR+aR gaL = 0 gaR = 0 endin ;--------------------------------------------------------------------------------------- ; compute combination tones ;--------------------------------------------------------------------------------------- opcode kGetCombinations, kkkkk, kk kpch1,kpch2 xin kdiff = abs(kpch2-kpch1) kdiff2 = abs((2*kpch2)-kpch1) kdiff3 = abs((3*kpch2)-(2*kpch1)) ksum = kpch1+kpch2 ksum2 = (2*kpch1)+kpch2 xout kdiff,kdiff2,kdiff3,ksum,ksum2 endop ;--------------------------------------------------------------------------------------- ; combination tone chord organ 2 (gliding) ;--------------------------------------------------------------------------------------- instr 3 idur = p3 ; duration iamp = p4/9 ; amplitude ifn = p5 ; function table number (waveform) for dyad ipch1 = p6 ; primary pitch (as a frequency) immm = p7 ; numerator of dyad innn = p8 ; denominator of dyad imm2 = p9 ; numerator of dyad inn2 = p10 ; denominator of dyad ilr = p11 ; 1.0 = left <-> 0.0 = right kpch1 = ipch1 ; primary pitch ipch2a = ipch1*(immm/innn) ; secondary starting pitch (primary * ratio) ipch2b = ipch1*(imm2/inn2) ; secondary ending pitch (primary * ratio) prints "\\n%d:%d -> %d:%d\\n", immm, innn, imm2, inn2 ; glide envelope kpch2 expseg ipch2a, 7, ipch2a, idur-16, ipch2b, 9, ipch2b ; continuous derivation of combination tones kdiff,kdiff2,kdiff3,ksum,ksum2 kGetCombinations kpch1, kpch2 ae linen iamp, 5, idur, 7 ; amplitude envelope ;asig1 poscil ae, kpch1, ifn asig2 poscil ae, kpch2, ifn adiff poscil ae, kdiff, ifn adiff2 poscil ae, kdiff2, ifn adiff3 poscil ae, kdiff3, ifn asum poscil ae, ksum, ifn asum2 poscil ae, ksum2, ifn aout = asig2+adiff+adiff2+adiff3+asum+asum2 gaL = gaL+(aout*ilr) gaR = gaR+(aout*(1-ilr)) endin ;--------------------------------------------------------------------------------------- ; combination tone chord organ 2 (gliding on both pitches) ;--------------------------------------------------------------------------------------- instr 31 idur = p3 ; duration iamp = p4/9 ; amplitude ifn = p5 ; function table number (waveform) for dyad ipch1 = p6 ; primary pitch (as a frequency) immm = p7 ; numerator of dyad innn = p8 ; denominator of dyad imm2 = p9 ; numerator of dyad inn2 = p10 ; denominator of dyad imm3 = p11 ; numerator of dyad inn3 = p12 ; denominator of dyad ilr = p13 ; 1.0 = left <-> 0.0 = right ipch2a = ipch1*(immm/innn) ; secondary starting pitch (primary * ratio) ipch2b = ipch1*(imm2/inn2) ; secondary ending pitch (primary * ratio) ipch3a = ipch1*(immm/innn) ; secondary ending pitch (primary * ratio) ipch3b = ipch1*(imm3/inn3) ; secondary ending pitch (primary * ratio) prints "\\n%d:%d <- %d:%d -> %d:%d\\n", imm3, inn3, immm, innn, imm2, inn2 ; glide envelopes kpch1 expseg ipch2a, 7, ipch2a, idur-16, ipch2b, 9, ipch2b kpch2 expseg ipch3a, 7, ipch3a, idur-16, ipch3b, 9, ipch3b ; continuous derivation of combination tones kdiff,kdiff2,kdiff3,ksum,ksum2 kGetCombinations kpch1, kpch2 ae linen iamp, 5, idur, 7 ; amplitude envelope asig1 poscil ae, kpch1, ifn asig2 poscil ae, kpch2, ifn adiff poscil ae, kdiff, ifn adiff2 poscil ae, kdiff2, ifn adiff3 poscil ae, kdiff3, ifn asum poscil ae, ksum, ifn asum2 poscil ae, ksum2, ifn aout = asig1+asig2+adiff+adiff2+adiff3+asum+asum2 gaL = gaL+(aout*ilr) gaR = gaR+(aout*(1-ilr)) endin ;--------------------------------------------------------------------------- ; score macros ;--------------------------------------------------------------------------- ; 60Hz base pitch #define BASE #60# ; base pitch in specified octave above base #define BOCT(O) #[$BASE.*(2^$O.)]# ; duration of piece #define DURATION #540# ;--------------------------------------------------------------------------- ; score ;--------------------------------------------------------------------------- ; reverb i 100 0 [$DURATION.+3] .79 15360 .3 ; gliders i 3 0 $DURATION. 4000 1 $BOCT.(2) 3 2 2 1 .9 i 3 . . . . $BOCT.(2) 3 2 1 1 .1 i 31 0 $DURATION. 4000 1 $BOCT.(2) 3 2 1 1 2 1 .5 e