Csound Csound-dev Csound-tekno Search About

Re: Oscillator Synch Orc/Sco

Date1998-11-15 12:51
FromJosep M Comajuncosas
SubjectRe: Oscillator Synch Orc/Sco
Reading Mike´s post I thought it would be possible another approach. But
it
didn´t worked. Anyway I think the bug is extremely instructive and I
believe
some of you may be interested in it for pedadogical purposes ;-), so I´m
posting
the example.
Let me suggest btw that a good sync should allow a sync time (the time
to
"forget" the previous oscillator phase) and a sync transition talbe to
be user
selectable, and the former k-variable.

sr = 44100
kr = 44100; kr = sr suggested
ksmps = 1
zakinit 1,1

; Note: these instruments don´t work properly
; the main reason is the pitch quantisation
; caused by Timout used to drive the sync
; An insteresting example
; of what you must not do ;-)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
instr 1; another sync oscillator (SINE)
; coded by Josep M Comajuncosas, Nov´98
; this instrument is MONOPHONIC
; otherwise set an offset to the zak parm.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;p4 = osc pitch
;p5 = sync freq
;p6 = discharge period

ksync_freq init p5
kdischarge_time init p6
; both prepared to be k-variable

kfreq init p4
ibound = sr/4
iamp   = 10000

sync:
aosc zar 0
kosc downsamp aosc
init_charge = i(kosc)
init_time   = i(kdischarge_time)

timout 0,i(1/ksync_freq),osc
reinit sync

osc:

;smooth transition to newly initialised oscillator
; oscil1 should be better but it crashes for some reason
kcharge linseg 1,init_time*.1, .9, init_time*.5, .1, init_time*.1,0

asine oscili 1,kfreq,1

;output is sine wave + remaining "charge"
acharge interp kcharge
aout = asine + acharge*init_charge
zaw aout,0

out aout*iamp
endin
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
instr 2; another sync oscillator (SAW)
; coded by Josep M Comajuncosas, Nov´98
; this instrument is MONOPHONIC
; otherwise set an offset to the zak parm.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;p4 = osc pitch
;p5 = sync freq
;p6 = discharge period

ksync_freq line p5,p3,p6
kdischarge_time line p7,p3,p8
; both prepared to be k-variable

kfreq init p4
ibound = sr/4
iamp   = 10000

;amplitude envelope (declick)
kenv linen 1, .05,p3,.05

sync:
aosc zar 0
kosc downsamp aosc
init_charge = i(kosc)
init_time   = i(kdischarge_time)

timout 0,i(1/ksync_freq),osc
reinit sync

osc:

;smooth transition to newly initialised oscillator
; oscil1 should be better but it crashes for some reason
kcharge linseg 1,init_time*.1, .9, init_time*.8, .1, init_time*.1,0

;bandlimited pulse
apulse buzz kenv, kfreq, ibound/kfreq, 1
;integrate the buzz to get a saw wave
asaw filter2 apulse, 1, 1, 1, -.99; leaky integrator

;output is saw wave + remaining "charge"
acharge interp kcharge
aout = asaw + acharge*init_charge
zaw aout,0

out aout*iamp
endin

f1 0 8192 10 1

;some transition curves for the sync feature
;falling sigmoid
;f2 0 8192 -19 .5 1 90 1
;straight line
;f3 0 8192 -7 1 8192 0

;some settings

;p4 = osc pitch
;p5 = sync freq
;p6 = discharge period
;p7 = discharge ftn

;test with a sine wave
;i1 0 2 221  99  .001 
;i1 2 2 221  99  .00001
;i1 4 2 221  99  .005
s
;testing a variable sync with a saw wave
;p4 = osc pitch
;p5 = starting sync pitch
;p6 = ending " "
;p7 = startinc sync time
;p8 = ending " "

i2 0 4 221 20 200 .005 .005
i2 4 4 221 200 1000 .0005  .0005
i2 8 4 221 220 224 .005 .00001