Csound Csound-dev Csound-tekno Search About

pulse width

Date1998-01-13 18:44
FromChristian Lyra
Subjectpulse width
Hi, Csounders!

	How can i modify the pulse width of a pulse wave in Csound.  I'd
like to modify the pulse width with a lfo (like the old analog synths),
but how can i do this if the waves stored in ftables are "static"?

	Thanks,
	
		Christian Lyra


Date1998-01-14 15:58
FromErik Spjut
SubjectRe: pulse width
At 3:44 PM -0300 1/13/98, Christian Lyra wrote:
>Hi, Csounders!
>
>	How can i modify the pulse width of a pulse wave in Csound.  I'd
>like to modify the pulse width with a lfo (like the old analog synths),
>but how can i do this if the waves stored in ftables are "static"?

It's been close to two years since I last answered this. I guess I can
answer again. You basically need to use a conditional to speed up the
phasor during the first half of the cycle and slow it down during the
second half (or vice versa). You need kr=sr because of the conditionals.
You really have to watch out for aliasing because pulse-width modulation
changes the harmonic content. To start with try the following orc and sco
(I apologize about the wraps in the sco).

********ORC**********
sr=44100
kr=44100
ksmps=1
nchnls=1

instr 1
a1     linseg     0.1,0.05,1000,p3-.1,10000,0.05,0.1
k3     linseg     0,0.05,0,p3-.1,1,0.05,1
k1    phasor   p5     ; p5 is note frequency in cps
k2    =   (k1 < k3 ? (k1 /(2*k3)): ((1-2*k3+k1)/(2*(1-k3))))
; k3 is the symmetry index, varies from 0 to 1. 0.5 gives triangle wave
k4    tablei     k2, 1,1     ; table 1 should contain a triangle wave, the
; second 1 indicate use normalized (0-1) index into table
a2     =     k4     ;a2 is your audio out. Multiply by amplitude before sending
       out      a2*a1
endin

*********************
*******sco***********
; triangle
f1 0 4096 10 1000 0 -111.111111 0 40 0 -20.4081633 0 12.345679 0
-8.26446281 0 5.91715976 0 -4.44444444 0 3.46020761 0 -2.7700831 0 2.2675737
; square
;f1 0 4096 9 1 1000 0 3 333.333333 0 5 200 0 7 142.857143 0 9 111.111111 0
11 90.9090909 0 13 76.9230769 0 15 66.6666667 0 17 58.8235294 0 19
52.6315789 0 21 47.6190476 0
i1    0    5    0    440
i1     5    5    0    220
i1    10   5    0 110
*********************

-------------------------------------------------------------------------------
Erik Spjut (rhymes with cute) - Acting Director,The Center for Design Education
and/or Associate Professor of Engineering
Harvey Mudd College, Claremont, CA 91711  USA
Erik_Spjut@hmc.edu      Ph & Voice mail (909) 607-3890      Fax (909) 621-8967