ivelocity -- MIDI velocity number, ranging from 0 through 127.
idecibels -- Desired dynamic range in decibels.
Performance
kamplitude -- Amplitude.
kvelocity -- MIDI velocity number, ranging from 0 through 127.
Musically map MIDI velocity to peak amplitude within a specified dynamic range in decibels: \(a = (mv + b) ^ 2\), where \(a\) = amplitude, \(v\) = MIDI velocity, \(r = 10 ^ {R / 20}\), \(b = 127 / (126 \sqrt{r}) - 1 / 126\), \(m = (1 - b) / 127\), and \(R\) = specified dynamic range in decibels. See Roger Dannenberg, "The Interpretation of MIDI Velocity", in Georg Essl and Ichiro Fujinaga (Eds.), Proceedings of the 2006 International Computer Music Conference, November 6-11, 2006 (San Francisco: The International Computer Music Association), pp. 193-196.
Examples
Here is an example of the ampmidid opcode. It uses the file ampmidid-modern.csd.
<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=2massign(0,1);assign all midi to instr. 1instr1sine:i=ftgenonce(0,0,4096,10,1);sine wavehz:i=cpsmidinn(p4)velocity:i=p5idb=ampmidid(velocity,20);map to dynamic range of 20 dB.idb+=60;limit range to 60 to 80 decibelsamplitude:i=idb;ampdb(idb) ;loudness in dB to signal amplitudeprint(velocity,idb,amplitude)a1=oscili(amplitude,hz,sine)env:a=madsr(0.05,0.1,0.5,0.2)sig:a=a1*envouts(sig,sig)endin</CsInstruments><CsScore>; note velocityi10261100i1+26510e</CsScore></CsoundSynthesizer>
Here is an example of the ampmidid opcode. It uses the file ampmidid.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=2massign0,1;assign all midi to instr. 1instr1isineftgenonce0,0,4096,10,1;sine waveihz=cpsmidinn(p4)ivelocity=p5idbampmididivelocity,20;map to dynamic range of 20 dB.idb=idb+60;limit range to 60 to 80 decibelsiamplitude=ampdb(idb);loudness in dB to signal amplitudea1osciliiamplitude,ihz,isineaenvmadsr0.05,0.1,0.5,0.2asig=a1*aenvoutsasig,asigendin</CsInstruments><CsScore>; note velocityi10261100i1+26510e</CsScore></CsoundSynthesizer>