diff options
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/audio.c | 54 | ||||
| -rw-r--r-- | src/audio/music.c | 258 | ||||
| -rw-r--r-- | src/audio/sound.c | 136 |
3 files changed, 246 insertions, 202 deletions
diff --git a/src/audio/audio.c b/src/audio/audio.c index cc9d81e..15ad6f7 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -11,44 +11,50 @@ static bool_t isAudioInit = FALSE; /* * Returns state of audio */ -bool_t isAudioInicialized() +bool_t +isAudioInicialized() { - return isAudioInit; + return isAudioInit; } + /* * Inicialize audio */ -void initAudio() +void +initAudio() { - if( isParamFlag("--noaudio") ) - { - return; - } + if (isParamFlag("--noaudio")) { + return; + } - 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, _("Unable to create proper audio settings: %s\n"), Mix_GetError()); - return; - } - Mix_AllocateChannels(16); - Mix_Volume(-1, MIX_MAX_VOLUME); + 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, _("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")); + printf(_("Initializing audio system...\n")); #endif - isAudioInit = TRUE; + isAudioInit = TRUE; } + /* * Quit audio */ -void quitAudio() +void +quitAudio() { - Mix_CloseAudio(); - isAudioInit = TRUE; + Mix_CloseAudio(); + isAudioInit = TRUE; #ifdef DEBUG - printf(_("Quitting audio...\n")); + printf(_("Quitting audio...\n")); #endif } - diff --git a/src/audio/music.c b/src/audio/music.c index f1c5cd8..58be368 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -18,204 +18,224 @@ static Mix_Music *currentMusic; /* * Return state of music initialization */ -bool_t isMusicInicialized() +bool_t +isMusicInicialized() { - return isMusicInit; + return isMusicInit; } + /* * Initialize music */ -void initMusic() +void +initMusic() { - if (isAudioInicialized() == FALSE) { - isMusicInit = FALSE; - return; - } - listStorage = newStorage(); - currentMusic = NULL; - isMusicInit = TRUE; - var_isMusicActive = TRUE; - if (isParamFlag("--nomusic")) - setMusicActive(FALSE); - if (isParamFlag("--music")) - setMusicActive(TRUE); + if (isAudioInicialized() == FALSE) { + 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")); + printf(_("Initializing music...\n")); #endif } + /* * Load music file and returns it */ -static Mix_Music* loadMixMusic(char *file) +static Mix_Music * +loadMixMusic(char *file) { - Mix_Music *mixer; - char str[STR_PATH_SIZE]; + Mix_Music *mixer; + char str[STR_PATH_SIZE]; #ifdef DEBUG - printf(_("Loading music file: %s\n"), file); + printf(_("Loading music file: %s\n"), file); #endif - if( isFillPath(file) ) - { - strcpy(str, file); - } - else - { - sprintf(str, PATH_MUSIC "%s", file); - } + if (isFillPath(file)) { + strcpy(str, file); + } + else { + sprintf(str, PATH_MUSIC "%s", file); + } - accessExistFile(str); + accessExistFile(str); - mixer = Mix_LoadMUS(str); + mixer = Mix_LoadMUS(str); - if( mixer == NULL ) - { - fprintf(stderr, _("Unable to load music from file: %s\n"), file); - return NULL; - } + if (mixer == NULL) { + fprintf(stderr, _("Unable to load music from file: %s\n"), file); + return NULL; + } - return mixer; + return mixer; } + /* * Prepare music mixer */ -static void playMixMusic() +static void +playMixMusic() { - if (currentMusic != NULL) - Mix_PlayMusic(currentMusic, 1000); + if (currentMusic != NULL) + Mix_PlayMusic(currentMusic, 1000); } + /* * Free memory of music */ -static void destroyMusic(void *p) +static void +destroyMusic(void *p) { - Mix_FreeMusic((Mix_Music *)p); + Mix_FreeMusic((Mix_Music *) p); } + /* * Add file to list with music */ -void addMusic(char *file, char *name, char *group) +void +addMusic(char *file, char *name, char *group) { - Mix_Music *new; - if (isMusicInit == FALSE) - return; + Mix_Music *new; + if (isMusicInit == FALSE) + return; - assert( file != NULL ); - assert( name != NULL ); - assert( group != NULL ); + assert(file != NULL); + assert(name != NULL); + assert(group != NULL); - new = loadMixMusic(file); - addItemToStorage(listStorage, group, name, new ); + new = loadMixMusic(file); + addItemToStorage(listStorage, group, name, new); } + /* * Disable music and stop playback */ -void stopMusic() +void +stopMusic() { - if (isMusicInit == FALSE || - var_isMusicActive == FALSE) - return; + if (isMusicInit == FALSE || var_isMusicActive == FALSE) + return; - if (currentMusic != NULL) { + if (currentMusic != NULL) { #ifdef DEBUG - printf(_("Stopping music...\n")); + printf(_("Stopping music...\n")); #endif - Mix_HaltMusic(); - currentMusic = NULL; - } + Mix_HaltMusic(); + currentMusic = NULL; + } } + /* * start music playback */ -void playMusic(char *name, char *group) +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) { - strcpy(currentMusic_group, "none"); - strcpy(currentMusic_name, "none"); - isStrInit = 1; - } - - if (isMusicInit == FALSE || - var_isMusicActive == FALSE) - return; - - if (currentMusic != NULL && - strcmp(currentMusic_group, group) == 0 && - strcmp(currentMusic_name, name) == 0) { - return; - } - - if (currentMusic != NULL) - stopMusic(); - - currentMusic = getItemFromStorage(listStorage, group, name); - strcpy(currentMusic_group, group); - strcpy(currentMusic_name, name); - - if( currentMusic != NULL ) { + static char currentMusic_group[STR_SIZE]; + static char currentMusic_name[STR_SIZE]; + static int isStrInit = 0; + + if (isStrInit == 0) { + strcpy(currentMusic_group, "none"); + strcpy(currentMusic_name, "none"); + isStrInit = 1; + } + + if (isMusicInit == FALSE || var_isMusicActive == FALSE) + return; + + if (currentMusic != NULL && + strcmp(currentMusic_group, group) == 0 && + strcmp(currentMusic_name, name) == 0) { + return; + } + + if (currentMusic != NULL) + stopMusic(); + + currentMusic = getItemFromStorage(listStorage, group, name); + strcpy(currentMusic_group, group); + strcpy(currentMusic_name, name); + + if (currentMusic != NULL) { #ifdef DEBUG - printf(_("Playing music file %s\n"), name); + printf(_("Playing music file %s\n"), name); #endif - playMixMusic(); - } + playMixMusic(); + } } + /* * Set music active/deactivated */ -void setMusicActive(bool_t n) +void +setMusicActive(bool_t n) { - static Mix_Music *music = NULL; - - if (n == FALSE) { - music = currentMusic; - stopMusic(); - } - if (n == TRUE) { - currentMusic = music; - playMixMusic(); - } - - var_isMusicActive = n; + static Mix_Music *music = NULL; + + if (n == FALSE) { + music = currentMusic; + stopMusic(); + } + if (n == TRUE) { + currentMusic = music; + playMixMusic(); + } + + var_isMusicActive = n; } + /* * Return status of music */ -bool_t isMusicActive() +bool_t +isMusicActive() { - return var_isMusicActive; + return var_isMusicActive; } + /* * TOCOMMENT */ -char* getCurrentMusic() +char * +getCurrentMusic() { - return "unknown"; + return "unknown"; } + /* * TOCOMMENT */ -void delAllMusicInGroup(char *group) +void +delAllMusicInGroup(char *group) { - if (isMusicInit == FALSE) - return; - delAllItemFromStorage(listStorage, group, destroyMusic); + if (isMusicInit == FALSE) + return; + delAllItemFromStorage(listStorage, group, destroyMusic); } + /* * Deactivate all what is ment for music */ -void quitMusic() +void +quitMusic() { - if (isMusicInit == FALSE) - return; + if (isMusicInit == FALSE) + return; - stopMusic(); - destroyStorage(listStorage, destroyMusic); - isMusicInit = FALSE; + stopMusic(); + destroyStorage(listStorage, destroyMusic); + isMusicInit = FALSE; #ifdef DEBUG - printf(_("Quitting music...\n")); + printf(_("Quitting music...\n")); #endif } diff --git a/src/audio/sound.c b/src/audio/sound.c index 0c6b342..50a5aad 100644 --- a/src/audio/sound.c +++ b/src/audio/sound.c @@ -16,119 +16,137 @@ static bool_t var_isSoundActive = TRUE; /* * Return state of sound */ -bool_t isSoundInicialized() +bool_t +isSoundInicialized() { - return isSoundInit; + return isSoundInit; } + /* * Audio initialization */ -void initSound() +void +initSound() { - if( isAudioInicialized() == FALSE ) { - isSoundInit = FALSE; - return; - } + if (isAudioInicialized() == FALSE) { + isSoundInit = FALSE; + return; + } - listStorage = newStorage(); - isSoundInit = TRUE; - var_isSoundActive = TRUE; - if (isParamFlag("--nosound")) - setSoundActive(FALSE); - if (isParamFlag("--sound")) - setSoundActive(TRUE); + listStorage = newStorage(); + isSoundInit = TRUE; + var_isSoundActive = TRUE; + if (isParamFlag("--nosound")) + setSoundActive(FALSE); + if (isParamFlag("--sound")) + setSoundActive(TRUE); #ifdef DEBUG - printf(_("Initializing sound...\n")); + printf(_("Initializing sound...\n")); #endif } + /* * Load sound file (Null/mixer) */ -static Mix_Chunk* loadMixSound(char *file) +static Mix_Chunk * +loadMixSound(char *file) { - Mix_Chunk *new; - char str[STR_PATH_SIZE]; + Mix_Chunk *new; + char str[STR_PATH_SIZE]; #ifdef DEBUG - printf(_("Loading sound file: %s\n"), file); + 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, _("Unable to load sound file: %s with error: %s\n"), str, Mix_GetError()); - return NULL; - } - return new; + 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()); + return NULL; + } + return new; } /* * 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 playback sound with error: %s\n"), Mix_GetError()); - return; - } + 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) +static void +destroySound(void *p) { - Mix_FreeChunk((Mix_Chunk *)p); + Mix_FreeChunk((Mix_Chunk *) p); } + /* * Add sound to list */ -void addSound(char *file, char *name, char *group) +void +addSound(char *file, char *name, char *group) { - Mix_Chunk *new; + Mix_Chunk *new; - if (isSoundInit == FALSE) - return; - assert( file != NULL ); - assert( name != NULL ); - assert( group != NULL ); - new = loadMixSound(file); - addItemToStorage(listStorage, group, name, new ); + 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) +void +playSound(char *name, char *group) { - if (isSoundInit == FALSE || - var_isSoundActive == FALSE) - return; - playMixSound(getItemFromStorage(listStorage, group, name)); + if (isSoundInit == FALSE || var_isSoundActive == FALSE) + return; + playMixSound(getItemFromStorage(listStorage, group, name)); } + /* * Set if sound is active True/False */ -void setSoundActive(bool_t n) +void +setSoundActive(bool_t n) { - var_isSoundActive = n; + var_isSoundActive = n; } + /* * Return state of sound */ -bool_t isSoundActive() +bool_t +isSoundActive() { - return var_isSoundActive; + return var_isSoundActive; } + /* * Quit all sound stuff */ -void quitSound() +void +quitSound() { - if( isSoundInit == FALSE ) - return; - destroyStorage(listStorage, destroySound); - isSoundInit = FALSE; + if (isSoundInit == FALSE) + return; + destroyStorage(listStorage, destroySound); + isSoundInit = FALSE; #ifdef DEBUG - printf(_("Quitting sound...\n")); + printf(_("Quitting sound...\n")); #endif } - |