sourceextensions/audio/demos/Instruments.xtl
1⍝# Instruments.xtl -- the instruments of the synthesizer demos (synth.xtl,
2⍝# scope.xtl): music as arrays. An ordinary X_eTaL library beside them.
3⍝# Import: "in:" u_se< "Instruments"
4
5⍝# frames a second
6ˡrate ← 22050.0
7
8⍝# a note's pitch: k semitones above A4 (440 Hz)
9ˡh̲z ← { k → 440.0 × 2.0 ^ (f̲loat k) ÷ 12.0 }
10
11⍝# the times of the samples of a 0.25 s step, and its envelope: a quick
12⍝# attack, a decay toward 60%, and a release at the end
13n ← f̲loor 0.25 × ˡrate
14t ← (f̲loat (r̲ange n) − 1) ÷ ˡrate
15env ← (1.0 m̲in t ÷ 0.01) × (((0.25 − t) ÷ 0.06) m̲in 1.0) × 0.6 + 0.4 × e̲xp 0.0 − t ÷ 0.12
16
17⍝# a tone: three harmonics (1, 1/2, 1/4) at each frequency of f, one row
18⍝# per frequency, along the times tt
19ˡt̲one ← { f tt →
20 x ← 6.283185307179586 × f '× t̲able tt
21 (s̲in x) + (0.5 × s̲in 2.0 × x) + 0.25 × s̲in 3.0 × x
22}
23
24⍝# the chords, as semitones from A4: C, Am, F, G (four notes each)
25chords ← 4 4 r̲eshape -9 -5 -2 3 -12 -9 -5 0 -16 -12 -9 -4 -14 -10 -7 -2
26
27⍝# bar b (from 1): the chord's notes in turn (one row each, enveloped,
28⍝# then laid end to end), over its root two octaves down for the whole
29⍝# bar, mixed to stereo (2 by 22048): the arpeggio more to the right, the
30⍝# bass more to the left
31ˡb̲ar ← { b →
32 k ← (1 + (b − 1) m̲od 4) s̲elect₁ chords
33 mel ← r̲avel 0.2 × ((ˡh̲z k) ˡt̲one t) × (4 c̲at n) r̲eshape env
34 tb ← (f̲loat (r̲ange 4 × n) − 1) ÷ ˡrate
35 low ← r̲avel (ˡh̲z (f̲irst k) − 24) ˡt̲one tb
36 bass ← 0.25 × low × (1.0 m̲in tb ÷ 0.02) × ((1.0 − tb) ÷ 0.1) m̲in 1.0
37 1.5 × (2 c̲at 4 × n) r̲eshape ((0.7 × bass) + 0.3 × mel) c̲at (0.3 × bass) + 0.7 × mel
38}