4 Super Tux - Audio Functions
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 22, 2000 - December 28, 2003
22 #include <sys/types.h>
33 #include <SDL_mixer.h>
35 /* --- OPEN THE AUDIO DEVICE --- */
37 int open_audio (int frequency, Uint16 format, int channels, int chunksize)
39 return Mix_OpenAudio( frequency, format, channels, chunksize );
43 /* --- LOAD A SOUND --- */
45 Mix_Chunk * load_sound(char * file)
49 snd = Mix_LoadWAV(file);
51 /* printf message and abort if there is an initialized audio device */
52 if ((snd == NULL) && (audio_device == YES))
53 st_abort("Can't load", file);
59 /* --- LOAD A SONG --- */
61 Mix_Music * load_song(char * file)
65 sng = Mix_LoadMUS(file);
67 /* printf message and abort if there is an initialized audio device */
68 if ((sng == NULL) && (audio_device == YES))
69 st_abort("Can't load", file);
74 /* --- PLAY A SOUND --- */
76 void play_sound(Mix_Chunk * snd)
78 /* this won't call the function if the user has disabled sound
79 * either via menu or via command-line option
81 if ((use_sound == YES) && (audio_device == YES))
83 Mix_PlayChannel(-1, snd, 0);
88 void free_chunk(Mix_Chunk *chunk)
92 DEBUG_MSG( __PRETTY_FUNCTION__ );
93 Mix_FreeChunk( chunk );
98 int playing_music(void)
100 if (use_music == YES)
102 return Mix_PlayingMusic();
106 /* we are in --disable-music we can't be playing music */
114 if ((use_music == YES) && (audio_device == YES))
116 return Mix_HaltMusic();
125 int play_music(Mix_Music *music, int loops)
127 if ((use_music == YES) && (audio_device == YES))
129 DEBUG_MSG(__PRETTY_FUNCTION__);
130 return Mix_PlayMusic(music, loops);
134 /* return error since you're trying to play music in --disable-sound mode */
140 void free_music(Mix_Music *music)
144 DEBUG_MSG(__PRETTY_FUNCTION__);
145 Mix_FreeMusic( music );
152 int open_audio (int frequency, int format, int channels, int chunksize)
157 void* load_sound(void* file)
161 void play_sound(void * snd)
163 void* load_song(void* file)
174 int play_music(void *music, int loops)
178 void free_music(void *music)
180 void free_chunk(void *chunk)