-
Notifications
You must be signed in to change notification settings - Fork 0
/
Music.d
executable file
·65 lines (47 loc) · 1.06 KB
/
Music.d
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
module Music;
private import derelict.sdl.sdl;
private import derelict.sdl.mixer;
private import Log;
private Mix_Music*[char[]] loadedMusic;
private Mix_Chunk*[char[]] loadedSounds;
void start()
{
Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 2048);
}
void playMusic(char[] fileName, int times = -1)
{
if(!loadedMusic[fileName]) {
Log.log("Loading music '%s'\n", fileName);
loadedMusic[fileName] = Mix_LoadMUS(fileName);
}
Mix_PlayMusic(loadedMusic[fileName], times);
}
void stopMusic(double ms)
{
Mix_FadeOutMusic(cast(int) ms);
}
void loadSound(char[] fileName)
{
if(!loadedSounds[fileName]) {
Log.log("Loading sound '%s'\n", fileName);
loadedSounds[fileName] = Mix_LoadWAV(fileName);
}
}
void startPreload()
{
Mix_Volume(1, 0);
}
void endPreload()
{
Mix_Volume(1, 128);
}
void preloadSound(char[] fileName)
{
loadSound(fileName);
Mix_PlayChannel(1, loadedSounds[fileName], 0);
}
void playSound(char[] fileName)
{
loadSound(fileName);
Mix_PlayChannel(-1, loadedSounds[fileName], 0);
}