idel (optional, default=0) -- period of zero before the envelope starts
ireltim (optional, default=-1) -- Control release time after receiving a MIDI noteoff event. If less than zero, the longest release time given in the current instrument is used. If zero or more, the given value will be used for release time. Its default value is -1. (New in Csound 3.59 - not yet properly tested)
Performance
The envelope is in the range 0 to 1 and may need to be scaled further. The envelope may be described as:
Picture of an exponential ADSR envelope.
The length of the sustain is calculated from the length of the note. This means adsr is not suitable for use with MIDI events. The opcode madsr uses the linsegr mechanism, and so can be used in MIDI applications. The opcode mxadsr is identical to madsr except it uses exponential, rather than linear, line segments.
You can use other pre-made envelopes which start a release segment upon receiving a note off message, like linsegr and expsegr, or you can construct more complex envelopes using xtratim and release. Note that you do not need to use xtratim if you are using mxadsr, since the time is extended automatically.
mxadsr is new in Csound version 3.51.
Examples
Here is an example of the mxadsr opcode. It uses the file mxadsr.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac -m0 --midi-key=4 --midi-velocity-amp=5 ; treat p4 and p5 as midi data; For Non-realtime ouput leave only the line below:; -o mxadsr-2.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1; by Menno Knevel - 2021instr1; use score and treat p4 and p5 as midi dataicps=cpsmidinn(p4); take midi note (p4) from scoreivelocampmididp5,92; take velocity (p5) from score; att, dec, lvl, releasekenvmxadsr.001,.2,1,p6prints"duration of note (%ds) + release (%2.1fs)\\n",p3,p6; asigvco2iveloc,icpsasigbutlpasig,2000outsasig*kenv,asig*kenvendin</CsInstruments><CsScore>; note vel release si10162600i12162800i141621000i16158500si11162600i13162801i151621003i17158505e</CsScore></CsoundSynthesizer>
Here is an example for the adsr-group, comparing the different adsr opcodes. It uses the file adsr-group.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o adsr-group.wav -W ;;; for file output any platform</CsOptions><CsInstruments>; by Menno Knevel - 2021sr=44100ksmps=32nchnls=20dbfs=1; both amplitude and filter use same ADSR curves instr1kenvadsr.01,.5,.5,p4; linear envelope asigvco2kenv,110; A+D+S+R = p3 asigrezzyasig,500+(kenv*1000),10; same curve but scaled outsasig,asigendininstr2; midi behavior kenvmadsr.01,.5,.5,p4; linear envelopeasigvco2kenv,110; A+D+S = p3, then go into Release stage asigrezzyasig,500+(kenv*1000),10; same curve but scaled outsasig,asigendininstr3kenvxadsr.01,.5,.5,p4; exponential envelopeasigvco2kenv,110; A+D+S+R = p3 asigrezzyasig,500+(kenv*1000),10; same curve but scaled outsasig,asigendininstr4; midi behavior kenvmxadsr.01,.5,.5,p4; exponential envelopeasigvco2kenv,110; A+D+S = p3, then go into Release stage asigrezzyasig,500+(kenv*1000),10; same curve but scaled outsasig,asigendin</CsInstruments><CsScore>si112.01; same notes for everyone!i15..5i19.1.5si212.01i25..5i29.1.5si312.01i35..5i39.1.5si412.01i45..5i49.1.5e</CsScore></CsoundSynthesizer>