Showing posts with label physical modeling. Show all posts
Showing posts with label physical modeling. Show all posts

Thursday, March 14, 2013

Pendula

Created some sound in Csound based on this video I found on Youtube:


https://soundcloud.com/hmikelson/pendula 






<CsoundSynthesizer>
<CsOptions>
;-RWfo pendula.wav
</CsOptions>
<CsInstruments>
;---------------------------------------------------------
; Pendula
; Inspired by Youtube video of pendulums of various lengths like this one
http://www.youtube.com/watch?v=eZm_-2O8ovI&list=UUeQEKFH31vvD-InkTGSvCrA 
; Hans Mikelson March 2013
;---------------------------------------------------------
sr = 44100 ; Sample rate
kr = 44100 ; Kontrol rate
ksmps = 1 ; Samples/Kontrol period This must be 1 to make sure to update time appropriately
nchnls = 2 ; Normal stereo
;---------------------------------------------------------
; Pendula
;---------------------------------------------------------
instr 50
idur = p3 ; Duration
iamp = p4  ; Amplitude
il0 = p5  ; Length of pendulum
ib = p6  ; Damping factor for pendulum (smaller damping will ring longer)
ig = p7  ; Gravity
kdclk linseg 0, .005, 1, idur-.01, 1, .005, 0
atime init 0  ; Need to start time at 0
atime = atime + .1  ; Time is incremented each sample
ialpha0 = ib/2/il0 ; Calculate alpha exponential decay factor
aamp0 = 1*exp(-ialpha0*atime) ; Calculate exponetial decay
aout0 = aamp0*cos(sqrt(ig/il0-ib/il0/il0)*atime) ; Calculate the oscillator times amplitude
apan = .5 + aout0/2
outs aout0*iamp*apan*kdclk, aout0*iamp*(1-apan)*kdclk ; Amplify and output
;outs aout0*iamp*sqrt(apan)*kdclk, aout0*iamp*sqrt(1-apan)*kdclk ; Amplify and output
;outs aout0*iamp*kdclk, -aout0*iamp*kdclk ; Amplify and output
endin
</CsInstruments>
<CsScore>
;-------------------------------------------------------------------------
f1 0 65536 10 1
; Pendula
; Sta Dur Amp PendL Damp Gravity
i50 0.0 10 3000  100 0.02 9.81
i50 . . .  90  . .
i50 . . .  80 . .
i50 . . .  70 . .
i50 . . .  60  . .
i50 . . .  50  . .
i50 . . .  40 . .
i50 . . .  30 . .
i50 . . .  20 . .
i50 . . .  10  . .
; Pendula
; Sta Dur Amp PendL Damp Gravity
i50 10.0 10 3000  100 0.02 9.81
i50 . . .  95  . .
i50 . . .  90 . .
i50 . . .  85 . .
i50 . . .  80  . .
i50 . . .  75  . .
i50 . . .  70 . .
i50 . . .  65 . .
i50 . . .  60 . .
i50 . . .  55  . .
; Pendula
; Sta Dur Amp PendL Damp Gravity
i50 20.0 5 3000  200 0.1 9.81
i50 . . .  100  . .
i50 . . .  50 . .
i50 . . .  25 . .
i50 . . .  12  . .
i50 . . .  6  . .
; Pendula
; Sta Dur Amp PendL Damp Gravity
i50 25.0 5 3000  100 0.05 9.81
i50 . . .  90  . .
i50 . . .  81 . .
i50 . . .  73 . .
i50 . . .  66  . .
i50 . . .  59  . .
i50 . . .  53 . .
i50 . . .  48 . .
i50 . . .  43 . .
i50 . . .  39  . .
</CsScore>
</CsoundSynthesizer>