Search code examples
csound

Is there any difference between `xtratim` and overriding p3?


According to reference csound manual, one should use xtratim (or opcodes that implicitly use it e.g. madsr) when writing instruments that respond to MIDI since the duration of the key/note is not know in advance (for live performances).

However, I also noted in an external example that one can override p3 (the score note length) from within the instrument code, merely by assigning to it. (In that example, p3 was set internally to the length of a wav file.) So, is there any difference between doing this and using xtratim?


Solution

  • Yes, xtratim and -r opcodes that have a release segment will trigger that extra time for release when the note turns off. p3 will only be the duration value for the "on" time.

    For example, if you run the following:

    instr S1
      p3 = 2
      asig = oscili(0.25, 440)
      asig *= linsegr(1, .1, 1, 4, 0)
      out(asig, asig)
    endin
    schedule("S1", 0, 0.1)
    
    1. The schedule call sets p3 to 0.1 seconds
    2. The instrument redefines p3 to 2 seconds
    3. The instrument runs for 2 seconds and has a 4 second release time afterwards due to the linsegr release value

    In general, overriding p3 should be used with caution but is good for certain situations like ensuring a minimum amount of time is given to an instrument. Release time from xtratim or -r opcodes is probably more applicable to most use cases.