-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.c
54 lines (45 loc) · 798 Bytes
/
sound.c
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
#include "common.h"
#include <SDL2/SDL_mixer.h>
static Mix_Music *music;
static Mix_Chunk *chunk;
void Sound_Init(void)
{
Mix_Init(MIX_INIT_OGG);
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT,2,1024) == -1)
{
printf("Couldn't initialize SDLMixer %s \n",SDL_GetError());
}
}
void Music_Load(const char file[])
{
if (file == NULL)
{
printf("File audio not found\n");
return;
}
music = Mix_LoadMUS(file);
if (music == NULL)
{
printf("Couldn't play audio %s\n",SDL_GetError());
return;
}
}
void Music_Play(void)
{
if (Mix_PlayMusic(music,-1) != 0)
{
printf("Couldn't play audio %s\n",SDL_GetError());
}
}
void Music_Pause(void)
{
Mix_PauseMusic();
}
void Music_Resume(void)
{
Mix_ResumeMusic();
}
void Sound_Quit(void)
{
Mix_Quit();
}