X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsound.c;h=1decace8a353c023aca13416de5a11297d76023a;hb=1280ea87a3b13fcadcc3d6767f89cd274e2e6a4a;hp=69c980bc136c7508a689ab612efeb9ff91c90ba7;hpb=de11b13419f0f5ab58bbdbbfe7d4d1769696ab9a;p=supertux.git diff --git a/src/sound.c b/src/sound.c index 69c980bc1..1decace8a 100644 --- a/src/sound.c +++ b/src/sound.c @@ -10,8 +10,6 @@ April 22, 2000 - July 15, 2002 */ -#ifndef NOSOUND - #include #include #include @@ -20,8 +18,6 @@ #include #include -#include - #ifdef LINUX #include #include @@ -33,17 +29,33 @@ #include "sound.h" #include "setup.h" +#ifndef NOSOUND + +/* --- OPEN THE AUDIO DEVICE --- */ + +int open_audio (int frequency, Uint16 format, int channels, int chunksize) +{ + if (use_sound) { + return Mix_OpenAudio( frequency, format, channels, chunksize ); + } + else { + // let the user think that the audio device was correctly opened + // and keep the compiler happy :-D + return 0; + } +} + /* --- LOAD A SOUND --- */ Mix_Chunk * load_sound(char * file) { Mix_Chunk * snd; - + if (use_sound) { snd = Mix_LoadWAV(file); - + if (snd == NULL) st_abort("Can't load", file); } @@ -54,14 +66,6 @@ Mix_Chunk * load_sound(char * file) } -/* --- PLAY A SOUND --- */ - -void playsound(Mix_Chunk * snd) -{ - Mix_PlayChannel(-1, snd, 0); -} - - /* --- LOAD A SONG --- */ Mix_Music * load_song(char * file) @@ -81,4 +85,85 @@ Mix_Music * load_song(char * file) return (sng); } + +/* --- PLAY A SOUND --- */ + + void play_sound(Mix_Chunk * snd) + { + // this won't call the function if the user has disabled sound + if (use_sound) { + Mix_PlayChannel(-1, snd, 0); + } +} + + +void free_chunk(Mix_Chunk *chunk) +{ + if (use_sound) { + DEBUG_MSG( __PRETTY_FUNCTION__ ); + Mix_FreeChunk( chunk ); + } +} + +int playing_music(void) +{ + if (use_sound) { + return Mix_PlayingMusic(); + } + else { + /* we are in --disable-sound we can't be playing music */ + return 0; + } +} + + +int halt_music(void) +{ + if (use_sound) { + return Mix_HaltMusic(); + } + else { + return 0; + } +} + + +int play_music(Mix_Music *music, int loops) +{ + if (use_sound) { + DEBUG_MSG(__PRETTY_FUNCTION__); + return Mix_PlayMusic(music, loops); + } + else { + /* return error since you're trying to play music in --disable-sound mode */ + return -1; + } +} + + +void free_music(Mix_Music *music) +{ + if (use_sound) { + DEBUG_MSG(__PRETTY_FUNCTION__); + Mix_FreeMusic( music ); + } +} + +#else + +int open_audio (int frequency, int format, int channels, int chunksize) +{ + return -1; +} + +void* load_sound(void* file) { return NULL; } +void play_sound(void * snd) {} +void* load_song(void* file) { return NULL; } + +int playing_music() { return 0; } +void halt_music() {} +int play_music(int *music, int loops) { return 0;} +void free_music(int *music) {} +void free_chunk(int *chunk) {} + #endif