diff options
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/audio.c | 35 | ||||
| -rw-r--r-- | src/audio/audio.h | 16 | ||||
| -rw-r--r-- | src/audio/music.c | 165 | ||||
| -rw-r--r-- | src/audio/music.h | 61 | ||||
| -rw-r--r-- | src/audio/sound.c | 103 | ||||
| -rw-r--r-- | src/audio/sound.h | 55 |
6 files changed, 209 insertions, 226 deletions
diff --git a/src/audio/audio.c b/src/audio/audio.c index 8397788..9436791 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -8,37 +8,42 @@ #include "interface.h" static bool_t isAudioInit = FALSE; - +/* + * Returns state of audio + */ bool_t isAudioInicialized() { return isAudioInit; } - +/* + * Inicialize audio + */ void initAudio() { - if( SDL_Init(SDL_INIT_AUDIO) == -1 ) - { - fprintf(stderr, "Nelze inicializovat audio : %s\n", SDL_GetError()); + if (SDL_Init(SDL_INIT_AUDIO) == -1) { + fprintf(stderr, _("Unable to initialize audio: %s\n"), SDL_GetError()); return; } - - if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1 ) - { - fprintf(stderr, "Nelze inicializovat audio : %s\n", Mix_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()); + return; } - Mix_AllocateChannels(16); Mix_Volume(-1, MIX_MAX_VOLUME); - - printf("init audio..\n"); +#ifdef DEBUG + printf(_("Initializing audio system...\n")); +#endif isAudioInit = TRUE; } - +/* + * Quit audio + */ void quitAudio() { Mix_CloseAudio(); isAudioInit = TRUE; - printf("quit audio..\n"); +#ifdef DEBUG + printf(_("Quitting audio...\n")); +#endif } diff --git a/src/audio/audio.h b/src/audio/audio.h index 242bb9a..4a79d5f 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -1,12 +1,10 @@ #ifndef AUDIO_H - -#define AUDIO_H - -#include "main.h" - -extern bool_t isAudioInicialized(); -extern void initAudio(); -extern void quitAudio(); - + #define AUDIO_H + + #include "main.h" + + extern bool_t isAudioInicialized(); + extern void initAudio(); + extern void quitAudio(); #endif diff --git a/src/audio/music.c b/src/audio/music.c index cf3db24..f2ac6e1 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -6,9 +6,7 @@ #include "main.h" #include "list.h" #include "storage.h" - #include "interface.h" - #include "audio.h" #include "music.h" @@ -17,199 +15,194 @@ static list_t *listStorage; static bool_t isMusicInit = FALSE; static bool_t var_isMusicActive = TRUE; static Mix_Music *currentMusic; - +/* + * Return state of music initialization + */ bool_t isMusicInicialized() { return isMusicInit; } - +/* + * Initialize music + */ void initMusic() { - if( isAudioInicialized() == FALSE ) - { + if (isAudioInicialized() == FALSE) { isMusicInit = FALSE; return; } - listStorage = newStorage(); currentMusic = NULL; - isMusicInit = TRUE; var_isMusicActive = TRUE; - - if( isParamFlag("--nomusic") ) - { + if (isParamFlag("--nomusic")) setMusicActive(FALSE); - } - - if( isParamFlag("--music") ) - { + if (isParamFlag("--music")) setMusicActive(TRUE); - } - - printf("init music..\n"); +#ifdef DEBUG + printf(_("Initializing music...\n")); +#endif } - +/* + * Load music file and returns it + */ static Mix_Music* loadMixMusic(char *file) { - Mix_Music *new; + Mix_Music *mixer; char str[STR_PATH_SIZE]; - - - printf("load music %s..\n", file); +#ifdef DEBUG + printf(_("Loading music file: %s\n"), file); +#endif sprintf(str, PATH_MUSIC "%s", file); - accessExistFile(str); - - new = Mix_LoadMUS(str); - - if( new == NULL ) - { - fprintf(stderr, "Nepodarilo sa nacitat hudbu %s\n", file); + mixer = Mix_LoadMUS(str); + if( mixer == NULL ) { + fprintf(stderr, _("Unable to load music from file: %s\n"), file); return NULL; } - return new; + return mixer; } - +/* + * Prepare music mixer + */ static void playMixMusic() { - if( currentMusic != NULL ) - { + if (currentMusic != NULL) Mix_PlayMusic(currentMusic, 1000); - } } - +/* + * Free memory of music + */ static void destroyMusic(void *p) { Mix_FreeMusic((Mix_Music *)p); } - +/* + * Add file to list with music + */ void addMusic(char *file, char *name, char *group) { Mix_Music *new; - - if( isMusicInit == FALSE ) - { + if (isMusicInit == FALSE) return; - } assert( file != NULL ); assert( name != NULL ); assert( group != NULL ); new = loadMixMusic(file); - addItemToStorage(listStorage, group, name, new ); } - +/* + * Disable music and stop playback + */ void stopMusic() { - if( isMusicInit == FALSE || - var_isMusicActive == FALSE ) - { + if (isMusicInit == FALSE || + var_isMusicActive == FALSE) return; - } - if( currentMusic != NULL ) - { - printf("stop music..\n"); + if (currentMusic != NULL) { +#ifdef DEBUG + printf(_("Stopping music...\n")); +#endif Mix_HaltMusic(); currentMusic = NULL; } } - +/* + * start music playback + */ void playMusic(char *name, char *group) { static char currentMusic_group[STR_SIZE]; static char currentMusic_name[STR_SIZE]; static int isStrInit = 0; - if( isStrInit == 0 ) - { + if (isStrInit == 0) { strcpy(currentMusic_group, "none"); strcpy(currentMusic_name, "none"); isStrInit = 1; } - if( isMusicInit == FALSE || - var_isMusicActive == FALSE ) - { + if (isMusicInit == FALSE || + var_isMusicActive == FALSE) return; - } - if( currentMusic != NULL && - strcmp(currentMusic_group, group) == 0 && - strcmp(currentMusic_name, name) == 0 ) - { + if (currentMusic != NULL && + strcmp(currentMusic_group, group) == 0 && + strcmp(currentMusic_name, name) == 0) { return; } - if( currentMusic != NULL ) - { + if (currentMusic != NULL) stopMusic(); - } currentMusic = getItemFromStorage(listStorage, group, name); strcpy(currentMusic_group, group); strcpy(currentMusic_name, name); - if( currentMusic != NULL ) - { - printf("play music %s\n", name); + if( currentMusic != NULL ) { +#ifdef DEBUG + printf(_("Playing music file %s\n"), name); +#endif playMixMusic(); } } - +/* + * Set music active/deactivated + */ void setMusicActive(bool_t n) { static Mix_Music *music = NULL; - if( n == FALSE ) - { + if (n == FALSE) { music = currentMusic; stopMusic(); } - - if( n == TRUE ) - { + if (n == TRUE) { currentMusic = music; playMixMusic(); } var_isMusicActive = n; } - +/* + * Return status of music + */ bool_t isMusicActive() { return var_isMusicActive; } - +/* + * TOCOMMENT + */ char* getCurrentMusic() { return "unknown"; } - +/* + * TOCOMMENT + */ void delAllMusicInGroup(char *group) { - if( isMusicInit == FALSE ) - { + if (isMusicInit == FALSE) return; - } - delAllItemFromStorage(listStorage, group, destroyMusic); } - +/* + * Deactivate all what is ment for music + */ void quitMusic() { - if( isMusicInit == FALSE ) - { + if (isMusicInit == FALSE) return; - } stopMusic(); destroyStorage(listStorage, destroyMusic); isMusicInit = FALSE; - - printf("quit music..\n"); +#ifdef DEBUG + printf(_("Quitting music...\n")); +#endif } diff --git a/src/audio/music.h b/src/audio/music.h index 0ae83c4..2cbdc15 100644 --- a/src/audio/music.h +++ b/src/audio/music.h @@ -1,36 +1,31 @@ #ifndef MUSIC_H - -#define MUSIC_H - -#ifndef NO_SOUND - -#include <SDL_mixer.h> -#include "main.h" - -#define MUSIC_GROUP_BASE "base" -#define MUSIC_GROUP_USER "user" - -/* -typedef struct music_struct -{ - char *name; - int group; - Mix_Music *music; -} music_t; -*/ - -extern bool_t isMusicInicialized(); -extern void initMusic(); -extern void addMusic(char *file, char *name, char *group); -extern void stopMusic(); -extern void playMusic(char *name, char *group); -extern void setMusicActive(bool_t n); -extern bool_t isMusicActive(); -extern char* getCurrentMusic(); -extern void delAllMusicInGroup(char *group); -extern void quitMusic(); - -#endif - + #define MUSIC_H + #ifndef NO_SOUND + #include <SDL_mixer.h> + #include "main.h" + + #define MUSIC_GROUP_BASE "base" + #define MUSIC_GROUP_USER "user" + + /* + typedef struct music_struct + { + char *name; + int group; + Mix_Music *music; + } music_t; + */ + + extern bool_t isMusicInicialized(); + extern void initMusic(); + extern void addMusic(char *file, char *name, char *group); + extern void stopMusic(); + extern void playMusic(char *name, char *group); + extern void setMusicActive(bool_t n); + extern bool_t isMusicActive(); + extern char* getCurrentMusic(); + extern void delAllMusicInGroup(char *group); + extern void quitMusic(); + #endif #endif diff --git a/src/audio/sound.c b/src/audio/sound.c index 652de67..72d1584 100644 --- a/src/audio/sound.c +++ b/src/audio/sound.c @@ -6,26 +6,26 @@ #include "main.h" #include "list.h" #include "storage.h" - #include "interface.h" - #include "audio.h" #include "sound.h" static list_t *listStorage; - static bool_t isSoundInit = FALSE; static bool_t var_isSoundActive = TRUE; - +/* + * Return state of sound + */ bool_t isSoundInicialized() { return isSoundInit; } - +/* + * Audio initialization + */ void initSound() { - if( isAudioInicialized() == FALSE ) - { + if( isAudioInicialized() == FALSE ) { isSoundInit = FALSE; return; } @@ -33,105 +33,102 @@ void initSound() listStorage = newStorage(); isSoundInit = TRUE; var_isSoundActive = TRUE; - - if( isParamFlag("--nosound") ) - { + if (isParamFlag("--nosound")) setSoundActive(FALSE); - } - - if( isParamFlag("--sound") ) - { + if (isParamFlag("--sound")) setSoundActive(TRUE); - } - - printf("init sound..\n"); +#ifdef DEBUG + printf(_("Initializing sound...\n")); +#endif } - +/* + * Load sound file (Null/mixer) + */ static Mix_Chunk* loadMixSound(char *file) { Mix_Chunk *new; char str[STR_PATH_SIZE]; - - printf("load sound %s..\n", file); +#ifdef DEBUG + printf("Loading sound file: %s\n", file); +#endif sprintf(str, PATH_SOUND "%s", file); - accessExistFile(str); - new = Mix_LoadWAV(str); - - if( new == NULL ) - { - fprintf(stderr, "Nelze nahrat zvuk %s : %s\n", str, Mix_GetError()); + if (new == NULL) { + fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"), str, Mix_GetError()); return NULL; } - return new; } - +/* + * Play sound with mixer + */ static void playMixSound(Mix_Chunk *p) { - if( Mix_PlayChannel(-1, p, 0) == -1 ) - { - fprintf(stderr, "Nelze prehrat zvuk : %s\n", Mix_GetError()); + if (Mix_PlayChannel(-1, p, 0) == -1) { + fprintf(stderr, _("Unable to playback sound with error: %s\n"), Mix_GetError()); return; } } - +/* + * Destroy mixer chunk + */ static void destroySound(void *p) { Mix_FreeChunk((Mix_Chunk *)p); } - +/* + * Add sound to list + */ void addSound(char *file, char *name, char *group) { Mix_Chunk *new; - if( isSoundInit == FALSE ) - { + if (isSoundInit == FALSE) return; - } - assert( file != NULL ); assert( name != NULL ); assert( group != NULL ); - new = loadMixSound(file); - addItemToStorage(listStorage, group, name, new ); } - +/* + * Start playback file from list + */ void playSound(char *name, char *group) { - if( isSoundInit == FALSE || - var_isSoundActive == FALSE ) - { + if (isSoundInit == FALSE || + var_isSoundActive == FALSE) return; - } - - playMixSound( getItemFromStorage(listStorage, group, name) ); + playMixSound(getItemFromStorage(listStorage, group, name)); } - +/* + * Set if sound is active True/False + */ void setSoundActive(bool_t n) { var_isSoundActive = n; } - +/* + * Return state of sound + */ bool_t isSoundActive() { return var_isSoundActive; } - +/* + * Quit all sound stuff + */ void quitSound() { if( isSoundInit == FALSE ) - { return; - } - destroyStorage(listStorage, destroySound); isSoundInit = FALSE; - printf("quit sound..\n"); +#ifdef DEBUG + printf(_("Quitting sound...\n")); +#endif } diff --git a/src/audio/sound.h b/src/audio/sound.h index 337ef3b..0bc0954 100644 --- a/src/audio/sound.h +++ b/src/audio/sound.h @@ -1,33 +1,28 @@ #ifndef SOUND_H - -#define SOUND_H - -#ifndef NO_SOUND - -#include <SDL_mixer.h> -#include "main.h" - -#define SOUND_GROUP_BASE "base" -#define SOUND_GROUP_USER "user" - -/* -typedef struct sound_struct -{ - char *name; - int group; - Mix_Chunk *sound; -} sound_t; -*/ - -extern bool_t isSoundInicialized(); -extern void initSound(); -extern void addSound(char *file, char *name, char *group); -extern void playSound(char *name, char *group); -extern void setSoundActive(bool_t n); -extern bool_t isSoundActive(); -extern void quitSound(); - -#endif - + #define SOUND_H + #ifndef NO_SOUND + #include <SDL_mixer.h> + #include "main.h" + + #define SOUND_GROUP_BASE "base" + #define SOUND_GROUP_USER "user" + + /* + typedef struct sound_struct + { + char *name; + int group; + Mix_Chunk *sound; + } sound_t; + */ + + extern bool_t isSoundInicialized(); + extern void initSound(); + extern void addSound(char *file, char *name, char *group); + extern void playSound(char *name, char *group); + extern void setSoundActive(bool_t n); + extern bool_t isSoundActive(); + extern void quitSound(); + #endif #endif |