| just to follow up on my previous message. just today, jpff posted
michel peters' didjerido instrument. what is the first line of the
instrument ?
>> instr 1
>>
>> ;=======ENVELOPES====================================================
>> kenv1 linseg 0, .1*p3, 1, .8*p3, 1, p3*.1, 0 ;/--\(FADE IN/OUT)
notice the instant reliance on p3. just a small example of an
instrument that cannot easily be used with real-time control (MIDI or
otherwise) since p3 is not known.
again, in quasimodo, i came up with a radically different approach to
enveloping, which is typically where p3 comes into play. i wrote a new
opcode called "envelope". here's an example of its use:
----------------------------------------------------------------
;Category Audio/Generators
instr "Enveloped Oscillator"
aoutput init 0
asig init 0
kfrequency init cpsmidi
kwavetable init "sine1"
krel init 0
kontrig init 0
knharmonics init 1
ienvduration init 5
ienvelope init "Enveloped Oscillator"
kenv init 1
kenvsection init 0 ; start in the first section
kenvamplitude init 1
isection2_offset init -1
isection3_offset init -1
isection4_offset init -1
isection5_offset init -1
polyphonic
midibind
kenv envelope ienvelope, ienvduration, kenvsection, kenvamplitude, \
0, \
isection2_offset, \
isection3_offset, \
isection4_offset, \
isection5_offset
kontrig = 1
asig buzz kenv, kfrequency, knharmonics, kwavetable
aoutput += asig
---------------------------------------------------------------------------
a couple of quasimodo-context explanations: tables and instruments
have names, not numbers. "polyphonic" specifies that the instrument
can be invoked to create multiple simultaneous voices, which is
actually the default, but is there for completeness. "midibind" turns
on automatic mapping of noteOn/noteOff MIDI messages for the
port/channel currently set for the instrument into voice
creation/deletion. also, "+=" is supported in quasimodo, but not
csound, and is essential to proper polyphonic operation.
"envelope"
---------
"envelope" takes a function table [ienvelope], and does interpolated
table lookup into [kenv]. the total duration represented by the table
is given by [ienvduration].
there are two keys to its operation. first, the value of [kenvsection]
selects one of the offset arguments. the offsets act as both the
starting point for, and a limit on, the table lookup pointer. so, if
[kenvsection] is currently 0, table lookup begins at table index 0,
and ends at table index [isection2_offset]. if the pointer reaches the
endpoint, it remains there (i.e. [kenv] gets a constant value) until
[kenvsection] ends.
the only exception to this is if the pointer is the last defined
"section" of the table. then, when the pointer reaches the end of the
section, an internal mechanism is used to turn off the voice after the
end of the current control cycle (i.e. the voice gets to use the last
value of [kenv], and is then turned off).
but wait, you may say, what about [ienvduration] ? doesn't that imply
known voice length ? No. All it determines the speed of the table
lookup pointer through the table. If there is only one section in the
table (i.e. 0 or 1 offset arguments), then indeed, it will affect the
total voice duration. however ...
here is the internal trick in the opcode - if the relevant noteOff has
been received for a voice (more generally, if the voice is marked as
"releasing" (aka "relesing" in the Csound source)), then it immediately
switches to the *last* section of the table.
so, to make this work for MIDI, you simply provide two offsets within
the table, thus defining two sections. Then, when the noteOn occurs,
table lookup begins at the first offset and continues until it reaches
the second offset. [kenv] then becomes constant. when the noteOff is
received, table lookup "starts again" from the second offset, and
proceeds to the end of the table. thus, the second section of the
table defines the "release" envelope.
note that strange effects can be obtained by k-rate alteration of
[kenvsection], effectively causing the table lookup to "jump" to
different sections of the function table.
this is a highly flexible approach to enveloping, more flexible than
ADSR or its descendants, and usable with real-time control in a way
that envelope lines based on a known p3 is not. and of course,
quasimodo lets you draw the envelope function tables graphically,
either free hand, as splines, or straight-line segments, though it
doesn't require that.
i plan to backport this opcode to Csound someday.
--p
|