#include "defines.h"
#include "globals.h"
#include "sound.h"
#include "setup.h"
bool use_sound = true;
bool use_music = true;
bool audio_device = true;
char * soundfilenames[NUM_SOUNDS] = {
"/sounds/jump.wav",
"/sounds/bigjump.wav",
"/sounds/skid.wav",
"/sounds/distro.wav",
"/sounds/herring.wav",
"/sounds/brick.wav",
"/sounds/hurt.wav",
"/sounds/squish.wav",
"/sounds/fall.wav",
"/sounds/ricochet.wav",
"/sounds/bump-upgrade.wav",
"/sounds/upgrade.wav",
"/sounds/excellent.wav",
"/sounds/coffee.wav",
"/sounds/shoot.wav",
"/sounds/lifeup.wav",
"/sounds/stomp.wav",
"/sounds/kick.wav",
"/sounds/explode.wav",
"/sounds/warp.wav"
};
Mix_Chunk * sounds[NUM_SOUNDS];
int open_audio (int frequency, Uint16 format, int channels, int chunksize)
{
#ifndef NO_SDLMIXER
if (Mix_OpenAudio( frequency, format, channels, chunksize ) < 0)
return -1;
if (Mix_AllocateChannels(8) != 8)
return -2;
if (Mix_ReserveChannels(SOUND_RESERVED_CHANNELS) != SOUND_RESERVED_CHANNELS)
return -3;
Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
#endif
return 0;
}
void close_audio( void )
{
#ifndef NO_SDLMIXER
if (audio_device) {
Mix_UnregisterAllEffects( SOUND_LEFT_SPEAKER );
Mix_UnregisterAllEffects( SOUND_RIGHT_SPEAKER );
Mix_CloseAudio();
}
#endif
}
Mix_Chunk* load_sound(const std::string& file)
{
#ifndef NO_SDLMIXER
if(!audio_device)
return 0;
Mix_Chunk* snd = Mix_LoadWAV(file.c_str());
if (snd == 0)
st_abort("Can't load", file);
return(snd);
#else
return 0;
#endif
}
void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker)
{
#ifndef NO_SDLMIXER
if(!audio_device || !use_sound)
return;
Mix_PlayChannel( whichSpeaker, snd, 0);
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:
break;
}
#endif
}
void free_chunk(Mix_Chunk *chunk)
{
#ifndef NO_SDLMIXER
Mix_FreeChunk( chunk );
#endif
}