## bpf

bpf — Break point function with linear interpolation

## Description

Break-point function with linear interpolation. Useful when defining a table with GEN27 and scaling the x value would be overkill.

## Syntax

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

## 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 96. Example of the bpf opcode.

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

ksmps = 128
nchnls = 2

instr 1
kx line -1, p3, 2.5

ky bpf kx,        \
0,    0,   \
1.01, 10,  \
2,    0.5, \
2.5,  -1

; the same expressed as a table (notice that we need to scale and
; limit kx). It gets even more complicated with breakpoints with
; negative x
itab ftgenonce 0, 0, 1000, -27,  \
0, 0,    \
101, 10,   \
200, 0.5,  \
250, -1,   \
1000, -1

ky2 tablei limit(kx, 0, 2.5)*100, itab

printks "kx: %f   ky: %f   ky2: %f \n", 1/kr, kx, ky, ky2

endin

</CsInstruments>
<CsScore>
i 1 0 2

</CsScore>
</CsoundSynthesizer>
```