Wednesday, June 8, 2011

zsnd-core

Copperbox revision 2445.

Various updates to the Inst / orchestra code. I've recreated a more substantial example from the Csound demos (the Zanadu FM synthesizer) which revealed some problems. Some I've fixed - allowing the int pretty printer to print negative numbers and printing floats in decimal notation, but others are more pernicious. As  a quick work around I've added a parens combinator to draw parens in the output code. This could be achieved with a proper unparser for arithmetic expressions that adds parens automatically, but I'm not minded to write one at the moment. The other problem is I seem need transparent casts in the Haskell code:
inst3 :: Inst
inst3 = runInstBuilder 3 $ do 
    ishift        <- ivar 0.00666667
    ipch          <- ivar (cpspch $ pfield 5)
    ioct          <- ivar (octpch $ pfield 5)
    (kadsr::Kr)   <- linseg 0 (pfield 3 / 3) 1.0 
                              [ ((pfield 3 / 3), 1.0), ((pfield 3 / 3), 0)]
    (kmodi::Kr)   <- linseg 0 (pfield 3 / 3) 5 
                              [ ((pfield 3 / 3), 3), ((pfield 3 / 3), 0)]
    (kmodr::Kr)   <- linseg (pfield 6) (pfield 3) (pfield 7) [] 
    a1            <- avar $ castAR $ kmodi*(parens ((kmodr-1)/kmodr))/2
    a1ndx         <- avar $ abs ((a1 * 2) / 20)
    a2            <- avar $ castAR $ kmodi*(parens ((kmodr+1)/kmodr))/2
    a3            <- tablei_ a1ndx 3 1 0 0
    (ao1::Ar)     <- oscil a1 ipch 2
    a4            <- avar $ exp((-0.5) * a3 + ao1)
    ao2           <- oscil (a2 * castAR ipch) ipch 2
    (aoutl::Ar)   <- oscil (1000*(castAR kadsr)*a4) 
                           (ao2 + castAR (cpsoct(ioct+ishift))) 1
    (aoutr::Ar)   <- oscil (1000*(castAR kadsr)*a4) 
                           (ao2 + castAR (cpsoct(ioct-ishift))) 1
    outs [aoutl, aoutr]


I think it will be a good idea to allow instrument definitions in native Csound to be combined with scores in Haskell. Whilst embedding the instrument language in Haskell was an interesting technical challenge, instruments are generally going to be easier to define with Csound rather than Haskell.

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.