-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.fab
43 lines (36 loc) · 855 Bytes
/
sound.fab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
vars /sound
UU tri_pitch = 0
UU sq1_pitch = 0
U sq1_duty = 0
U sq1_vol = $0
UU sq2_pitch = 0
U sq2_duty = 0
U sq2_vol = $0
fn reset_audio()
// we need to handle sq pitch separately because setting high resets
// the duty cycle.
fn set_sq1_timbre()
fence
{SQ1_VOL}((sq1_duty << 6) | %110000 | (sq1_vol & $F))
fence
fn set_sq1_pitch()
fence
{SQ1_LO}(sq1_pitch.a)
{SQ1_HI}(sq1_pitch.b & %111)
fence
fn set_sq2_timbre()
fence
{SQ2_VOL}((sq2_duty << 6) | %110000 | (sq2_vol & $F))
fence
fn set_sq2_pitch()
fence
{SQ2_LO}(sq2_pitch.a)
{SQ2_HI}(sq2_pitch.b & %111)
fence
// works like normal, plays note for exactly one frame
fn play_tri()
fence
{TRI_LINEAR}($04) // play for one frame
{TRI_LO}(tri_pitch.a)
{TRI_HI}(tri_pitch.b & %111)
fence