peak
Prev | Orchestra Opcodes and Operators | Next

## peak

peak — Maintains the output equal to the highest absolute value received.

## Description

These opcodes maintain the output k-rate variable as the peak absolute level so far received.

## Syntax

    kres peak asig

    kres peak ksig

## Performance

kres -- Output equal to the highest absolute value received so far. This is effectively an input to the opcode as well, since it reads kres in order to decide whether to write something higher into it.

ksig -- k-rate input signal.

asig -- a-rate input signal.

## Examples

Here is an example of the peak opcode. It uses the file peak.csd, and beats.wav.

Example 557. Example of the peak 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
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o peak.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 44100
    ksmps = 1
    nchnls = 1

    ; Instrument #1 - play an audio file.
    instr 1
      ; Capture the highest amplitude in the "beats.wav" file.
      asig soundin "beats.wav"
      kp peak asig

      ; Print out the peak value once per second.
      printk 1, kp

      out asig
    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument #1, the audio file, for three seconds.
    i 1 0 3
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like this:

     i   1 time     0.00002:  4835.00000
     i   1 time     1.00002: 29312.00000
     i   1 time     2.00002: 32767.00000

## Credits

Author: Robin Whittle
Australia
May 1997

Example written by Kevin Conder.

Prev | Up | Next
pdhalfy | Home | peakk