Local maximum (or minimum) value of an incoming asig signal, checked in the time interval between ktrig has become true twice.
Note
Up to Csound 6, this opcode was called max_k.
Syntax
knumkout=maxk(asig,ktrig,itype)
knumkoutmax_kasig,ktrig,itype
Initialization
itype - itype determinates the behaviour of maxk (see below)
Performance
asig - incoming (input) signal
ktrig - trigger signal
maxk outputs the local maximum (or minimum) value of the incoming asig signal, checked in the time interval between ktrig has become true twice. itype determinates the behaviour of maxk:
1 - absolute maximum (sign of negative values is changed to positive before evaluation).
2 - actual maximum.
3 - actual minimum.
4 - calculate average value of asig in the time interval since the last trigger.
This opcode can be useful in several situations, for example to implement a vu-meter.
Examples
Here is an example of the maxk opcode. It uses the file maxk.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;-Ma ;;;realtime audio out and midi in (on all inputs);-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o max_k.wav -W ;;; for file output any platform</CsOptions><CsInstruments>; by Stefano Cucchi 2020sr=44100ksmps=32nchnls=20dbfs=1instr1Noise:a=noise(0.1,0.1); generate some noiseRandom:a=randomi(400,12000,4); generate random numbers from 400 to 1200 trig:k=metro(3); trigger signalMin:k=maxk(Random,trig,3); minumum value Max:k=maxk(Random,trig,2); maximum value printk(0.2,Min)printk(0.2,Max)noisehp:a=butterhp(Noise,Min); hipass filter at kmin frequencynoiselp:a=butterlp(Noise,Max*0.5); lopass filter at kmin/2 frequencycomp:a=poscil(0.1,440); comparator signal for consistent amplitudenoisehp=balance(noisehp,comp); adjusting the volumenoiselp=balance(noiselp,comp); adjusting the volumeout(noisehp,noiselp)endin</CsInstruments><CsScore>i1010e</CsScore></CsoundSynthesizer>
Here is an example of the max_k opcode. It uses the file max_k.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;-Ma ;;;realtime audio out and midi in (on all inputs);-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o max_k.wav -W ;;; for file output any platform</CsOptions><CsInstruments>; by Stefano Cucchi 2020sr=44100ksmps=32nchnls=20dbfs=1instr1anoisenoise0.1,0.1; generate some noisearandomrandomi400,12000,4; generate random numbers from 400 to 1200 ktrigmetro3; trigger signalkminmax_karandom,ktrig,3; minumum value kmaxmax_karandom,ktrig,2; maximum value printk0.2,kminprintk0.2,kmaxanoisehpbutterhpanoise,kmin; hipass filter at kmin frequencyanoiselpbutterlpanoise,kmax*0.5; lopass filter at kmin/2 frequencyacomposcil0.1,440; comparator signal for consistent amplitudeanoisehpbalanceanoisehp,acomp; adjusting the volumeanoiselpbalanceanoiselp,acomp; adjusting the volumeoutsanoisehp,anoiselpendin</CsInstruments><CsScore>i1010e</CsScore></CsoundSynthesizer>