Csound Csound-dev Csound-tekno Search About

Re: Digeridoo

Date1999-07-27 02:53
FromMatti Khler-Busch
SubjectRe: Digeridoo
Many thanks.

jpff@maths.bath.ac.uk wrote:

> >From my archives....
>
> 
> 
> ; This patch generates the sound of a didjerido
> ; by means of wave shaping....
>
> ;       Michel Peters
> ; Utrecht School of the Arts
> ; dep. Musictechnology
> ; course year MT-t-1  94/95
>
> sr=44100
> kr=441
> ksmps=100
> nchnls=2
>
>                 instr   1
>
> ;=======ENVELOPES====================================================
> kenv1   linseg  0, .1*p3, 1, .8*p3, 1, p3*.1,   0 ;/--\(FADE IN/OUT)
>
> ;=======LFO'S========================================================
> klfo1   randi   .02,    20,     .123
> klfo2   randi   .02,    10,     .23
> klfo3   randi   500,    5,      .67
> ;=======SIGNAL-PROCESSING============================================
> anoise  rand    .05                                 ;NOISE
> asin1   oscili  .3+klfo2,       p5+klfo1,       1       ;FREQ+LFO'S
> awave1  tablei  asin1,          2,      1,      .5      ;WAVESHAPING/SQA.+RES.
> afilter reson   awave1+anoise,1000,     1000+klfo3
> abal    balance afilter,awave1
> ;=======OUTPUT=======================================================
>                 outs    abal*kenv1*p4,abal*kenv1*p4
>                 endin
> 
> 
> ;========================================================SCORE=======
> ; a test-score for the wave shaped didge
>
> f1 0 1024 10 1
> f2 0 1024 7 0 32 1 32 .7 64 .9 54 .6 64 1 54 .7 64 1 44 .8 84 .6 40 -.6 84 -.8
> 44 -1 64 -.7 54 -1 64 -.6 54 -.9 64 -.7 32 -1 32 0
>
> ;instr   start   dur     amp      freq
> i1       0       5       29000     65
> e
> 
> 



--

6669the RaabidMuttn Speaks6999

Date1999-07-27 04:21
FromPaul Barton-Davis
Subjectreal-time control, MIDI, p3 [was Re: sequencer]
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