DEADSOFTWARE

headers describes that c-files implements
[flatwaifu.git] / src / music.c
index 1f0881584ba96fef761bbf69e010e22377002faf..ddd74b03c90dc56c60b8bfa041de81a102278839 100644 (file)
 */
 
 #include "glob.h"
-#include "sound.h"
+#include "files.h"
+#include "music.h"
+#include "error.h"
+#include "game.h"
 #include <SDL.h>
 #include <SDL_mixer.h>
 
 short mus_vol = 50;
-
-Mix_Music * muslo;
-
 char music_random = ON;
 int music_time = 3;
 int music_fade = 5;
 
-Uint32 muscount;
-
-int musdisabled = 1;
+static Uint32 muscount;
+static Mix_Music * muslo;
+static int musdisabled = 1;
+static int volsetcount = 0;
 
-void S_initmusic(void)
-{
+void S_initmusic (void) {
     if (!SDL_WasInit(SDL_INIT_AUDIO)) {
         if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
             fprintf(stderr, "\nUnable to initialize audio:  %s\n", SDL_GetError());
@@ -62,30 +62,28 @@ void S_initmusic(void)
    S_volumemusic(mus_vol);
 }
 
-void S_donemusic(void)
-{
-    F_freemus();
-    Mix_CloseAudio();
-    SDL_QuitSubSystem(SDL_INIT_AUDIO);
+void S_donemusic (void) {
+    if (SDL_WasInit(SDL_INIT_AUDIO)) {
+        F_freemus();
+        Mix_CloseAudio();
+        SDL_QuitSubSystem(SDL_INIT_AUDIO);
+    }
 }
 
-void S_startmusic(int time)
-{
+void S_startmusic (int time) {
     if (musdisabled) return;
     Mix_PlayMusic(muslo, -1);
     Mix_VolumeMusic(mus_vol);
     muscount=time*60*1000/DELAY;
 }
 
-void S_stopmusic(void)
-{
+void S_stopmusic (void) {
     if (musdisabled) return;
     Mix_HaltMusic();
     muscount = 0;
 }
 
-void S_volumemusic(int v)
-{
+void S_volumemusic (int v) {
     if (musdisabled) return;
     mus_vol = v;
     if (mus_vol>128) mus_vol=128;
@@ -101,7 +99,7 @@ void S_volumemusic(int v)
     }
 }
 
-struct {
+static struct {
     Uint8 ascii;
     Uint8 asciilc;
     char *ch;
@@ -141,7 +139,7 @@ struct {
     {0}
 };
 
-char *get_trans_char (Uint8 c)
+static char *get_trans_char (Uint8 c)
 {
     int i = 0;
     while (atrans[i].ascii) {
@@ -154,7 +152,7 @@ char *get_trans_char (Uint8 c)
     return NULL;
 }
 
-void trans_ascii_str (char *dest, char *src)
+static void trans_ascii_str (char *dest, char *src)
 {
     char *p = dest;
     int i;
@@ -172,27 +170,36 @@ void trans_ascii_str (char *dest, char *src)
     *p='\0';
 }
 
-void F_loadmus(char n[8]) {
+void F_loadmus (char n[8]) {
     if (musdisabled) return;
     char f[50];
+    char name[50];
 #ifndef WIN32
-    strcpy(f,"music/");
+    strcpy(f, "/usr/share/doom2d-rembo/music/");
 #else
-    strcpy(f,"music\\");
+    strcpy(f, "music\\");
 #endif
-    strncpy(&f[6], n, 8);
-    f[6+8]='\0';
-    muslo = Mix_LoadMUS(f);
-    if (muslo == NULL) {
-        char name[50];
+    int l = strlen(f);
+    strncpy(&f[l], n, 8);
+    f[l+8]='\0';
+    trans_ascii_str(name, f);
+    muslo = Mix_LoadMUS(name);
+    if (muslo == NULL)
+    {
+#ifndef WIN32
+        strcpy(f, "music/");
+        int l = strlen(f);
+        strncpy(&f[l], n, 8);
+        f[l+8]='\0';
         trans_ascii_str(name, f);
         muslo = Mix_LoadMUS(name);
-        if (!muslo) logo("Music not found '%s'\n", name);
+#endif
     }
-}
+    if (!muslo) logo("Music not found '%s'\n", name);
 
+}
 
-void F_freemus(void) {
+void F_freemus (void) {
     if (musdisabled) return;
     if (muslo) {
         Mix_HaltMusic();
@@ -201,12 +208,7 @@ void F_freemus(void) {
     muslo = NULL;
 }
 
-extern byte g_music[8];
-
-static int volsetcount = 0;
-
-void S_updatemusic()
-{
+void S_updatemusic (void) {
     if (musdisabled) return;
     
     //періодично встановлюю гучність музикі, так як вона сама підвищується до максимуму через певний час