5 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
21 #define SET_MUS_VOL(vol) \
23 int mv = (vol) * vol_master >> 9; \
24 Player_SetVolume(mv ? mv + 1 : 0); \
27 static struct au_module *curmod;
28 static int vol_master, vol_mus, vol_sfx;
31 static DWORD WINAPI upd_thread(void *cls);
33 static void *update(void *cls);
39 vol_master = vol_mus = vol_sfx = 255;
41 if(!opt.music) return 0;
43 #if defined(__linux__)
44 MikMod_RegisterDriver(&drv_alsa);
45 #elif defined(__FreeBSD__)
46 MikMod_RegisterDriver(&drv_oss);
47 #elif defined(__sgi__)
48 MikMod_RegisterDriver(&drv_sgi);
50 MikMod_RegisterDriver(&drv_ds);
52 MikMod_RegisterDriver(&drv_nos);
55 MikMod_RegisterLoader(&load_it);
56 MikMod_RegisterLoader(&load_mod);
57 MikMod_RegisterLoader(&load_s3m);
58 MikMod_RegisterLoader(&load_xm);
61 fprintf(stderr, "failed ot initialize mikmod: %s\n", MikMod_strerror(MikMod_errno));
69 if((thr = CreateThread(0, 0, upd_thread, 0, 0, 0))) {
74 if(pthread_create(&upd_thread, 0, update, 0) == 0) {
75 pthread_detach(upd_thread);
82 void au_shutdown(void)
90 struct au_module *au_load_module(const char *fname)
92 struct au_module *mod;
96 if(!(mod = malloc(sizeof *mod))) {
97 fprintf(stderr, "au_load_module: failed to allocate module\n");
101 if(!(mikmod = Player_Load(fname, 128, 0))) {
102 fprintf(stderr, "au_load_module: failed to load module: %s: %s\n",
103 fname, MikMod_strerror(MikMod_errno));
109 if(mikmod->songname && *mikmod->songname) {
110 name = alloca(strlen(mikmod->songname) + 1);
111 strcpy(name, mikmod->songname);
113 end = name + strlen(name) - 1;
114 while(end >= name && isspace(*end)) {
121 /* fallback to using the filename */
122 if((name = strrchr(fname, '/')) || (name = strrchr(fname, '\\'))) {
129 if(!(mod->name = malloc(strlen(name) + 1))) {
130 fprintf(stderr, "au_load_module: mod->name malloc failed\n");
131 Player_Free(mod->impl);
135 strcpy(mod->name, name);
137 printf("loaded module \"%s\" (%s)\n", name, fname);
141 void au_free_module(struct au_module *mod)
146 au_stop_module(curmod);
148 Player_Free(mod->impl);
153 int au_play_module(struct au_module *mod)
156 if(curmod == mod) return 0;
157 au_stop_module(curmod);
160 Player_Start(mod->impl);
161 SET_MUS_VOL(vol_mus);
170 if(!Player_Active()) {
177 static DWORD WINAPI upd_thread(void *cls)
179 static void *update(void *cls)
183 if(Player_Active()) {
195 int au_stop_module(struct au_module *mod)
197 if(mod && curmod != mod) return -1;
198 if(!curmod) return -1;
205 int au_module_state(struct au_module *mod)
208 return curmod == mod ? AU_PLAYING : AU_STOPPED;
210 return curmod ? AU_PLAYING : AU_STOPPED;
213 int au_volume(int vol)
215 AU_VOLADJ(vol_master, vol);
216 if(vol != vol_master) {
219 au_sfx_volume(vol_sfx);
220 au_music_volume(vol_mus);
225 int au_sfx_volume(int vol)
227 AU_VOLADJ(vol_sfx, vol);
233 int au_music_volume(int vol)
235 AU_VOLADJ(vol_mus, vol);