-
Notifications
You must be signed in to change notification settings - Fork 0
/
son.c
34 lines (30 loc) · 808 Bytes
/
son.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
// son.c
#include <SDL.h>
#include "son.h"
static Mix_Music * music = NULL;
int ahInitAudio(const char * musicFile) {
if(SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Erreur lors de l'initialisation de SDL_AUDIO : %s\n", SDL_GetError());
return 0;
}
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
fprintf(stderr, "Erreur lors de l'initialisation de Mix_OpenAudio : %s\n", Mix_GetError());
return 0;
}
if(!(music = Mix_LoadMUS(musicFile))) {
fprintf(stderr, "Erreur lors de la lecture du fichier %s : %s\n", musicFile, Mix_GetError());
return 0;
}
return 1;
}
void ahPlayMusic() {
Mix_PlayMusic(music, -1);
}
void ahClean() {
if(music) {
Mix_FreeMusic(music);
music = NULL;
}
Mix_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}