sound-synthesiscsound

How to include durations in an instrument definition in Csound


Using the function oscil, I define an oscillator bank with given frequencies and amplitudes:

instr 1
    a1 oscil .3, 110
        outs a1,a1
    a2 oscil .2, 220
        outs a2,a2
    a3 oscil .1, 330
        outs a3,a3
endin

I know that I can set the duration in the orchestra section. But how can I give different durations to the different oscillations? Can I do this in the instrument definition? Because I want to be able to call the instrument (3 oscillators) with one line in the orchestra:

;instr start duration
i 1 0 ;duration of oscils defined under instr 1
e

Solution

  • Opcode instances within an instrument instance all share the same processing context (i.e., p3/duration). There are a few different strategies one could use to get different durations here:

    1. Use multiple instrument instances have one oscillator per instrument. This is probably the most flexible, but most verbose.
    2. Use some form of envelope and multiply that with the output of each oscillator. For example:

      instr 1
        p3 = 4
        a1 oscil .3, 110
        aenv1 linseg 1, 3, 1, 0.01, 0, 0.99, 0 
        a1 *= aenv1
        outs a1,a1
        ...
      endin
      

    In #2, the duration is set by the instrument. The linseg is used as an envelope and the durations written in. One could then use multiple linseg/oscil pairs and hand write the durations for each part in.