-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixer.c
More file actions
108 lines (83 loc) · 2.04 KB
/
Copy pathmixer.c
File metadata and controls
108 lines (83 loc) · 2.04 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
#include <SDL_mixer.h>
#include "mixer.h"
#include "miau.h"
Mix_Music* resplandescente;
Mix_Music* bianca_kalutor_e_o_demonio;
Mix_Chunk* miau;
Mix_Chunk* uai;
void mix_sample(Mix_Chunk* x)
{
if (Mix_PlayChannel(0, x, 0))
erorr("Mix_PlayChannel: %s", Mix_GetError());
}
void mix_miau()
{
mix_sample(miau);
}
void mix_uai()
{
mix_sample(uai);
}
void mix_frame()
{
}
static Mix_Chunk* load_chunk(const char* path)
{
Mix_Chunk* chunk;
chunk = Mix_LoadWAV(path);
if (!chunk)
die(-1, "Failed to load audio sample: %s: %s", path, Mix_GetError());
return chunk;
}
static Mix_Music* load_music(const char* path)
{
Mix_Music* music;
music = Mix_LoadMUS(path);
if (!music)
die(-1, "Failed to load music: %s: %s", path, Mix_GetError());
return music;
}
static void play_music(Mix_Music* music, int n)
{
if(Mix_PlayMusic(music, n))
die(-1, "Failed to play music: %s", Mix_GetError());
}
void mix_bianca_kalutor_e_o_demonio()
{
static unsigned long t1 = 0, t2;
t2 = SDL_GetTicks();
if (t1 == 0 || 20000 < t2 - t1)
{
play_music(bianca_kalutor_e_o_demonio, 1);
t1 = t2;
}
}
void mix_init()
{
int flags;
int x;
info ("Initializing SDL mixer.");
if (SDL_InitSubSystem(SDL_INIT_AUDIO))
die(-1, "Failed to initialize SDL: %s", SDL_GetError());
/* FIXME: do a Mix_Init() twice with Mix_OpenAudio in between, otherwise
* it will report the MP3 driver as not available */
flags = 0;
if ((flags & (x = Mix_Init(flags))) != flags)
die(-1, "Failed to init SDL_Mixer: %s", Mix_GetError());
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);
flags = MIX_INIT_MP3;
if ((flags & (x = Mix_Init(flags))) != flags)
die(-1, "Failed to init SDL_Mixer: %s", Mix_GetError());
Mix_AllocateChannels(1);
resplandescente = load_music("assets/resplandescente.mp3");
bianca_kalutor_e_o_demonio = load_music("assets/bianca_kalutor_e_o_demonio.mp3");
miau = load_chunk("assets/miau.mp3");
uai = load_chunk("assets/uai.mp3");
play_music(resplandescente, -1);
}
void mix_fini()
{
Mix_CloseAudio();
Mix_Quit();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}