bpf
Prev | Orchestra Opcodes and Operators | Next

## bpf

bpf — Break point function with linear interpolation

## Description

Plugin opcode in emugens.

Break-point function with linear interpolation.

## Syntax

    ky bpf kx, kx1, ky1, kx2, ..., kxn, kyn

    iy bpf ix, ix1, iy1, ix2, ..., ixn, iyn

    kys[] bpf kxs[], kx1, ky1, kx2, ..., kxn, kyn

    iys[] bpf ixs[], ix1, iy1, ix2, ..., ixn, iyn

## Performance

kx -- Input value

kxn, kyn -- Defines a breakpoint. Can be changed at krate, but all kxs must be sorted

The points (kx1, ky1), (kx2, ky2), etc, define a linearly interpolated function. This function is evaluated at point kx. This function extends to both -inf and +inf, so if kx < kx1 then ky = ky1 and the same holds true the other end.

These are equivalent:

              ky bpf kx, 0, 0, 0.5, 10, 1.02, 200

              itab ftgenonce 0, 0, -27, 0, 0, 50, 10, 102, 200
              ky = tablei(limit(kx, 0, 1.02)*100, itab)

| Note
x values need to be sorted. Both x and y values can change but x values must stay sorted.

## Examples

Here is an example of the bpf opcode. It uses the file bpf.csd.

Example 99. Example of the bpf opcode.

    <CsoundSynthesizer>
    <CsOptions>
    </CsOptions>
    <CsInstruments>

    ; Example for opcode bpf

    /*

      bpf stands for Break Point Function

      Given an x value and a series of pairs (x, y), it returns
      the corresponding y value in the linear curve defined by the
      pairs

      It works both at i- and k- time

      ky    bpf kx,    kx0, ky0, kx1, ky1, kx2, ky2, ...
      kys[] bpf kxs[], kx0, ky0, kx1, ky1, kx2, ky2, ...

      NB: x values must be ordered (kx0 < kx1 < kx2 etc)

      See also: bpfcos, linlin, lincos

    */

    ksmps = 64
    nchnls = 2

    instr 1
      kx line -1, p3, 2.5
      ky bpf kx,        \
             0,    0,   \
             1.01, 10,  \
             2,    0.5, \
             2.5,  -1
      printks "kx: %f   ky: %f \n", 0.1, kx, ky
    endin

    instr 2
      ; test i-time
      ix = 1.2
      iy bpf ix, 0,0, 0.5,5, 1,10, 1.5,15, 2,20, 2.5,25, 3,30
      print iy
      turnoff
    endin

    instr 3
      ; bpf also works with arrays
      kx[] fillarray 0, 0.15, 0.25, 0.35, 0.45, 0.55, 0.6
      ky[] bpf kx, 0,0, 0.1,10, 0.2,20, 0.3,30, 0.4,40, 0.5,50
      printarray ky, 1, "", "ky="
      turnoff
    endin

    </CsInstruments>
    <CsScore>
    i 1 1 3
    i 2 0 -1
    i 3 0 -1

    </CsScore>
    </CsoundSynthesizer>

## See Also

bpfcos, linlin xyscale, scale, ntrpol,

## Credits

By: Eduardo Moguillansky 2017

Prev | Up | Next
birnd | Home | bpfcos