- added rules for building asm code in the gcc makefiles
[dosdemo] / src / sdl / music.c
1 #include "music.h"
2 #include "mikmod.h"
3
4 static MODULE *mod;
5 static int initialized;
6
7
8 static int init(void)
9 {
10         MikMod_RegisterAllDrivers();
11         MikMod_RegisterAllLoaders();
12
13         md_mode |= DMODE_SOFT_MUSIC | DMODE_16BITS | DMODE_STEREO | DMODE_INTERP;
14         if(MikMod_Init("") != 0) {
15                 fprintf(stderr, "mikmod init failed: %s\n",
16                                 MikMod_strerror(MikMod_errno));
17                 return -1;
18         }
19         return 0;
20 }
21
22 int music_open(const char *fname)
23 {
24         if(!initialized) {
25                 if(init() == -1) {
26                         return -1;
27                 }
28                 initialized = 1;
29         }
30
31         if(!(mod = Player_Load(fname, 64, 0))) {
32                 fprintf(stderr, "failed to load music: %s: %s\n", fname,
33                                 MikMod_strerror(MikMod_errno));
34                 return -1;
35         }
36         return 0;
37 }
38
39 void music_close(void)
40 {
41         if(mod) {
42                 music_stop();
43                 Player_Free(mod);
44                 mod = 0;
45         }
46 }
47
48 void music_play(void)
49 {
50         Player_Start(mod);
51 }
52
53 void music_stop(void)
54 {
55         Player_Stop();
56 }
57
58 void music_update(void)
59 {
60         if(Player_Active()) {
61                 MikMod_Update();
62         }
63 }