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
|
#include "audio.h"
void PHL_AudioInit()
{
//oslInitAudio();
if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 1, 4096))
{
fprintf(stderr, "SDL_Mixer Error: %s\n", Mix_GetError());
exit(EXIT_FAILURE);
}
}
void PHL_AudioClose()
{
Mix_CloseAudio();
}
//Each system can use a custom music file extension
PHL_Music PHL_LoadMusic(char* fname, int loop)
{
PHL_Music result;
result.loop = loop;
char fullPath[40];
strcpy(fullPath, fname);
strcat(fullPath, ".ogg");
FILE* file;
if ((file = fopen(fullPath, "r"))) {
fclose(file);
result.data = Mix_LoadMUS(fullPath);
result.used = 1;
}else{
result.used = 0;
}
return result;
}
//PHL_Sound PHL_LoadSound(char* fname, int loop, int stream, int channel)
PHL_Sound PHL_LoadSound(char* fname)
{
PHL_Sound result;
FILE* file;
if ((file = fopen(fname, "r"))) {
fclose(file);
result.data = Mix_LoadWAV(fname);
result.used = 1;
}else{
result.used = 0;
}
return result;
}
void PHL_PlayMusic(PHL_Music snd)
{
if (snd.used == 1) {
int loop = 1;
if (snd.loop == 1) {
loop = -1;
}
Mix_PlayMusic(snd.data, loop);
}
}
//void PHL_PlaySound(PHL_Sound snd)
void PHL_PlaySound(PHL_Sound snd, int channel)
{
if (snd.used == 1) {
Mix_PlayChannel(channel, snd.data, 0);
}
}
void PHL_StopMusic()
{
Mix_HaltMusic();
}
void PHL_StopSound(PHL_Sound snd, int channel)
{
}
void PHL_FreeMusic(PHL_Music snd)
{
Mix_FreeMusic(snd.data);
snd.used = 0;
}
void PHL_FreeSound(PHL_Sound snd)
{
Mix_FreeChunk(snd.data);
snd.used = 0;
}
|