Maps an input MIDI velocity number to an output gain factor with a maximum value of 1, modifying the output gain by a dynamic range and a shaping exponent.
Plugin opcode in ampmidid.
The minimum output gain is 1 minus the dynamic range. A shaping exponent of 1 gives a linear response; increasing the exponent produces an increasingly depressed knee in the gain response curve.
_imidivelocity _ -- MIDI velocity number, ranging from 0 through 127.
idynamicrange -- Intended dynamic range of gain, from 0 through 1.
iexponent -- Exponent applied to shape the gain response curve, 1 or greater.
Performance
_kmidivelocity _ -- MIDI velocity number, ranging from 0 through 127.
kdynamicrange -- Intended dynamic range of gain, from 0 through 1.
kexponent -- Exponent applied to shape the gain response curve, 1 or greater.
Maps an input MIDI velocity number to an output gain factor with a maximum value of 1, modifying the output gain by a dynamic range and a shaping exponent. The minimum output gain is 1 minus the dynamic range. A shaping exponent of 1 gives a linear response; increasing the exponent produces an increasingly depressed knee in the gain response curve, according to the equation: \(y = d \; (x/127)^h + 1 - d\), where \(y\) = the gain, \(x\) = the input MIDI velocity (from 0 through 127), \(d\) = the dynamic range (from p through 1), and \(h\) = the shaping exponent (1 or greater). This opcode was suggested by Mauro Giubileo.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform;;;RT audio out, note=p4 and velocity=p5-odac -d --midi-key=4 --midi-velocity-amp=5
;-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o ampmidid.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1massign(0,1);assign all midi to instr. 1instr1sine:iftgenonce0,0,4096,10,1;sine wavehz:i=cpsmidinn(p4)velocity:i=p5; MIDI velocity to signal amplitude.amplitude:i=ampdb(velocity); Gain with compressed dynamic range, soft knee.igain=ampmidicurve(velocity,0.92,3)print(velocity,amplitude,igain)a1=oscili(1,hz,sine)env:a=madsr(0.05,0.1,0.5,0.2)sig:a=a1*env*igainouts(sig,sig)endin</CsInstruments><CsScore>; note velocityi10261100i1+26510e</CsScore></CsoundSynthesizer>
Here is an example of the ampmidicurve opcode. It uses the file ampmidicurve.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform;;;RT audio out, note=p4 and velocity=p5-odac --midi-key=4 --midi-velocity-amp=5
;-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o ampmidid.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1massign0,1;assign all midi to instr. 1instr1isineftgenonce0,0,4096,10,1;sine waveihz=cpsmidinn(p4)ivelocity=p5; MIDI velocity to signal amplitude.iamplitude=ampdb(ivelocity); Gain with compressed dynamic range, soft knee.igainampmidicurveivelocity,.92,3printivelocity,iamplitude,igaina1oscili1,ihz,isineaenvmadsr0.05,0.1,0.5,0.2asig=a1*aenv*igainoutsasig,asigendin</CsInstruments><CsScore>; note velocityi10261100i1+26510e</CsScore></CsoundSynthesizer>