csound -d -W -o bells.wav
; Setup
sr = 48000 ; Sample rate
kr = 4800 ; Control rate (k-rate)
nchnls = 1 ; One channel
; Variables
giMax = 32767 ; Maximum amplitude
;----------------------------------------------
; Bell
; - p4 : fundamental frequency (pitch)
; - p5 : velocity (normalized)
; - p6 : bell type : 0 - Harmonic components
; 1 - Arbitrary inharmonic components
; 2 - Golden-ratio exponential spaced components
; 3 - Square-root distributed components
instr 1
iDuration = p5 * 10 ; Duration of the sound
iAttack = 0.01 ; Attack time in seconds
iAmp = p5 * giMax ; Maximum amplitude
iFreq = cpspch(p4) ; Pitch to frequency
iType = p6 ; Type of bell
; Compute the frequency of the four harmonics according
; to the chosen bell type
if (iType == 1) igoto inharmonic
if (iType == 2) igoto golden_ratio
if (iType == 3) igoto square_root
igoto harmonic
inharmonic:
iF1 = 1
iF2 = 2.23
iF3 = 3.89
iF4 = 5.30
igoto playit
golden_ratio:
iPhi = (1 + sqrt(5)) / 2;
iF1 = 1
iF2 = iPhi
iF3 = iPhi * iPhi
iF4 = iPhi * iPhi * iPhi
igoto playit
square_root:
iF1 = 1
iF2 = sqrt(2)
iF3 = sqrt(3)
iF4 = sqrt(4)
igoto playit
harmonic:
iF1 = 1
iF2 = 2
iF3 = 3
iF4 = 4
playit:
; Generate the amplitude envelopes
kenv1 expseg .01, iAttack, iAmp, iDuration - iAttack, 1
kenv2 expseg .01, iAttack, iAmp, (iDuration - iAttack) * .6, 1
kenv3 expseg .01, iAttack, iAmp, (iDuration - iAttack) * .35, 1
kenv4 expseg .01, iAttack, iAmp, (iDuration - iAttack) * .2, 1
; Generate sounds
a1 oscil 1. * kenv1, iF1 * iFreq, 1
a2 oscil .9 * kenv1, iF1 * iFreq + .9, 1
a3 oscil .6 * kenv2, iF2 * iFreq, 1
a4 oscil .5 * kenv2, iF2 * iFreq + 1.7, 1
a5 oscil .3 * kenv3, iF3 * iFreq, 1
a6 oscil .4 * kenv4, iF4 * iFreq, 1
; Output
out (1*a1 + .9*a2 + .6*a3 + .5*a4 + .3*a5 + .4*a6) / (1 + .9 + .6 + .5 + .3 + .4)
; out a2 / 6
; out a3 / 6
; out a4 / 6
; out a5 / 6
; out a6 / 6
endin
;----------------------------------------------
; Chimes
; - p4 : start pitch
; - p6 : amplitude (normalized)
instr 2
endin
; Tables
f1 0 8192 10 1 ; Sinewave
f2 0 64 5 1 2 120 60 1 1 0.001 1 ; Percussive envelope
; Tempo
t 0 90
i1 .1 10 10.06 .3 1
i1 .15 10 10.09 .5 1
i1 .19 10 10.08 .3 2
i1 .23 10 11.03 .2 0
i1 .28 10 11.00 .3 3
i1 .35 10 12.09 .3 3
i1 .43 10 12.02 .4 2
i1 .50 10 11.04 .1 1
i1 .58 10 10.07 .3 2
; Score
i1 1 10 8.11 1 0 ; Big ben with harmonic bells
i1 2 10 8.07 1 0
i1 3 10 8.09 1 0
i1 4 10 8.02 1 0
i1 7 10 8.02 1 0
i1 8 10 8.09 1 0
i1 9 10 8.11 1 0
i1 10 10 8.07 1 0
i1 13 10 8.11 1 1 ; Big ben with inharmonic bells
i1 14 10 8.07 1 1
i1 15 10 8.09 1 1
i1 16 10 8.02 1 1
i1 19 10 8.02 1 1
i1 20 10 8.09 1 1
i1 21 10 8.11 1 1
i1 22 10 8.07 1 1
i1 25 10 8.11 1 2 ; Big ben with golden-ratio bells
i1 26 10 8.07 1 2
i1 27 10 8.09 1 2
i1 28 10 8.02 1 2
i1 31 10 8.02 1 2
i1 32 10 8.09 1 2
i1 33 10 8.11 1 2
i1 34 10 8.07 1 2
i1 37 10 8.11 1 3 ; Big ben with square-root bells
i1 38 10 8.07 1 3
i1 39 10 8.09 1 3
i1 40 10 8.02 1 3
i1 43 10 8.02 1 3
i1 44 10 8.09 1 3
i1 45 10 8.11 1 3
i1 46 10 8.07 1 3
e