forked from EkardNT/GymClock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsound.h
More file actions
159 lines (151 loc) · 3.93 KB
/
sound.h
File metadata and controls
159 lines (151 loc) · 3.93 KB
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
#ifndef GYMCLOCK_SOUND_H
#define GYMCLOCK_SOUND_H
#include <AceRoutine.h>
// Pitches retrieved from https://codebender.cc/library/pitches#pitches.h
const int NOTE_B0 = 31;
const int NOTE_C1 = 33;
const int NOTE_CS1 = 35;
const int NOTE_D1 = 37;
const int NOTE_DS1 = 39;
const int NOTE_E1 = 41;
const int NOTE_F1 = 44;
const int NOTE_FS1 = 46;
const int NOTE_G1 = 49;
const int NOTE_GS1 = 52;
const int NOTE_A1 = 55;
const int NOTE_AS1 = 58;
const int NOTE_B1 = 62;
const int NOTE_C2 = 65;
const int NOTE_CS2 = 69;
const int NOTE_D2 = 73;
const int NOTE_DS2 = 78;
const int NOTE_E2 = 82;
const int NOTE_F2 = 87;
const int NOTE_FS2 = 93;
const int NOTE_G2 = 98;
const int NOTE_GS2 = 104;
const int NOTE_A2 = 110;
const int NOTE_AS2 = 117;
const int NOTE_B2 = 123;
const int NOTE_C3 = 131;
const int NOTE_CS3 = 139;
const int NOTE_D3 = 147;
const int NOTE_DS3 = 156;
const int NOTE_E3 = 165;
const int NOTE_F3 = 175;
const int NOTE_FS3 = 185;
const int NOTE_G3 = 196;
const int NOTE_GS3 = 208;
const int NOTE_A3 = 220;
const int NOTE_AS3 = 233;
const int NOTE_B3 = 247;
const int NOTE_C4 = 262;
const int NOTE_CS4 = 277;
const int NOTE_D4 = 294;
const int NOTE_DS4 = 311;
const int NOTE_E4 = 330;
const int NOTE_F4 = 349;
const int NOTE_FS4 = 370;
const int NOTE_G4 = 392;
const int NOTE_GS4 = 415;
const int NOTE_A4 = 440;
const int NOTE_AS4 = 466;
const int NOTE_B4 = 494;
const int NOTE_C5 = 523;
const int NOTE_CS5 = 554;
const int NOTE_D5 = 587;
const int NOTE_DS5 = 622;
const int NOTE_E5 = 659;
const int NOTE_F5 = 698;
const int NOTE_FS5 = 740;
const int NOTE_G5 = 784;
const int NOTE_GS5 = 831;
const int NOTE_A5 = 880;
const int NOTE_AS5 = 932;
const int NOTE_B5 = 988;
const int NOTE_C6 = 1047;
const int NOTE_CS6 = 1109;
const int NOTE_D6 = 1175;
const int NOTE_DS6 = 1245;
const int NOTE_E6 = 1319;
const int NOTE_F6 = 1397;
const int NOTE_FS6 = 1480;
const int NOTE_G6 = 1568;
const int NOTE_GS6 = 1661;
const int NOTE_A6 = 1760;
const int NOTE_AS6 = 1865;
const int NOTE_B6 = 1976;
const int NOTE_C7 = 2093;
const int NOTE_CS7 = 2217;
const int NOTE_D7 = 2349;
const int NOTE_DS7 = 2489;
const int NOTE_E7 = 2637;
const int NOTE_F7 = 2794;
const int NOTE_FS7 = 2960;
const int NOTE_G7 = 3136;
const int NOTE_GS7 = 3322;
const int NOTE_A7 = 3520;
const int NOTE_AS7 = 3729;
const int NOTE_B7 = 3951;
const int NOTE_C8 = 4186;
const int NOTE_CS8 = 4435;
const int NOTE_D8 = 4699;
const int NOTE_DS8 = 4978;
// Melody array has the following schema:
// <note> <duration> <start>
// - note is the tone frequency.
// - duration is the tone duration in millis
// - start is the offset in millis *since the melody's start* that the note begins playing at.
// Start times should be monotonically increasing
// At the end of the melody, put a 0 for the final frequency value.
const int SOUND_NONE[] = {
0
};
const int SOUND_BEEP[] = {
NOTE_C4, 250, 0,
0
};
const int SOUND_STARTUP[] = {
NOTE_DS6, 125, 0,
NOTE_DS5, 125, 250,
NOTE_AS5, 125, 375,
NOTE_GS5, 125, 750,
NOTE_DS6, 125, 1250,
NOTE_AS5, 500, 1500,
0
};
// TODO: make this distinct from STARTUP
const int SOUND_START_SET[] = {
NOTE_DS6, 125, 0,
NOTE_DS5, 125, 250,
NOTE_AS5, 125, 375,
NOTE_GS5, 125, 750,
NOTE_DS6, 125, 1250,
NOTE_AS5, 500, 1500,
0
};
// TODO: make this distinct from STARTUP
const int SOUND_START_REST[] = {
NOTE_DS6, 125, 0,
NOTE_DS5, 125, 250,
NOTE_AS5, 125, 375,
NOTE_GS5, 125, 750,
NOTE_DS6, 125, 1250,
NOTE_AS5, 500, 1500,
0
};
class SoundRoutine : public ace_routine::Coroutine {
public:
SoundRoutine() {}
int runCoroutine() override;
void playSound(const int *sound);
private:
bool checkAndClearInterrupt();
const int* currentSound = SOUND_NONE;
unsigned int generation = 0;
unsigned int expectedGeneration = 0;
int frequency = 0;
int absoluteStart = 0;
};
extern SoundRoutine soundRoutine;
#endif