diff options
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/audio/audio.c | 55 | ||||
| -rw-r--r-- | src/audio/audio.h | 10 | ||||
| -rw-r--r-- | src/audio/music.c | 232 | ||||
| -rw-r--r-- | src/audio/music.h | 33 | ||||
| -rw-r--r-- | src/audio/sound.c | 148 | ||||
| -rw-r--r-- | src/audio/sound.h | 30 |
7 files changed, 0 insertions, 515 deletions
diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt deleted file mode 100644 index 2e93cef..0000000 --- a/src/audio/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -############################################################################### -# tuxanci/src/*/CMakeLists.txt -############################################################################### -# Generate source_code files from .c files we find in directory -############################################################################### -MacroAddSources() -############################################################################### diff --git a/src/audio/audio.c b/src/audio/audio.c deleted file mode 100644 index 8e224fd..0000000 --- a/src/audio/audio.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> -#include <assert.h> -#include <SDL_mixer.h> - -#include "main.h" -#include "audio.h" -#include "interface.h" - -static bool_t isAudioInit = FALSE; - -/** - * Return status of audio - */ -bool_t audio_is_inicialized() -{ - return isAudioInit; -} - -/** - * Initialize audio - */ -void audio_init() -{ - if (isParamFlag("--no-audio")) { - return; - } - - debug("Initializing audio"); - - if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) { - error("Unable to initialize audio: %s", SDL_GetError()); - return; - } - - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { - error("Unable to create proper audio settings: %s", Mix_GetError()); - return; - } - - Mix_AllocateChannels(16); - Mix_Volume(-1, MIX_MAX_VOLUME); - - isAudioInit = TRUE; -} - -/** - * Shutdown audio - */ -void audio_quit() -{ - debug("Shutting down audio"); - - Mix_CloseAudio(); - isAudioInit = TRUE; -} diff --git a/src/audio/audio.h b/src/audio/audio.h deleted file mode 100644 index cc0b197..0000000 --- a/src/audio/audio.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef AUDIO_H -#define AUDIO_H - -#include "main.h" - -extern bool_t audio_is_inicialized(); -extern void audio_init(); -extern void audio_quit(); - -#endif /* AUDIO_H */ diff --git a/src/audio/music.c b/src/audio/music.c deleted file mode 100644 index 9834630..0000000 --- a/src/audio/music.c +++ /dev/null @@ -1,232 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "list.h" -#include "storage.h" -#include "interface.h" -#include "audio.h" -#include "music.h" - -static list_t *listStorage; - -static bool_t isMusicInit = FALSE; -static bool_t var_music_is_active = TRUE; -static Mix_Music *currentMusic; - -/** - * Return status of music - */ -bool_t music_is_inicialized() -{ - return isMusicInit; -} - -/** - * Initialize music - */ -void music_init() -{ - if (audio_is_inicialized() == FALSE) { - isMusicInit = FALSE; - return; - } - - debug("Initializing music"); - - listStorage = storage_new(); - currentMusic = NULL; - isMusicInit = TRUE; - var_music_is_active = TRUE; - - if (isParamFlag("--no-music")) { - music_set_active(FALSE); - } else if (isParamFlag("--music")) { - music_set_active(TRUE); - } -} - -/** - * Load a file with music and returns it - */ -static Mix_Music *loadMixMusic(char *file) -{ - Mix_Music *mixer; - char str[STR_PATH_SIZE]; - - debug("Loading music [%s]", file); - - if (isFillPath(file)) { - strcpy(str, file); - } else { - sprintf(str, PATH_MUSIC "%s", file); - } - - accessExistFile(str); - - mixer = Mix_LoadMUS(str); - - if (mixer == NULL) { - error("Unable to load music [%s]", file); - return NULL; - } - - return mixer; -} - -/** - * Prepare the music mixer - */ -static void playMixMusic() -{ - if (currentMusic != NULL) { - Mix_PlayMusic(currentMusic, 1000); - } -} - -/** - * Remove music from the memory - */ -static void destroyMusic(void *p) -{ - Mix_FreeMusic((Mix_Music *) p); -} - -/** - * Add a file to the music list - */ -void music_add(char *file, char *name, char *group) -{ - Mix_Music *new; - - if (isMusicInit == FALSE) { - return; - } - - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); - - new = loadMixMusic(file); - storage_add(listStorage, group, name, new); -} - -/** - * Stop playing music - */ -void music_stop() -{ - if (isMusicInit == FALSE || var_music_is_active == FALSE) { - return; - } - - if (currentMusic != NULL) { - debug("Stopping playing music"); - - Mix_HaltMusic(); - currentMusic = NULL; - } -} - -/** - * Play music playback - */ -void music_play(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_music_is_active == FALSE) { - return; - } - - if (currentMusic != NULL && - strcmp(currentMusic_group, group) == 0 && - strcmp(currentMusic_name, name) == 0) { - return; - } - - if (currentMusic != NULL) { - music_stop(); - } - - currentMusic = storage_get(listStorage, group, name); - strcpy(currentMusic_group, group); - strcpy(currentMusic_name, name); - - if (currentMusic != NULL) { - debug("Playing music [%s]", name); - - playMixMusic(); - } -} - -/** - * Set music status to active/inactive - */ -void music_set_active(bool_t n) -{ - static Mix_Music *music = NULL; - - if (n == FALSE) { - music = currentMusic; - music_stop(); - } else if (n == TRUE) { - currentMusic = music; - playMixMusic(); - } - - var_music_is_active = n; -} - -/** - * Return the activity status of music - */ -bool_t music_is_active() -{ - return var_music_is_active; -} - -/** - * Return the music playing right now - */ -char *music_get_current() -{ - return "unknown"; -} - -/** - * Remove all music files belonging to the certain group - */ -void music_del_all_in_group(char *group) -{ - if (isMusicInit == FALSE) { - return; - } - - storage_del_all(listStorage, group, destroyMusic); -} - -/** - * Shutdown music - */ -void music_quit() -{ - if (isMusicInit == FALSE) { - return; - } - - debug("Shutting down music"); - - music_stop(); - storage_destroy(listStorage, destroyMusic); - isMusicInit = FALSE; -} diff --git a/src/audio/music.h b/src/audio/music.h deleted file mode 100644 index 9eedac7..0000000 --- a/src/audio/music.h +++ /dev/null @@ -1,33 +0,0 @@ -#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 music_is_inicialized(); -extern void music_init(); -extern void music_add(char *file, char *name, char *group); -extern void music_stop(); -extern void music_play(char *name, char *group); -extern void music_set_active(bool_t n); -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 /* NO_SOUND */ -#endif /* MUSIC_H */ diff --git a/src/audio/sound.c b/src/audio/sound.c deleted file mode 100644 index 79a152d..0000000 --- a/src/audio/sound.c +++ /dev/null @@ -1,148 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#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_sound_is_active = TRUE; - -/** - * Return status of sound - */ -bool_t sound_is_inicialized() -{ - return isSoundInit; -} - -/** - * Initialize sound - */ -void sound_init() -{ - if (audio_is_inicialized() == FALSE) { - isSoundInit = FALSE; - return; - } - - debug("Initializing sound"); - - listStorage = storage_new(); - isSoundInit = TRUE; - var_sound_is_active = TRUE; - - if (isParamFlag("--no-sound")) { - sound_set_active(FALSE); - } else if (isParamFlag("--sound")) { - sound_set_active(TRUE); - } -} - -/** - * Load sound from file (Null/mixer) - */ -static Mix_Chunk *loadMixSound(char *file) -{ - Mix_Chunk *new; - char str[STR_PATH_SIZE]; - - debug("Loading sound [%s]", file); - - sprintf(str, PATH_SOUND "%s", file); - accessExistFile(str); - new = Mix_LoadWAV(str); - - if (new == NULL) { - error("Unable to load sound [%s]: %s", str, Mix_GetError()); - return NULL; - } - - return new; -} - -/** - * Play sound with mixer - */ -static void playMixSound(Mix_Chunk *p) -{ - if (Mix_PlayChannel(-1, p, 0) == -1) { - error("Unable to play sound: %s", Mix_GetError()); - return; - } -} - -/** - * Destroy mixer chunk - */ -static void destroySound(void *p) -{ - Mix_FreeChunk((Mix_Chunk *) p); -} - -/** - * Add a sound to list - */ -void sound_add(char *file, char *name, char *group) -{ - Mix_Chunk *new; - - if (isSoundInit == FALSE) { - return; - } - - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); - - new = loadMixSound(file); - storage_add(listStorage, group, name, new); -} - -/** - * 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) { - return; - } - - playMixSound(storage_get(listStorage, group, name)); -} - -/** - * Set sound status to active/inactive (true/false) - */ -void sound_set_active(bool_t n) -{ - var_sound_is_active = n; -} - -/** - * Return status of sound - */ -bool_t sound_is_active() -{ - return var_sound_is_active; -} - -/** - * Shutdown sound - */ -void sound_quit() -{ - if (isSoundInit == FALSE) { - return; - } - - debug("Shutting down sound"); - - storage_destroy(listStorage, destroySound); - isSoundInit = FALSE; -} diff --git a/src/audio/sound.h b/src/audio/sound.h deleted file mode 100644 index f8cf2d3..0000000 --- a/src/audio/sound.h +++ /dev/null @@ -1,30 +0,0 @@ -#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 sound_is_inicialized(); -extern void sound_init(); -extern void sound_add(char *file, char *name, char *group); -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 /* NO_SOUND */ -#endif /* SOUND_H */ |