#include "setup.h"
/*global variable*/
-bool use_sound; /* handle sound on/off menu and command-line option */
-bool use_music; /* handle music on/off menu and command-line option */
-bool audio_device; /* != 0: available and initialized */
-int current_music;
+bool use_sound = true; /* handle sound on/off menu and command-line option */
+bool use_music = true; /* handle music on/off menu and command-line option */
+bool audio_device = true; /* != 0: available and initialized */
char * soundfilenames[NUM_SOUNDS] = {
"/sounds/jump.wav",
"/sounds/bigjump.wav",
"/sounds/skid.wav",
- "/sounds/distro.wav",
- "/sounds/herring.wav",
+ "/sounds/coin.wav",
+ "/sounds/invincible.wav",
"/sounds/brick.wav",
"/sounds/hurt.wav",
"/sounds/squish.wav",
"/sounds/ricochet.wav",
"/sounds/bump-upgrade.wav",
"/sounds/upgrade.wav",
- "/sounds/excellent.wav",
- "/sounds/coffee.wav",
+ "/sounds/grow.wav",
+ "/sounds/fire-flower.wav",
"/sounds/shoot.wav",
"/sounds/lifeup.wav",
"/sounds/stomp.wav",
- "/sounds/kick.wav"
+ "/sounds/kick.wav",
+ "/sounds/explosion.wav"
};
#include <SDL_mixer.h>
Mix_Chunk * sounds[NUM_SOUNDS];
-Mix_Music * herring_song = 0;
-Mix_Music * current_song = 0;
/* --- OPEN THE AUDIO DEVICE --- */
int open_audio (int frequency, Uint16 format, int channels, int chunksize)
{
- /* if success we reserved some channels and register panning effects */
- if (Mix_OpenAudio( frequency, format, channels, chunksize ) == 0)
- {
- if (Mix_ReserveChannels( SOUND_RESERVED_CHANNELS )
- != SOUND_RESERVED_CHANNELS )
- {
- DEBUG_MSG( "Warning: open_audio could'nt reserve channels" );
- }
-
- /* prepare the spanning effects, no error checking */
- Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
- Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
- return 0;
- }
- else
- {
- return -1;
- }
+ if (Mix_OpenAudio( frequency, format, channels, chunksize ) < 0)
+ return -1;
+
+ // allocate 16 channels for mixing
+ if (Mix_AllocateChannels(8) != 8)
+ return -2;
+
+ /* reserve some channels and register panning effects */
+ if (Mix_ReserveChannels(SOUND_RESERVED_CHANNELS) != SOUND_RESERVED_CHANNELS)
+ return -3;
+
+ /* prepare the spanning effects */
+ Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
+ Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
+ return 0;
}
/* --- LOAD A SOUND --- */
-Mix_Chunk * load_sound(const std::string& file)
-{
- Mix_Chunk * snd;
-
- snd = Mix_LoadWAV(file.c_str());
-
- /* printf message and abort if there is an initialized audio device */
- if ((snd == NULL) && audio_device)
- st_abort("Can't load", file);
-
- return(snd);
-}
-
-
-/* --- LOAD A SONG --- */
-
-Mix_Music * load_song(const std::string& file)
+Mix_Chunk* load_sound(const std::string& file)
{
if(!audio_device)
return 0;
- Mix_Music * sng;
+ Mix_Chunk* snd = Mix_LoadWAV(file.c_str());
- sng = Mix_LoadMUS(file.c_str());
-
- /* printf message and abort if there is an initialized audio device */
- if (sng == NULL)
+ if (snd == 0)
st_abort("Can't load", file);
-
- return (sng);
-}
+ return(snd);
+}
/* --- PLAY A SOUND ON LEFT OR RIGHT OR CENTER SPEAKER --- */
/* this won't call the function if the user has disabled sound
* either via menu or via command-line option
*/
- if (use_sound && audio_device)
- {
- Mix_PlayChannel( whichSpeaker, snd, 0);
-
- /* prepare for panning effects for next call */
- /* warning: currently, I do not check for errors here */
- switch (whichSpeaker) {
- case SOUND_LEFT_SPEAKER:
- Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
- break;
- case SOUND_RIGHT_SPEAKER:
- Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
- break;
- default: // keep the compiler happy
- break;
- }
- }
-}
-
-
-void free_chunk(Mix_Chunk *chunk)
-{
- if (chunk != NULL)
- {
- DEBUG_MSG( __PRETTY_FUNCTION__ );
- Mix_FreeChunk( chunk );
- chunk = NULL;
- }
-}
-
-void halt_music(void)
-{
- if (!use_music || !audio_device)
+ if(!audio_device || !use_sound)
return;
- Mix_HaltMusic();
- current_song = 0;
-}
-
+ Mix_PlayChannel( whichSpeaker, snd, 0);
-void play_music(Mix_Music *music)
-{
- if (!audio_device)
- return;
-
- if (use_music && Mix_PlayMusic(music, -1) < 0)
- st_abort("Couldn't play music: ", Mix_GetError());
-
- current_song = music;
-}
-
-
-void free_music(Mix_Music *music)
-{
- Mix_FreeMusic( music );
+ /* prepare for panning effects for next call */
+ switch (whichSpeaker) {
+ case SOUND_LEFT_SPEAKER:
+ Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
+ break;
+ case SOUND_RIGHT_SPEAKER:
+ Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
+ break;
+ default: // keep the compiler happy
+ break;
+ }
}
-void enable_music(bool enable)
+void free_chunk(Mix_Chunk *chunk)
{
- if(!audio_device)
- return;
-
- use_music = enable;
- if(!use_music)
- Mix_HaltMusic();
- else
- Mix_PlayMusic(current_song, -1);
+ Mix_FreeChunk( chunk );
}