max_k
Prev | Orchestra Opcodes and Operators | Next

## 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 434. 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>

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

    	FLpanel	"This Panel contains VU-meter",300,100
    gk1,gih1 FLslider "VU-meter", 0,1,0,1, -1, 250,30, 30,30
    	FLsetColor2 50, 50, 255,  gih1
    	FLpanel_end
    	FLrun

    ga1 init 0

    instr 1

    kenv	linsegr	0,.5,.7,.5,.5,.2,0
    ifreq	cpsmidi
    a1	poscil	0dbfs*kenv, ifreq, 1
    ga1	=	ga1+a1

    endin

    instr 2

    	outs	ga1, ga1
    ktrig	metro	25					;refresh 25 times per second
    kval	max_k	ga1, ktrig, 1
    	FLsetVal ktrig, kval, gih1
    ga1	=	0

    endin

    </CsInstruments>
    <CsScore>
    f1 0 1024 10 1

    i2 0 3600
    f0 3600

    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

Prev | Up | Next
maxalloc | Home | maxtab