diff options
| author | xHire <xhire@tuxportal.cz> | 2009-04-25 17:36:10 +0200 |
|---|---|---|
| committer | xHire <xhire@tuxportal.cz> | 2009-05-26 01:08:37 +0200 |
| commit | 9ab82c4ad5eeedd66b768db9f27bfd097d3284e8 (patch) | |
| tree | 793083d28c6d7591e919307be56789b1b3d7ef5a /src | |
| parent | eab321fa21828fe1aaaa03e4be4583cb70695acf (diff) | |
Rewritten messages/comments in audio code
Rectified the coding style in audio code
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio/audio.c | 21 | ||||
| -rw-r--r-- | src/audio/audio.h | 8 | ||||
| -rw-r--r-- | src/audio/music.c | 56 | ||||
| -rw-r--r-- | src/audio/music.h | 20 | ||||
| -rw-r--r-- | src/audio/sound.c | 43 | ||||
| -rw-r--r-- | src/audio/sound.h | 20 |
6 files changed, 86 insertions, 82 deletions
diff --git a/src/audio/audio.c b/src/audio/audio.c index 59e0cb1..829c510 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <assert.h> #include <SDL_mixer.h> @@ -10,7 +9,7 @@ static bool_t isAudioInit = FALSE; /* - * Returns state of audio + * Return status of audio */ bool_t audio_is_inicialized() { @@ -26,33 +25,31 @@ void audio_init() return; } + DEBUG_MSG(_("[Debug] Initializing audio\n")); + if (SDL_Init(SDL_INIT_AUDIO) == -1) { - fprintf(stderr, _("Error! Unable to initialize audio: %s\n"), SDL_GetError()); + fprintf(stderr, _("[Error] Unable to initialize audio: %s\n"), SDL_GetError()); return; } - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1) - { - fprintf(stderr, _("Unable to create proper audio settings: %s\n"), - Mix_GetError()); + if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { + fprintf(stderr, _("[Error] Unable to create proper audio settings: %s\n"), Mix_GetError()); return; } Mix_AllocateChannels(16); Mix_Volume(-1, MIX_MAX_VOLUME); - DEBUG_MSG(_("Initializing audio\n")); - isAudioInit = TRUE; } /* - * Quit audio + * Shutdown audio */ void audio_quit() { + DEBUG_MSG(_("[Debug] Shutting down audio\n")); + Mix_CloseAudio(); isAudioInit = TRUE; - - DEBUG_MSG(_("Quitting audio\n")); } diff --git a/src/audio/audio.h b/src/audio/audio.h index 65620e7..cc0b197 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -1,10 +1,10 @@ - #ifndef AUDIO_H -# define AUDIO_H +#define AUDIO_H -# include "main.h" +#include "main.h" extern bool_t audio_is_inicialized(); extern void audio_init(); extern void audio_quit(); -#endif + +#endif /* AUDIO_H */ diff --git a/src/audio/music.c b/src/audio/music.c index 1b526c6..2d2194f 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <assert.h> @@ -17,7 +16,7 @@ static bool_t var_music_is_active = TRUE; static Mix_Music *currentMusic; /* - * Return state of music initialization + * Return status of music */ bool_t music_is_inicialized() { @@ -34,18 +33,18 @@ void music_init() return; } + DEBUG_MSG(_("[Debug] Initializing music\n")); + listStorage = storage_new(); currentMusic = NULL; isMusicInit = TRUE; var_music_is_active = TRUE; - if (isParamFlag("--no-music")) + if (isParamFlag("--no-music")) { music_set_active(FALSE); - - if (isParamFlag("--music")) + } else if (isParamFlag("--music")) { music_set_active(TRUE); - - DEBUG_MSG(_("Initializing music\n")); + } } /* @@ -56,7 +55,7 @@ static Mix_Music *loadMixMusic(char *file) Mix_Music *mixer; char str[STR_PATH_SIZE]; - DEBUG_MSG(_("Loading a file with music: %s\n"), file); + DEBUG_MSG(_("[Debug] Loading music [%s]\n"), file); if (isFillPath(file)) { strcpy(str, file); @@ -69,7 +68,7 @@ static Mix_Music *loadMixMusic(char *file) mixer = Mix_LoadMUS(str); if (mixer == NULL) { - fprintf(stderr, _("Unable to load music from file %s\n"), file); + fprintf(stderr, _("[Error] Unable to load music [%s]\n"), file); return NULL; } @@ -77,7 +76,7 @@ static Mix_Music *loadMixMusic(char *file) } /* - * Prepare music mixer + * Prepare the music mixer */ static void playMixMusic() { @@ -87,7 +86,7 @@ static void playMixMusic() } /* - * Free memory of music + * Remove music from the memory */ static void destroyMusic(void *p) { @@ -95,14 +94,15 @@ static void destroyMusic(void *p) } /* - * Add file to list with music + * Add a file to the music list */ void music_add(char *file, char *name, char *group) { Mix_Music *new; - if (isMusicInit == FALSE) + if (isMusicInit == FALSE) { return; + } assert(file != NULL); assert(name != NULL); @@ -113,7 +113,7 @@ void music_add(char *file, char *name, char *group) } /* - * Disable music and stop playback + * Stop playing music */ void music_stop() { @@ -122,7 +122,7 @@ void music_stop() } if (currentMusic != NULL) { - DEBUG_MSG(_("Stopping music\n")); + DEBUG_MSG(_("[Debug] Stopping playing music\n")); Mix_HaltMusic(); currentMusic = NULL; @@ -144,8 +144,9 @@ void music_play(char *name, char *group) isStrInit = 1; } - if (isMusicInit == FALSE || var_music_is_active == FALSE) + if (isMusicInit == FALSE || var_music_is_active == FALSE) { return; + } if (currentMusic != NULL && strcmp(currentMusic_group, group) == 0 && @@ -162,7 +163,7 @@ void music_play(char *name, char *group) strcpy(currentMusic_name, name); if (currentMusic != NULL) { - DEBUG_MSG(_("Playing music from file %s\n"), name); + DEBUG_MSG(_("[Debug] Playing music [%s]\n"), name); playMixMusic(); } @@ -178,8 +179,7 @@ void music_set_active(bool_t n) if (n == FALSE) { music = currentMusic; music_stop(); - } - if (n == TRUE) { + } else if (n == TRUE) { currentMusic = music; playMixMusic(); } @@ -188,7 +188,7 @@ void music_set_active(bool_t n) } /* - * Return status of music + * Return the activity status of music */ bool_t music_is_active() { @@ -196,7 +196,7 @@ bool_t music_is_active() } /* - * TOCOMMENT + * Return the music playing right now */ char *music_get_current() { @@ -204,27 +204,29 @@ char *music_get_current() } /* - * TOCOMMENT + * Remove all music files belonging to the certain group */ void music_del_all_in_group(char *group) { - if (isMusicInit == FALSE) + if (isMusicInit == FALSE) { return; + } storage_del_all(listStorage, group, destroyMusic); } /* - * Deactivate all what is ment for music + * Shutdown music */ void music_quit() { - if (isMusicInit == FALSE) + if (isMusicInit == FALSE) { return; + } + + DEBUG_MSG(_("[Debug] Shutting down music\n")); music_stop(); storage_destroy(listStorage, destroyMusic); isMusicInit = FALSE; - - DEBUG_MSG(_("Quitting music\n")); } diff --git a/src/audio/music.h b/src/audio/music.h index cb5995d..9eedac7 100644 --- a/src/audio/music.h +++ b/src/audio/music.h @@ -1,12 +1,13 @@ - #ifndef MUSIC_H -# define MUSIC_H -# ifndef NO_SOUND -# include <SDL_mixer.h> -# include "main.h" +#define MUSIC_H + +#ifndef NO_SOUND -# define MUSIC_GROUP_BASE "base" -# define MUSIC_GROUP_USER "user" +#include <SDL_mixer.h> +#include "main.h" + +#define MUSIC_GROUP_BASE "base" +#define MUSIC_GROUP_USER "user" /* typedef struct music_struct @@ -27,5 +28,6 @@ extern bool_t music_is_active(); extern char *music_get_current(); extern void music_del_all_in_group(char *group); extern void music_quit(); -# endif -#endif + +#endif /* NO_SOUND */ +#endif /* MUSIC_H */ diff --git a/src/audio/sound.c b/src/audio/sound.c index 8d368a3..58a78ba 100644 --- a/src/audio/sound.c +++ b/src/audio/sound.c @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> #include <assert.h> @@ -32,18 +31,17 @@ void sound_init() return; } + DEBUG_MSG(_("[Debug] Initializing sound\n")); + listStorage = storage_new(); isSoundInit = TRUE; var_sound_is_active = TRUE; - if (isParamFlag("--no-sound")) + if (isParamFlag("--no-sound")) { sound_set_active(FALSE); - - if (isParamFlag("--sound")) + } else if (isParamFlag("--sound")) { sound_set_active(TRUE); - - DEBUG_MSG(_("Initializing sound\n")); - + } } /* @@ -54,14 +52,14 @@ static Mix_Chunk *loadMixSound(char *file) Mix_Chunk *new; char str[STR_PATH_SIZE]; - DEBUG_MSG(_("Loading sound file: %s\n"), file); + DEBUG_MSG(_("[Debug] Loading sound [%s]\n"), file); sprintf(str, PATH_SOUND "%s", file); accessExistFile(str); new = Mix_LoadWAV(str); if (new == NULL) { - fprintf(stderr, _("Unable to load sound from file %s with error: %s\n"), str, Mix_GetError()); + fprintf(stderr, _("[Error] Unable to load sound [%s]: %s\n"), str, Mix_GetError()); return NULL; } @@ -71,10 +69,10 @@ static Mix_Chunk *loadMixSound(char *file) /* * Play sound with mixer */ -static void playMixSound(Mix_Chunk * p) +static void playMixSound(Mix_Chunk *p) { if (Mix_PlayChannel(-1, p, 0) == -1) { - fprintf(stderr, _("Unable to play sound with error: %s\n"), Mix_GetError()); + fprintf(stderr, _("[Error] Unable to play sound: %s\n"), Mix_GetError()); return; } } @@ -88,14 +86,15 @@ static void destroySound(void *p) } /* - * Add sound to list + * Add a sound to list */ void sound_add(char *file, char *name, char *group) { Mix_Chunk *new; - if (isSoundInit == FALSE) + if (isSoundInit == FALSE) { return; + } assert(file != NULL); assert(name != NULL); @@ -106,18 +105,19 @@ void sound_add(char *file, char *name, char *group) } /* - * Start playback file from list + * Start playing a sound from a file from the list */ void sound_play(char *name, char *group) { - if (isSoundInit == FALSE || var_sound_is_active == FALSE) + if (isSoundInit == FALSE || var_sound_is_active == FALSE) { return; + } playMixSound(storage_get(listStorage, group, name)); } /* - * Set if sound is active True/False + * Set sound status to active/inactive (true/false) */ void sound_set_active(bool_t n) { @@ -125,7 +125,7 @@ void sound_set_active(bool_t n) } /* - * Return state of sound + * Return status of sound */ bool_t sound_is_active() { @@ -133,15 +133,16 @@ bool_t sound_is_active() } /* - * Quit all sound stuff + * Shutdown sound */ void sound_quit() { - if (isSoundInit == FALSE) + if (isSoundInit == FALSE) { return; + } + + DEBUG_MSG(_("[Debug] Shutting down sound\n")); storage_destroy(listStorage, destroySound); isSoundInit = FALSE; - - DEBUG_MSG(_("Quitting sound\n")); } diff --git a/src/audio/sound.h b/src/audio/sound.h index 4c61bcd..f8cf2d3 100644 --- a/src/audio/sound.h +++ b/src/audio/sound.h @@ -1,12 +1,13 @@ - #ifndef SOUND_H -# define SOUND_H -# ifndef NO_SOUND -# include <SDL_mixer.h> -# include "main.h" +#define SOUND_H + +#ifndef NO_SOUND -# define SOUND_GROUP_BASE "base" -# define SOUND_GROUP_USER "user" +#include <SDL_mixer.h> +#include "main.h" + +#define SOUND_GROUP_BASE "base" +#define SOUND_GROUP_USER "user" /* typedef struct sound_struct @@ -24,5 +25,6 @@ extern void sound_play(char *name, char *group); extern void sound_set_active(bool_t n); extern bool_t sound_is_active(); extern void sound_quit(); -# endif -#endif + +#endif /* NO_SOUND */ +#endif /* SOUND_H */ |