Monday, July 18, 2011

fm-gong

Here's a transliteration of the fm-gong from the CLM distribution:

Orch:
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

;
; This is fm-gong written by Paul Weineke and distributed with
; CLM (Common Lisp Music). The CLM original is in the file 
; fmex.ins. 
;


instr 1
  isinetbl      = 1
  idur          = p3
  iamp          = p4
  ifreq         = p5
  imod1fq       = ifreq * 1.16
  imod2fq       = ifreq * 3.14
  imod3fq       = ifreq * 1.005 
  indx1a        = .01 * imod1fq
  indx1b        = .30 * imod1fq
  indx1scaler   = indx1b - indx1a
  indx2a        = .01 * imod2fq
  indx2b        = .38 * imod2fq
  indx2scaler   = indx2b - indx2a
  indx3a        = .01 * imod3fq
  indx3b        = .50 * imod3fq
  indx3scaler   = indx3b - indx3a  


  ; mod1 envelope (CLM fmup)
  kmod1env  linseg  0, idur*0.75, 1, idur*.23, 1, idur*.02, 0

  ; mod2 envelope (CLM fmdwn)
  kmod2env  linseg  0, idur*.02, 1, idur*.98, 0

  ; mod3 envelope (CLM rise)
  kmod3env  linseg  0, idur*.15, 0.3, idur*.15, 1, idur*.45, 0.5, idur*.25, 0

  ; amp envelope
  kampenv   expseg .01, .002, 1, idur-.002, .01

  ; modulator1
  amod1phs  phasor  imod1fq
  amod1sig  tablei  amod1phs, isinetbl, 1, 0, 1

  amod1sig  = (indx1a + indx1scaler * kmod1env) * amod1sig

  ; modulator2
  amod2phs  phasor  imod2fq
  amod2sig  tablei  amod2phs, isinetbl, 1, 0, 1

  amod2sig  = (indx2a + indx2scaler * kmod2env) * amod2sig

  ; modulator3
  amod3phs  phasor  imod3fq
  amod3sig  tablei  amod3phs, isinetbl, 1, 0, 1

  amod3sig  = (indx3b + indx3scaler * kmod3env) * amod3sig


  ; carrier
  acarrphs  phasor  ifreq + amod1sig + amod2sig + amod3sig
  acarrsig  tablei  acarrphs, isinetbl, 1, 0, 1


            out iamp * kampenv * acarrsig


endin

Score:
; Table #1: sinewave
f 1 0 1024 10 1

; #   st   drn  amp    freq
i 1   0    3.0  20000  261.61



It was a lot easier to make this one than the fm-drum.

fm-drum

Vis the previous post, the code is a translation to Csound of Jan Mattox's fm drum that is distributed with CLM (Common Lisp Music).

The "low" drum seems sonically pretty close to the original, the "high" drum sounds somewhat different, though I can't work out why.

It turned out to be a lot of effort porting from CLM (which I didn't know at all) to Csound (which I clearly didn't know that well...), hence I haven't updated Copperbox recently. Developing instruments does seem to need a lot of domain knowledge which is perhaps not easy to acquire, certainly if you view instrument building as a "programming" exercise. Maybe it is easier for electronic engineers.

fm-drum

Orch:
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

;
; This is fm-drum written by Jan Mattox and distributed with
; CLM (Common Lisp Music). The CLM original is in the file 
; fmex.ins. 
;
; Note - the low drum is pretty close to the CLM original, but the 
; high drum is some way off.
;


instr 1
  isinetbl      = 1
  idur          = p3
  iamp          = p4
  ifreq         = p5
  iindx         = p6
  ihigh         = p7
  inoiseamp     = 1000.0
  icasrat       = (ihigh > 0 ? 8.525 : 3.515)
  imodrat       = (ihigh > 0 ? 3.414 : 1.414)
  iamprise      = 0.015
  iamp1decay    = (idur < 0.18 ? 0.5 * idur : 0.18)
  iamp2decay    = idur - (iamprise + iamp1decay)
  icascadehz    = ifreq * icasrat
  imodhz        = ifreq * imodrat
  icarrhz       = ifreq
  idevscaler    = 7000
  icascscaler   = iindx * icascadehz 
  imodscaler    = iindx * imodhz
  iglsscaler    = (ihigh > 0 ? 66.0 : 0.0)

  

  ; modulator indices
  kindxenv    transeg .01, .015, 2,  1, .085, -1, 0.333,  idur-.10, -1, .012

  ; noise envelope does not decay to zero...
  ; In CLM there is a minor difference for high and low but it 
  ; seems to do little in the generated waveform.
  knoiseenv   expseg  .01, .015, 1, .005, 1, .010, .1, .040, .002, idur-.070, 0.01

  ; amplitude envelope...
  kampenv     transeg .01, iamprise, 1, 1.0, iamp1decay, 2, .75, iamp2decay, -8, .001


  ; gls envelope
  kgls        linseg 0, idur*0.25, 0, idur*.5, 1, idur*.25, 1

  ; deviation
  adev1     rand inoiseamp
  adevsig   = idevscaler * knoiseenv * adev1
  adevsig   = (icasrat * iglsscaler * kgls) + adevsig 

  ; cacasade 
  acascphs  phasor  icascadehz + adevsig
  acascsig  tablei  acascphs, isinetbl, 1, 0, 1

  acascsig  = icascscaler * kindxenv * acascsig 
  acascsig  = (imodrat * iglsscaler * kgls) + acascsig

  ; modulator
  amodphs   phasor  imodhz + acascsig
  amodsig   tablei  amodphs, isinetbl, 1, 0, 1

  amodsig   = imodscaler * kindxenv * amodsig
  amodsig   = (iglsscaler * kgls) + amodsig

  ; carrier
  acarrphs  phasor  icarrhz + amodsig
  acarrsig  tablei  acarrphs, isinetbl, 1, 0, 1
  
            out iamp * acarrsig * kampenv

endin


Score:
; Table #1: sinewave
f 1 0 1024 10 1

; #   st   drn  amp    hz  ix   hi
i 1   0    1.5  20000  55  5    0
i 1   2    1.5  20000  66  4    1

Saturday, July 9, 2011

zsnd-core

Copperbox revision 2492.

I've added the zak opcodes and fixed a couple of bugs in the score generation code.

Friday, July 8, 2011

zsnd-core

Copperbox revision 2491.

I've changed the Score language so instrument parameters are CsValues - this means they can be Ints or Doubles. It also means they can be Strings, though I don't know that there is a need for this. Maybe I'll have to restrict to just Int - Double at some point.

zsnd

Copperbox revision 2490.

Updates fleshing out the monadic layer of the new Inst language so it can handle the Xanadu instrument. Tidying up some code in ZSnd-Basic.

Thursday, July 7, 2011

zsnd-core

Copperbox revision 2488.

I've re-implemented the instrument language, no longer is it based on Click. The new version is significantly lower level, but it can manage control flow via labels and goto - not handling control flow was a significant deficiency of the Click version and the reason for its scrapping.

Quite a few of the details still need to be worked out in the monadic layer, though I've updated all the opcodes which is a significant effort and the simple demo instrument works.


Revision 2489 - deleted old files from the Click version.

Blog Archive

About Me

My photo
Disambiguating biog as there are a few Stephen Tetley's in the world. I'm neither a cage fighter or yachtsman. I studied Fine Art in the nineties (foundation Bradford 1992, degree Cheltenham 1992 - 95) then Computing part-time at Leeds Met graduating in 2003. I'm the Stephen Tetley on Haskell Cafe and Stackoverflow.