; sample rate should stay at 44100
sr = 44100
kr = 44100
nchnls = 1
; 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
; set the modulus, should be equivalent to bit-depth with which the file is rendered
gi_mod = 2^16
seed 0 ; random values globally seeded from system clock, comment out if desired
; 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
; used by orchestra, no input necessary
itmp ftgen 2, 0, 64, -2, 0
; input j (see equation at top)
gi_j = 31
; input k (the number of integers entered into table 1 if manually entered)
gi_k = 63
; invert phase if desired by entering 1 below, 0 is standard
gi_invert = 0
; instrument 1 treats the number 0 as the sample -gi_mod/2, 1 as -gi_mod/2+1 etc.
instr 1
kres timek
kndx = 0
imax = gi_k-1
if (kres>1) goto phase_2
loop_0:
ktab1 table kndx, 1
tablew int(ktab1), kndx, 1
printk2 int(ktab1)
kndx = kndx + 1
if (kndx <= imax) goto loop_0
phase_2:
kndx = 0
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
ktab1 table 0, 1
if (gi_invert==1) goto inverted
out a(ktab1-gi_mod/2)
goto end
inverted:
out a(-(1+ktab1-gi_mod/2))
end:
kndx = 0
loop_2:
ktab2 table kndx, 2
tablew ktab2, kndx, 1
kndx = kndx + 1
if (kndx <= imax) goto loop_2
endin
; instrument 2 treats the number 0 as the sample 0, 1 as 1, gi_mod/2 is treated as -gi_mod/2, gi_mod/2+1 as -gi_mod/2+1 etc.
instr 2
kres timek
kndx = 0
imax = gi_k-1
if (kres>1) goto phase_2
loop_0:
ktab1 table kndx, 1
tablew int(ktab1), kndx, 1
printk2 int(ktab1)
kndx = kndx + 1
if (kndx <= imax) goto loop_0
phase_2:
kndx = 0
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
ktab1 table 0, 1
if (gi_invert==1) goto inverted
if (ktab1>=gi_mod/2) goto bend_around
out a(ktab1)
goto end
bend_around:
out a(ktab1-gi_mod)
goto end
inverted:
if (ktab1>=gi_mod/2) goto bend_around_i
out a(-ktab1-1)
goto end
bend_around_i:
out a(-ktab1-1+gi_mod)
end:
kndx = 0
loop_2:
ktab2 table kndx, 2
tablew ktab2, kndx, 1
kndx = kndx + 1
if (kndx <= imax) goto loop_2
endin
; choose instrument 1 or 2
i2 0 1