Csound Csound-dev Csound-tekno Search About

New minmax opcode library

Date2006-01-24 08:36
FromAnthony Kozar
SubjectNew minmax opcode library
Attachmentsminmaxtest.csd  minmaxtest2.csd  minmax.c  fmscape.orc  fmscape.sco  
I've finished up a new set of opcodes tonight for outputing the minimum or
maximum values among several signals.  The code is currently only for Csound
4 but I will be porting it to Csound 5 just as soon as I can.  A MacOS 9
plugin library for these opcodes is available upon request.  If you are on
another platform, you can try compiling them yourself with the attached
code.

Syntax:

        maxaccum    aAccumulator, aInput
        minaccum    aAccumulator, aInput
        maxabsaccum aAccumulator, aInput
        minabsaccum aAccumulator, aInput

amax    max         ain1, ain2 [, ain3] [, ain4] [...]
amin    min         ain1, ain2 [, ain3] [, ain4] [...]
amax    maxabs      ain1, ain2 [, ain3] [, ain4] [...]
amin    minabs      ain1, ain2 [, ain3] [, ain4] [...]

kmax    max         kin1, kin2 [, kin3] [, kin4] [...]
kmin    min         kin1, kin2 [, kin3] [, kin4] [...]
kmax    maxabs      kin1, kin2 [, kin3] [, kin4] [...]
kmin    minabs      kin1, kin2 [, kin3] [, kin4] [...]


The maxaccum and minaccum opcodes work similarly to the vincr opcode except
that they store the maximum or minimum value into aAccumulator instead of
adding them together.  aAccumulator is used as both an input and an output
signal here with the following logic:

       maxaccum:   if  (aInput > aAccumulator)  aAccumulator = aInput
       minaccum:   if  (aInput < aAccumulator)  aAccumulator = aInput

This test is performed on a per sample basis and can easily lead to
discontinuities in the output signal.  For this reason, I typically use the
opcodes to combine audio-rate control signals.

maxabsaccum and minabsaccum are identical to maxaccum and minaccum except
that they compare the absolute values of the inputs, and thus always have a
positive output.


The max and min families of opcodes are used to find the maximum or minimum
values among any number of a-rate or k-rate signals.  The ain* and kin*
parameters are only read by these opcodes and the output is written to amax,
amin, kmax, or kmin just as one would expect.

Once again, the a-rate versions work on a per sample basis.  And maxabs and
minabs take the absolute value of all of the inputs before comparing them.

I've attached two example CSDs that output four-channel files with
infrasonic signals.  Opening the output files in an editor clearly shows the
operation of the different max/min opcodes.

Also attached is the orc/sco for the first minute of a new piece called
"FMscape no. 1" that shows a musical use for the maxaccum opcode.  The work
uses an FM carrier wave with a variable number of modulators where the
output amplitude is controlled by the maximum of all of the modulators'
envelopes.

An MP3 of this one-minute excerpt is available here:
http://briefcase.yahoo.com/bc/akozar@sbcglobal.net/lst?.dir=/Music

Finally, source code is attached.

Comments are welcome.  Thanks.

Anthony Kozar
anthonykozar AT sbcglobal DOT net