; sample rate can be changed as desired, control rate must match sample rate
sr = 44100
kr = 44100
nchnls = 2
; this piece is based on the defining relation S(n) = S(n - j) + S(n - k) mod m
; parameters, including the starting values, are to be entered below as instructed
gi_gr = sqrt(5)/2-.5 ; the golden ratio, do not edit
; used by orchestra, no input necessary
itmp ftgen 2, 0, 64, -2, 0
itmp ftgen 3, 0, 17, -2, 0
itmp ftgen 4, 0, 16384, 10, 1
ift vco2init -1, -1, 0, 0, 0, 4
seed 0 ; random values globally seeded from system clock, comment out if desired
; set the modulus
gi_mod = 2^32
; input starting integers for generator starting to the right of -2, or use pseudo-random initialization in table below, increase table size if needed
itmp ftgen 1, 0, 64, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
; comment out table above and un-comment below for pseudo-random seed (disadvantage: some possibility starting vals aren't relatively prime)
;itmp ftgen 1, 0, 64, -21, 1, gi_mod
; select wave: 0 = saw, 10 = square, 12 = triangle, 14 = sine
gi_wave = 0
; set duration of one integer in samples
gi_length_in_smps = 1850
; frequency of integers, no need to edit
gi_env_freq = sr/gi_length_in_smps
; input j (see equation at top)
gi_j = 1
; input k (the number of integers entered into table 1 if manually entered)
gi_k = 2
; set pitch for 0
gi_0_cps = 430
; set temperament (x in the form of phi^x + 1)
gi_temp = 45
; calculates base interval in temperament, no need to edit
gi_temp_num = 1+gi_gr^gi_temp
; comment out above and un-comment below for descending orientation (the higher the integer the lower the pitch)
;gi_temp_num = 1/(1+gi_gr^gi_temp)
; set attack and release values
gi_att = .0045
gi_rel = .0072
; no need to edit instruments
instr 1
kndx = 0
kres timek
if (kres!=1) goto phase_2
imax = gi_k-1
katt = gi_att
krel = gi_rel
prints "starting values (note: repeated values not shown): \n"
loop_0:
ktab1 table kndx, 1
tablew int(ktab1), kndx, 1
printk2 int(ktab1)
kndx = kndx + 1
if (kndx <= imax) kgoto loop_0
phase_2:
if (kres%gi_length_in_smps!=0) goto phase_3
loop_1:
ktab1 table kndx+1, 1
tablew ktab1, kndx, 2
kndx = kndx + 1
if (kndx < imax) goto loop_1
ktab1a table kndx-gi_j+1, 1
ktab1b table 0, 1
tablew (ktab1a+ktab1b)%gi_mod, kndx, 2
kndx = 0
loop_2:
ktab2 table kndx, 2
tablew ktab2, kndx, 1
kndx = kndx + 1
if (kndx <= imax) goto loop_2
phase_3:
ktab1 table 0, 1
kenv loopseg gi_env_freq, 0, 0, 0, katt/(1/gi_env_freq), 1, 1-(katt+krel)/(1/gi_env_freq), 1, krel/(1/gi_env_freq), 0
kamp table3 ktab1/((gi_mod-1)/16), 10
aw1 vco2 kamp, (gi_temp_num^ktab1)*gi_0_cps, gi_wave
kpan table3 ktab1/((gi_mod-1)/16), 11
outs aw1*kenv*kpan, aw1*kenv*(1-kpan)
end:
endin
instr 2
i_att = gi_att
i_rel = gi_rel
i_extreme_cps = (gi_temp_num^(gi_mod-1))*gi_0_cps
prints "extreme pitch in Hz: \n"
print i_extreme_cps
kit1 = (gi_temp_num^(((gi_mod-1)/16)*p4))*gi_0_cps
kenv linen 1, gi_att, p3, gi_rel
kamp table3 p4, 10
aw1 vco2 kamp, (gi_temp_num^(((gi_mod-1)/16)*p4))*gi_0_cps, gi_wave
kpan table3 p4, 11
outs aw1*kenv*kpan, aw1*kenv*(1-kpan)
end:
endin
; The pan and amplitude need to be set every time the pitch is shifted (gi_0_cps), temperament changed (gi_temp), modulus changed (gi_mod)
; or when the timbre (gi_wave) is changed. In other words, when a different set of pitches (or timbre) is used, the profile needs to be adjusted.
; set amplitude
f10 0 17 -2 165 190 219 258 342 380 410 472 565 650 715 780 860 920 970 1290 1520
; set pan here to simulate line described in comment for the delay above, pan is in strength of left speaker (if left .72, right is .28)
f11 0 17 -2 .3 .33 .365 .397 .43 .451 .47 .486 .5 .514 .53 .552 .575 .592 .61 .627 .645
; Use instrument 2 to set the profile; work down this list from 3 -> 5 -> 9 -> 17, these are reference pitches.
;i2 0 .5 0 ; lowest pitch (0th value of tables above)
;i2 + . 8 ; exactly in the middle - pan should always be .5 here (8th value in tables above)
;i2 + . 16 ; highest pitch (16th value in tables above)
;i2 0 .5 0
;i2 + . 4
;i2 + . 8
;i2 + . 12
;i2 + . 16
;i2 0 .5 0
;i2 + . 2
;i2 + . 4
;i2 + . 6
;i2 + . 8
;i2 + . 10
;i2 + . 12
;i2 + . 14
;i2 + . 16
;i2 0 .5 0
;i2 + . 1
;i2 + . 2
;i2 + . 3
;i2 + . 4
;i2 + . 5
;i2 + . 6
;i2 + . 7
;i2 + . 8
;i2 + . 9
;i2 + . 10
;i2 + . 11
;i2 + . 12
;i2 + . 13
;i2 + . 14
;i2 + . 15
;i2 + . 16
i1 0 66.99433 ; make sure that piece length given here is a multiple of the note length