cmp

cmp — Compares audio signals or arrays

Description

Plugin opcode in emugens.

Compares audio signals or arrays, sample by sample or value by value All comparison operations are possible: `< `<=, >, >=, ==, !=

An audio signal can be compared against another audio signal, or against a scalar (i- or k-value).

aOut cmp aL, ">", aR
aOut cmp aIn, ">=", 0.5
aOut cmp aIn, "`<=", kthreshold
      

An array can be compared against another array, against a scalar, or checked to be within the range of two scalars. All operations are available for i- and k- arrays

        kOut[] cmp kIn[], ">=", kx
        kOut[] cmp kA[], "==", kB[]
        kOut[] cmp 0.5, "`<", kIn[], "`<=", 1
      

Syntax

aout cmp a1, S_operator, a2
aout cmp a1, S_operator, kb
kOut[] cmp kA[], S_operator, kb
kOut[] cmp kA[], S_operator, kB[]
kOut[] cmp k1, S_operator1, kIn[], S_operator2, k2

Initialization

S_operator Math operator, one of ">", ">=", "`<", "`<=", "=="

Performance

a1 / a2 -- Input signals

kb / ib -- Scalar term

kA[] / kB[] -- array inputs

Some example usages:

aout cmp aL, ">", aR      ; aout = aL > aR for every sample
aout cmp aL, ">=", aR
aout cmp aL, "`<", aR
aout cmp aL, "`<=", aR
aout cmp aL, "==", aR
kOut[] cmp kA, ">=", kb   ; kA is an array
      

Examples

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

Example 149. Example of the cmp opcode.

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

sr = 44100
ksmps = 128
nchnls = 5
0dbfs = 1.0

; this is the example file for 'cmp'

/*

cmp

compare audio or arrays, value by value

Audio:
  * compare audio signals, sample by sample, against another signal or scalar
  * compara audio singal, sample by sample, within a range:
    aout cmp klo, "<", ain, "<=", khi

Arrays:
  * compare arrays value by value or against a scalar
  * compare array value by value within a range:
    kout[] = klo < kin[] <= khi   ->   kout[] cmp klo, "<", kin[], "<=", khi

aout cmp a1, Sop, a2                 : aout cmp ain, "<", acmp
aout cmp a1, Sop, kval               : aout cmp ain, ">=", 0.1
kout[] cmp k1[], Sop, k2[]           : kout[] cmp kxs, "<", kys
iout[] cmp i1[], Sop, i2[]           : iout[] cmp ixs, "<", iys
kout[] cmp k1[], Sop, k              : kout[] cmp kxs, "<", 0.5
iout[] cmp i1[], Sop, i              : iout[] cmp ixs, "<", 0.5
kout[] cmp klo, Sop, kx[], Sop, khi  : kout[] cmp 0, "<", kxs, "<=", 1
iout[] cmp ilo, Sop, ix[], Sop, ihi  : iout[] cmp 0, "<", ixs, "<=", 1

TODO: implement array operations for multidim. arrays
      (at the time, array operations work only for 1D-arrays)

*/

; for audio operations, render this to a soundfile and open in an editor
; to check the results

instr 1
  a0 linseg 0, p3, 1
  a1 linseg 1, p3, 0
  aout1 cmp a0, "<", a1
  aout2 cmp a0, "<=", 0.5
  aout3 cmp a0, ">", 0.5
  outch 1, a0
  outch 2, a1
  outch 3, aout1
  outch 4, aout2
  outch 5, aout3
endin

instr 4
  ; cmp with arrays
  ixs[] fillarray 0, 1, 2, 3, 4, 5
  iys[] cmp ixs, ">=", 3
  printarray iys, "", "instr 4, iys"
  
  kxs[] fillarray 0, 1, 2, 3, 4, 5
  kys[] cmp kxs, ">=", 3
  printarray kys, 1, "", "instr 4, kys"
  turnoff
endin

instr 5
  ; range
  ixs[] fillarray 0, 1, 2, 3, 4, 5
  iys[] cmp 1, "<", ixs, "<=", 4
  printarray iys, "", "instr 5, iys"

  kxs[] fillarray 0, 1, 2, 3, 4, 5
  kys[] cmp 1, "<", kxs, "<=", 4
  printarray kys, 1, "", "instr 5, kys"
  turnoff
endin



</CsInstruments>
<CsScore>
i 1 0 2
i 4 0 1
i 5 0 1
</CsScore>
</CsoundSynthesizer>


See also

Arithmetic and Logic Operations

Comparators and Accumulators

Array opcodes

Credits

By: Eduardo Moguillansky 2017