Csound Csound-dev Csound-tekno Search About

Re: Looking for drums

Date1999-08-25 03:11
FromHans Mikelson
SubjectRe: Looking for drums
Hi,

Here is a drum machine.  The kick isn't too bad, 808ish.  Watch out for all
the line wraps.  Sorry about the lack of comments.

Bye,
Hans Mikelson

;---------------------------------------------------------------------------
; Coded: February-May 1998 by Hans Mikelson
;---------------------------------------------------------------------------
; ORC
sr=44100
kr=22050
ksmps=2
nchnls=2
zakinit 50, 50
gareverb init 0

; Envelope
       instr    5

idur   =        p3
iamp   =        p4
irate  =        p5
itab1  =        p6
ioutch =        p7

kenv1  oscili   iamp, irate/idur, itab1
       zkw      kenv1, ioutch
       endin

; Drum Machine
instr 30

idur    =     p3
iamp    =     p4
idurtab =     p5
idrumtb =     p6
iacctab =     p7
iamptab =     p8
ispeed  =     p9
isteps  =     p10
ikinch  =     p11
ioutch  =     p12

kstep   init   isteps-1
kspeed  oscili 1, 1/p3, ispeed

loop1:
;     Read table values.
      kdur     table frac((kstep + 1)/isteps)*isteps, idurtab
      kdrnum   table kstep, idrumtb
      kaccnt   table kstep, iacctab
      kamp     table kstep, iamptab
      kaccnt1  table frac((kstep + 1)/isteps)*isteps, iacctab
      kdur1    =     kdur/kspeed          ; Make the step smaller.
      kdclick  linseg 0, .002, 1, i(kdur1)-.004, 1, .002, 0
      kaccin   zkr    ikinch
      kaccnt   =      kaccnt*kaccin
      kaccnt1  =      kaccnt1*kaccin

; Switch between the different drums
      if (kdrnum != 0) kgoto next1
  ;     Noise Blip
        kampenv0   linseg 0, .01/i(kaccnt1), iamp/2, .04/i(kaccnt1), 0, .01,
0
        asig0      rand   kampenv0
        aflt1      butterlp asig0, 400*kaccnt
        aflt2      butterbp asig0, 2000*kaccnt, 400*kaccnt
        aout       =        aflt1*4+aflt2*2
        kgoto  endswitch
next1:
      if (kdrnum != 1) kgoto next2
;       Dumb Drum
        kampenv1   expseg .0001, .01/i(kaccnt1), iamp, .08/i(kaccnt1), .01
        arnd1      rand kampenv1
        afilt      reson arnd1, 500*kaccnt, 50*kaccnt
        aout       balance afilt, arnd1
        kgoto endswitch
next2:
      if (kdrnum != 2) kgoto next3
;       Dumb Bass Drum
        kampenv2   linseg  0, .02, iamp*2,  .5/i(kaccnt1), 0
        kfreqenv   expseg  50,  .05, 200*i(kaccnt1)+.001,   .8, 10
        arnd2      rand    kampenv2
        afilt1     butterbp arnd2, kfreqenv, kfreqenv/32
        aosc1      oscil   kampenv2, kfreqenv, 1
;        afilt2     butterbp arnd2, kfreqenv*1.5, kfreqenv/32*1.5
;        aosc2      oscil   kampenv2, kfreqenv*1.5, 1
        aout       balance afilt+aosc1, arnd2*.5
        kgoto endswitch
next3:
      if (kdrnum != 3) kgoto next4
;       KS Snare
        kampenv3   linseg  0, .002, 1,  i(kdur1)-.022, 1, .02, 0
        kptchenv   linseg  100, .01, 300, .2, 200, .01, 200
        aplk3      pluck   iamp/2, kptchenv, 50, 2, 4, 1/(1+i(kaccnt)), 3
        aout       =        aplk3*kampenv3
        kgoto endswitch

next4:
      if (kdrnum != 4) kgoto next5
;       FM Boink
        kamp40    linseg  0, .002, 1,   i(kdur1)-.004, 1, .002, 0
        kamp41    linseg  0, .01, iamp, i(kdur1)-.06, iamp*.1, .05, 0
        kamp42    linseg  0, .01, 1,  i(kdur1)-.03, 0, .01, 0
        kamp4     =       kamp40*kamp41
        klfo      oscil   1, 8, 1
        aout      foscil  kamp4, 110*kaccnt, 1, 1.5+klfo, kamp42*kaccnt, 1
        kgoto endswitch

next5:
      if (kdrnum != 5) kgoto next6
        ; Sorta Cool Knock Sweep Drum
        kfreqenv51 expseg  800*i(kaccnt1)+.001,  .04, 40, .01, 40
        kfreqenv52 expseg  2000*i(kaccnt1)+.001, .04, 150, .01, 150
        kampenv5   linseg  0, .001, iamp, .1, iamp*.5, .05, 0, .01, 0
        asig   rand    kampenv5
        afilt1 reson   asig, kfreqenv51, kfreqenv51/32
        afilt2 reson   asig, kfreqenv52, kfreqenv52/16
        aout1  balance afilt1, asig
        aout2  balance afilt2, asig
        aout   =       (aout1+aout2)/2
        kgoto endswitch

next6:
      if (kdrnum != 6) kgoto next7
        ; Ring Mod Drum 1
        kampenv6 linseg 0, .01/i(kaccnt1), iamp, .04/i(kaccnt1), 0, .001, 0
        kpchenv6 linseg 100, .01/i(kaccnt1), 400*i(kaccnt1), .04/i(kaccnt1),
100, .001, 100
        asig1  oscil   kampenv6, kpchenv6, 1
        asig2  oscil   kampenv6, kpchenv6*kaccnt, 1
        aout   balance asig1*asig2, asig1
        kgoto endswitch

next7:
      if (kdrnum != 7) kgoto next8
        ; Thunder Bomb
        aop4    init    0
        kae70   linseg  0, .002, iamp, i(kdur1)-.004, iamp, .002, 0
        kae71   linseg  0, .1*i(kaccnt1), 1, .2*i(kdur1)-.1*i(kaccnt1), .8,
.8*i(kdur1), 0
        kae72   linseg  0, .1*i(kaccnt1), 1, .2*i(kdur1)-.1*i(kaccnt1), .8,
.8*i(kdur1), 0
        kae73   linseg  0, .1*i(kaccnt1), 1, .2*i(kdur1)-.1*i(kaccnt1), .8,
.8*i(kdur1), 0
        kae74   linseg  0, .1*i(kaccnt1), 1, .2*i(kdur1)-.1*i(kaccnt1), .8,
.8*i(kdur1), 0
        krnfqc  randh   165*kaccnt1, 200

        aop4    oscil  10*kae74,   3*(1+.8*aop4)*krnfqc, 1
        aop3    oscil  20*kae73,     .5*(1+aop4)*krnfqc, 1
        aop2    oscil  16*kae72,            5.19*krnfqc, 1
        aop1    oscil  2* kae71,.5*(1+aop2+aop3)*krnfqc, 1
        aout   tone    aop1*kae70, 200*kaccnt1

next8:
      if (kdrnum != 8) kgoto endswitch
        ; Sorta Cool Knock Sweep Drum 2
        kfreqenv81 expseg  220*i(kaccnt1)+.001,  .25/i(kaccnt1), 40, .01, 40
        kampenv8   expseg  .01, .001/i(kaccnt1), iamp, .002, iamp*.5, .06,
iamp, .05, iamp*.5, .1, .3*iamp, .1, .05*iamp, .01, .05*iamp
        kdclick8   linseg  0, .002, 1, i(kdur1)-.04, 1, .002, 0
        asig   rand        kampenv8
        aflt   reson       asig, kfreqenv81, 1
        abal   balance     aflt, asig
        aout   =           abal*kdclick8
        kgoto endswitch

endswitch:
;     When the time runs out go to the next step of the sequence and
reinitialize the envelopes.
      timout 0, i(kdur1), cont1
        kstep   = frac((kstep + 1)/isteps)*isteps
        reinit loop1

  cont1:

     zaw    aout*kdclick*kamp, ioutch    ;, aout*kdclick*kamp

endin

;---------------------------------------------------------------------------
; Mixer Section
;---------------------------------------------------------------------------
          instr 190

idur      init  p3
iamp      init  p4
inch      init  p5
ipan      init  p6
ifader    init  p7

asig1     zar    inch           ; Read input channel 1

kfader    oscil  1, 1/idur, ifader
kpanner   oscil  1, 1/idur, ipan

kgl1      =      kfader*sqrt(kpanner)    ; Left gain
kgr1      =      kfader*sqrt(1-kpanner)  ; Right gain

kdclick   linseg  0, .002, iamp, p3-.004, iamp, .002, 0  ; Declick

asigl     =     asig1*kgl1       ; Scale and sum
asigr     =     asig1*kgr1

          outs  kdclick*asigl, kdclick*asigr   ; Output stereo pair

          endin

;---------------------------------------------------------------------------
; Zak Clear
;---------------------------------------------------------------------------
          instr 195

          zacl 0, 50
          zkcl 0, 50

          endin

;SCO

f1  0 8193 10 1              ; Sine
f2  0 1025  7 1  1025 1      ; 1?
f3  0 1025 -7 5  1025 5      ; Speed
f4  0 1025 10 1  0  .333  0  .2  0  .143  0 .111  0   .0909  ; Square ?

f90 0 1025 -7 0  1025 1   ; Ramp, FadeIn, PanRL
f91 0 1025 -7 1  1025 0   ; Saw, FadeOut, PanLR
f92 0 1025 -7 1  1025 1   ; Const 1, PanL
f93 0 1025 -7 .5 1025 .5  ; Const .5, PanC
f94 0 1025 -7 0  1025 0   ; Const 0, PanR
f95 0 1025 -7 .8  513 .2 512 .8   ; PanRLR
f96 0 1025 -7 .2  513 .8 512 .2   ; PanLRL
f97 0 1025 -7 1   1025 .7         ; FadeDown
f98 0 1025 -7 .5  1025 1          ; FadeUp
f99 0 1025 -7 0  513 1 512 1      ; FadeIn & Hold

;---------------------------------------------------------------------------
; Drums
;---------------------------------------------------------------------------
; Envelope
f10  0 1025 -7 1.2 128 1.5 128 1.7 256 1 513 1.3  ; Accent Envelope
;   Sta  Dur    Amp  Rate  Table  OutKCh
i5  0    25.6    1    1     10     1
; Drums :  0=HiHat, 1=Tap, 2=Bass, 3=KS Snare, 4=FMBoink, 5=Sweep,
6=RingMod1
; Beat         1     2     3     4     5     6     7     8     9     10
11    12    13    14    15    16    17
f21  0 32  -2  2     2     2     2     2     2     2     2     2     2     2
2     2     2     2     1     1    ; Duration
f22  0 32  -2  8     8     8     8     8     8     8     8     8     8     8
8     8     8     8     8     8    ; Drum
f23  0 32  -2  1.5   1.1   1.1   .98   .99   1.1   1     1.5   .9    .8    1
1     1     1     1     .8    .8   ; Accent
f24  0 32  -2  1.2   .8    1     1     1     1     1     1.2   1.3   .5    1
1     1     1     1     1     1    ; Amp
f25  0 32  -2  1.2   1     .8    1     1     1     1     1.2   .5    1.3   1
1     1     1     1     1     1    ; Amp
;   Sta  Dur    Amp  DurTab  DrumTab  Accent  AmpTab  Speed  Steps  InKCh
OutCh
i30 0    25.6   8000  21      22       23      24      3     17     1      1
i30 0    25.6   8000  21      22       23      25      3     17     1      2
; Mixer
;    Sta  Dur    Amp  Ch  Pan  Fader
i190 0    25.6   2.0  1   92   92
i190 0    25.6   2.0  2   94   92


; Clear Zak
;     Sta  Dur
i195  0    25.6