-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundManager.pde
204 lines (168 loc) · 4.82 KB
/
SoundManager.pde
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import processing.sound.*;
import ddf.minim.*;
class SoundManager implements IWaiter {
final SoundClip LIGHT_BLINK_SOUND = new SoundClip("light blink 01.wav");
final SoundClip INSERT_BATTERIES_SOUND = new SoundClip("insert batteries.wav");
final SoundClip PICK_UP_ITEM_01 = new SoundClip("pickuo item 01.mp3");
final SoundClip PICK_UP_ITEM_02 = new SoundClip("pickuo item 02.mp3");
final SoundClip FLASHLIGHT_ON = new SoundClip("flashlight on.wav");
final SoundClip FLASHLIGHT_OFF = new SoundClip("flashlight off.wav");
final SoundClip ATTIC_DOOR_FALL = new SoundClip("attic door open.wav");
final SoundClip FOOT_STEPS = new SoundClip("footstep01 0.800 seconds.wav");
final SoundClip OPEN_DOOR = new SoundClip("53280__the-bizniss__front-door-open.wav");
final SoundClip[] PICKUP_PAGE = new SoundClip[] {
new SoundClip("pickup page 01.wav"),
new SoundClip("pickup page 02.wav")
};
final SoundClip[] PAGE_FLIP = new SoundClip[] {
new SoundClip("page flip 01.wav"),
new SoundClip("page flip 02.wav")
};
//Music and BG
final SoundClip BG_SOUND = new SoundClip("Insanity_BG_Audio.wav");
final SoundClip LIVINGROOM_MUSIC = new SoundClip("Living Room Fireplace and Family photos.wav");
final SoundClip ATTIC_MUSIC = new SoundClip("Attic with fade out.wav");
final SoundClip LIMBO_SOUND = new SoundClip("Lets Play Limbo (Blind) - Part 4 - Medium Speed Chase.wav");
final SoundClip[] sounds = new SoundClip[] {
LIGHT_BLINK_SOUND,
INSERT_BATTERIES_SOUND,
PICK_UP_ITEM_01,
PICK_UP_ITEM_02,
FLASHLIGHT_ON,
FLASHLIGHT_OFF,
ATTIC_DOOR_FALL,
FOOT_STEPS,
OPEN_DOOR,
PICKUP_PAGE[0],
PICKUP_PAGE[1],
PAGE_FLIP[0],
PAGE_FLIP[1],
};
final SoundClip[] musics = new SoundClip[] {
BG_SOUND,
LIVINGROOM_MUSIC,
ATTIC_MUSIC,
LIMBO_SOUND
};
HashSet<SoundClip> soundsPlaying;
SoundManager() {
println( "new SoundManager()");
soundsPlaying = new HashSet<SoundClip>();
//for (int i = 0; i < musics.length; i++) {
// musics[i].amp = 0;
// musics[i].play();
// musics[i].player.amp(0);
//}
//waiter.waitForSeconds(0.5, this, 0, null);
}
void step(float delta) {
}
void playCategory(ItemCategory category) {
switch (category) {
case NOTE:
break;
case TOOL:
break;
default:
}
}
void playPickUpItem(String itemName) {
switch (itemName) {
case "notes_item":
int rand = int(random(0, PICKUP_PAGE.length));
PICKUP_PAGE[rand].play();
break;
case "batteries_item":
PICK_UP_ITEM_01.play();
break;
case "flashlight_item":
PICK_UP_ITEM_02.play();
break;
default:
}
}
void playItemClicked(String itemName) {
switch (itemName) {
case "notes_item":
PICKUP_PAGE[1].play();
break;
case "flashlight_batteries_item_on":
FLASHLIGHT_ON.play();
break;
case "flashlight_batteries_item_off":
FLASHLIGHT_OFF.play();
break;
default:
}
}
void execute(int executeId, Object obj) {
if (executeId == 0) {
for (int i = 0; i < musics.length; i++) {
musics[i].player.stop();
}
}
}
}
class SoundClip {
float FADEOUT_DURATION = 2;
SoundFile player;
float amp = 1;
boolean isFadingOut;
float fooLoop; //used to make a fake Ani only to wait and run a callback <-- ugly but productive
float fooPlay;
Ani anim;
SoundClip(String pSoundFile) {
//player = minim.loadFile(pSoundFile);
println(pSoundFile);
player = new SoundFile(thisApplet, pSoundFile);
}
boolean play() {
if (player.isPlaying() == false) {
amp = 1;
player.amp(amp);
player.play();
return true;
} else if (player.isPlaying() && isFadingOut) {
fooLoop = 0;
float wait = map(amp, 0, 1, 0, FADEOUT_DURATION);
Ani.to(this, wait, 0, "fooPlay", 1, Ani.LINEAR, this, "onEnd:playAgainAfterFadeOut");
}
return false;
}
boolean loop() {
if (player != null && player.isPlaying() == false) {
amp = 1;
player.amp(amp);
player.loop();
return true;
} else if (player.isPlaying() && isFadingOut) {
fooLoop = 0;
float wait = map(amp, 0, 1, 0, FADEOUT_DURATION);
Ani.to(this, wait, 0, "fooLoop", 1, Ani.LINEAR, this, "onEnd:loopAgainAfterFadeOut");
}
return false;
}
void playAgainAfterFadeOut() {
this.play();
}
void loopAgainAfterFadeOut() {
this.loop();
}
boolean fadeOut() {
if (player.isPlaying()) {
anim = Ani.to(this, FADEOUT_DURATION, 0, "amp", 0, Ani.LINEAR, this, "onUpdate:fadeOutUpdate, onEnd:fadeOutEnd");
isFadingOut = true;
return true;
}
return false;
}
void fadeOutUpdate() {
player.amp(amp);
}
void fadeOutEnd() {
if (player.isPlaying()) {
player.stop();
}
isFadingOut = false;
}
}