5 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
20 #define SET_MUS_VOL(vol) \
22 int mv = (vol) * vol_master >> 9; \
23 Player_SetVolume(mv ? mv + 1 : 0); \
26 static struct au_module *curmod;
27 static int vol_master, vol_mus, vol_sfx;
30 static DWORD WINAPI upd_thread(void *cls);
32 static void *update(void *cls);
38 vol_master = vol_mus = vol_sfx = 255;
40 #if defined(__linux__)
41 MikMod_RegisterDriver(&drv_alsa);
42 #elif defined(__FreeBSD__)
43 MikMod_RegisterDriver(&drv_oss);
44 #elif defined(__sgi__)
45 MikMod_RegisterDriver(&drv_sgi);
47 MikMod_RegisterDriver(&drv_ds);
49 MikMod_RegisterDriver(&drv_nos);
52 MikMod_RegisterLoader(&load_it);
53 MikMod_RegisterLoader(&load_mod);
54 MikMod_RegisterLoader(&load_s3m);
55 MikMod_RegisterLoader(&load_xm);
58 fprintf(stderr, "failed ot initialize mikmod: %s\n", MikMod_strerror(MikMod_errno));
66 if((thr = CreateThread(0, 0, upd_thread, 0, 0, 0))) {
71 if(pthread_create(&upd_thread, 0, update, 0) == 0) {
72 pthread_detach(upd_thread);
79 void au_shutdown(void)
85 struct au_module *au_load_module(const char *fname)
87 struct au_module *mod;
91 if(!(mod = malloc(sizeof *mod))) {
92 fprintf(stderr, "au_load_module: failed to allocate module\n");
96 if(!(mikmod = Player_Load(fname, 128, 0))) {
97 fprintf(stderr, "au_load_module: failed to load module: %s: %s\n",
98 fname, MikMod_strerror(MikMod_errno));
104 if(mikmod->songname && *mikmod->songname) {
105 name = alloca(strlen(mikmod->songname) + 1);
106 strcpy(name, mikmod->songname);
108 end = name + strlen(name) - 1;
109 while(end >= name && isspace(*end)) {
116 /* fallback to using the filename */
117 if((name = strrchr(fname, '/')) || (name = strrchr(fname, '\\'))) {
124 if(!(mod->name = malloc(strlen(name) + 1))) {
125 fprintf(stderr, "au_load_module: mod->name malloc failed\n");
126 Player_Free(mod->impl);
130 strcpy(mod->name, name);
132 printf("loaded module \"%s\" (%s)\n", name, fname);
136 void au_free_module(struct au_module *mod)
141 au_stop_module(curmod);
143 Player_Free(mod->impl);
148 int au_play_module(struct au_module *mod)
151 if(curmod == mod) return 0;
152 au_stop_module(curmod);
155 Player_Start(mod->impl);
156 SET_MUS_VOL(vol_mus);
165 if(!Player_Active()) {
172 static DWORD WINAPI upd_thread(void *cls)
174 static void *update(void *cls)
178 if(Player_Active()) {
190 int au_stop_module(struct au_module *mod)
192 if(mod && curmod != mod) return -1;
193 if(!curmod) return -1;
200 int au_module_state(struct au_module *mod)
203 return curmod == mod ? AU_PLAYING : AU_STOPPED;
205 return curmod ? AU_PLAYING : AU_STOPPED;
208 int au_volume(int vol)
210 AU_VOLADJ(vol_master, vol);
211 if(vol != vol_master) {
214 au_sfx_volume(vol_sfx);
215 au_music_volume(vol_mus);
220 int au_sfx_volume(int vol)
222 AU_VOLADJ(vol_sfx, vol);
228 int au_music_volume(int vol)
230 AU_VOLADJ(vol_mus, vol);