summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/audio.c17
-rw-r--r--src/audio/music.c28
-rw-r--r--src/audio/sound.c29
3 files changed, 38 insertions, 36 deletions
diff --git a/src/audio/audio.c b/src/audio/audio.c
index 0d9b0a2..9d629eb 100644
--- a/src/audio/audio.c
+++ b/src/audio/audio.c
@@ -29,17 +29,19 @@ void initAudio()
fprintf(stderr, _("Unable to initialize audio: %s\n"), SDL_GetError());
return;
}
- if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) ==
- -1) {
+
+ if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
+ {
fprintf(stderr, _("Unable to create proper audio settings: %s\n"),
Mix_GetError());
return;
}
+
Mix_AllocateChannels(16);
Mix_Volume(-1, MIX_MAX_VOLUME);
-#ifdef DEBUG
- printf(_("Initializing audio system...\n"));
-#endif
+
+ DEBUG_MSG(_("Initializing audio system...\n"));
+
isAudioInit = TRUE;
}
@@ -50,7 +52,6 @@ void quitAudio()
{
Mix_CloseAudio();
isAudioInit = TRUE;
-#ifdef DEBUG
- printf(_("Quitting audio...\n"));
-#endif
+
+ DEBUG_MSG(_("Quitting audio...\n"));
}
diff --git a/src/audio/music.c b/src/audio/music.c
index 04de359..5af9dda 100644
--- a/src/audio/music.c
+++ b/src/audio/music.c
@@ -32,17 +32,19 @@ void initMusic()
isMusicInit = FALSE;
return;
}
+
listStorage = newStorage();
currentMusic = NULL;
isMusicInit = TRUE;
var_isMusicActive = TRUE;
+
if (isParamFlag("--nomusic"))
setMusicActive(FALSE);
+
if (isParamFlag("--music"))
setMusicActive(TRUE);
-#ifdef DEBUG
- printf(_("Initializing music...\n"));
-#endif
+
+ DEBUG_MSG(_("Initializing music...\n"));
}
/*
@@ -53,9 +55,7 @@ static Mix_Music *loadMixMusic(char *file)
Mix_Music *mixer;
char str[STR_PATH_SIZE];
-#ifdef DEBUG
- printf(_("Loading music file: %s\n"), file);
-#endif
+ DEBUG_MSG(_("Loading music file: %s\n"), file);
if (isFillPath(file)) {
strcpy(str, file);
@@ -98,6 +98,7 @@ static void destroyMusic(void *p)
void addMusic(char *file, char *name, char *group)
{
Mix_Music *new;
+
if (isMusicInit == FALSE)
return;
@@ -118,9 +119,8 @@ void stopMusic()
return;
if (currentMusic != NULL) {
-#ifdef DEBUG
- printf(_("Stopping music...\n"));
-#endif
+ DEBUG_MSG(_("Stopping music...\n"));
+
Mix_HaltMusic();
currentMusic = NULL;
}
@@ -158,9 +158,8 @@ void playMusic(char *name, char *group)
strcpy(currentMusic_name, name);
if (currentMusic != NULL) {
-#ifdef DEBUG
- printf(_("Playing music file %s\n"), name);
-#endif
+ DEBUG_MSG(_("Playing music file %s\n"), name);
+
playMixMusic();
}
}
@@ -221,7 +220,6 @@ void quitMusic()
stopMusic();
destroyStorage(listStorage, destroyMusic);
isMusicInit = FALSE;
-#ifdef DEBUG
- printf(_("Quitting music...\n"));
-#endif
+
+ DEBUG_MSG(_("Quitting music...\n"));
}
diff --git a/src/audio/sound.c b/src/audio/sound.c
index c96e3ac..63d4566 100644
--- a/src/audio/sound.c
+++ b/src/audio/sound.c
@@ -34,13 +34,15 @@ void initSound()
listStorage = newStorage();
isSoundInit = TRUE;
var_isSoundActive = TRUE;
+
if (isParamFlag("--nosound"))
setSoundActive(FALSE);
+
if (isParamFlag("--sound"))
setSoundActive(TRUE);
-#ifdef DEBUG
- printf(_("Initializing sound...\n"));
-#endif
+
+ DEBUG_MSG(_("Initializing sound...\n"));
+
}
/*
@@ -51,17 +53,17 @@ static Mix_Chunk *loadMixSound(char *file)
Mix_Chunk *new;
char str[STR_PATH_SIZE];
-#ifdef DEBUG
- printf(_("Loading sound file: %s\n"), file);
-#endif
+ DEBUG_MSG(_("Loading sound file: %s\n"), file);
+
sprintf(str, PATH_SOUND "%s", file);
accessExistFile(str);
new = Mix_LoadWAV(str);
+
if (new == NULL) {
- fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"),
- str, Mix_GetError());
+ fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"), str, Mix_GetError());
return NULL;
}
+
return new;
}
@@ -71,8 +73,7 @@ static Mix_Chunk *loadMixSound(char *file)
static void playMixSound(Mix_Chunk * p)
{
if (Mix_PlayChannel(-1, p, 0) == -1) {
- fprintf(stderr, _("Unable to playback sound with error: %s\n"),
- Mix_GetError());
+ fprintf(stderr, _("Unable to playback sound with error: %s\n"), Mix_GetError());
return;
}
}
@@ -94,9 +95,11 @@ void addSound(char *file, char *name, char *group)
if (isSoundInit == FALSE)
return;
+
assert(file != NULL);
assert(name != NULL);
assert(group != NULL);
+
new = loadMixSound(file);
addItemToStorage(listStorage, group, name, new);
}
@@ -108,6 +111,7 @@ void playSound(char *name, char *group)
{
if (isSoundInit == FALSE || var_isSoundActive == FALSE)
return;
+
playMixSound(getItemFromStorage(listStorage, group, name));
}
@@ -136,7 +140,6 @@ void quitSound()
return;
destroyStorage(listStorage, destroySound);
isSoundInit = FALSE;
-#ifdef DEBUG
- printf(_("Quitting sound...\n"));
-#endif
+
+ DEBUG_MSG(_("Quitting sound...\n"));
}