-
Notifications
You must be signed in to change notification settings - Fork 3
/
music.c
167 lines (127 loc) · 3.67 KB
/
music.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
typedef enum {
C3, Cd3, D3, Dd3, E3, F3, Fd3, G3, Gd3, A3, Ad3, B3,
C4, Cd4, D4, Dd4, E4, F4, Fd4, G4, Gd4, A4, Ad4, B4,
C5, Cd5, D5, Dd5, E5, F5, Fd5, G5, Gd5, A5, Ad5, B5,
C6, Cd6, D6, Dd6, E6, F6, Fd6, G6, Gd6, A6, Ad6, B6,
C7, Cd7, D7, Dd7, E7, F7, Fd7, G7, Gd7, A7, Ad7, B7,
C8, Cd8, D8, Dd8, E8, F8, Fd8, G8, Gd8, A8, Ad8, B8,
SILENCE
} Pitch;
const UWORD frequencies[] = { //values based on a formula used by the GB processor
44, 156, 262, 363, 457, 547, 631, 710, 786, 854, 923, 986,
1046, 1102, 1155, 1205, 1253, 1297, 1339, 1379, 1417, 1452, 1486, 1517,
1546, 1575, 1602, 1627, 1650, 1673, 1694, 1714, 1732, 1750, 1767, 1783,
1798, 1812, 1825, 1837, 1849, 1860, 1871, 1881, 1890, 1899, 1907, 1915,
1923, 1930, 1936, 1943, 1949, 1954, 1959, 1964, 1969, 1974, 1978, 1982,
1985, 1988, 1992, 1995, 1998, 2001, 2004, 2006, 2009, 2011, 2013, 2015,
0
};
enum DurationNote
{
LONG = 0x84U,
SHORT = 0x81U,
LONG_LONG = 135
};
//Define Instrument names
//Instruments should be confined to one channel
//due to different registers used between ch1, 2, 3, 4
typedef enum {
NONE,
MELODY, //channel 1
HARMONY, //channel 1
SNARE, //channel 2
WAVE, //channel 3
CYMBAL //channel 4
} Instrument;
//Define a Note as having a Pitch, Instrument, and volume envelope
typedef struct {
Instrument i;
Pitch p;
UINT16 env;
} Note;
const Note jingle[] = {
{MELODY, C3, SHORT},
{MELODY, G3, SHORT},
{MELODY, C4, LONG}
};
const Note you_win[] = {
{MELODY, B4, LONG},
{MELODY, C5, LONG},
{MELODY, D5, LONG},
{MELODY, G5, LONG},
{MELODY, G5, LONG},
{MELODY, G5, LONG},
{MELODY, F5, LONG},
{MELODY, E5, LONG},
{MELODY, D5, LONG}
};
const Note game_ch1[] = {
{MELODY, D4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, C4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, D4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, C4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, G3, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, C4, SHORT},
{NONE, SILENCE, LONG_LONG},
{MELODY, D4, LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
//bar 2
{MELODY, D4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, C4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, D4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, C4, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, G3, LONG},
{NONE, SILENCE, LONG_LONG},
{MELODY, C4, SHORT},
{NONE, SILENCE, LONG_LONG},
{MELODY, D4, LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
};
const Note game_ch2[] = {
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
//bar 2
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
{CYMBAL, G3, SHORT},
{CYMBAL, G3, SHORT},
{NONE, SILENCE, LONG_LONG},
{NONE, SILENCE, LONG_LONG},
};