max_k

max_k — Local maximum (or minimum) value of an incoming asig signal

Description

max_k outputs the local maximum (or minimum) value of the incoming asig signal, checked in the time interval between ktrig has become true twice.

Syntax

knumkout max_k asig, ktrig, itype

Initialization

itype - itype determinates the behaviour of max_k (see below)

Performance

asig - incoming (input) signal

ktrig - trigger signal

max_k 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 max_k:

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 max_k opcode. It uses the file max_k.csd.

Example 578. Example of the max_k opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<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 2020

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1


instr 1

anoise noise 0.1, 0.1 ; generate some noise
arandom randomi 400, 12000, 4 ; generate random numbers from 400 to 1200 

ktrig metro 3 ; trigger signal

kmin max_k arandom, ktrig, 3 ; minumum value 
kmax max_k arandom, ktrig, 2 ; maximum value 

printk 0.2, kmin
printk 0.2, kmax

anoisehp butterhp anoise, kmin ; hipass filter at kmin frequency
anoiselp butterlp anoise, kmax*0.5 ; lopass filter at kmin/2 frequency

acomp oscil 0.1, 440 ; comparator signal for consistent amplitude

anoisehp balance anoisehp, acomp ; adjusting the volume
anoiselp balance anoiselp, acomp ; adjusting the volume

outs anoisehp, anoiselp

endin

</CsInstruments>
<CsScore>

i1 0 10
e
</CsScore>
</CsoundSynthesizer>


Credits

Written by Gabriel Maldonado.

New in Csound 5 (Previously available only on CsoundAV)

Fixed to agree with documentation in 5.15