The envelope generated is the range 0 to 1 and may need to be scaled further, depending on the amplitude required. If using 0dbfs = 1, scaling down will probably be required since playing more than one note might result in clipping. If not using 0dbfs, scaling to a large amplitude (e.g. 32000) might be required.
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 xadsr is not suitable for use with MIDI events, use mxadsr instead. The opcode xadsr is identical to adsr except it uses exponential, rather than linear, line segments.
Examples
Here is an example of the xadsr opcode. It uses the file xadsr.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o xadsr.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1instr1iatt=p5idec=p6islev=p7irel=p8kenvxadsriatt,idec,islev,irelkcps=cpspch(p4);frequencyasigvco2kenv*0.8,kcpsoutsasig,asigendin</CsInstruments><CsScore>i1017.00.00011.01.001; short attacki1217.021.5.01.001; long attacki1426.09.00011.1.7; long releasee</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>