1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Added volume support.

This commit is contained in:
Frank Zago 2009-05-06 03:13:46 +00:00
parent 11779956b1
commit a594beea92
2 changed files with 44 additions and 4 deletions

View File

@ -206,6 +206,22 @@ void CSoundHandler::stopSound( int handler )
Mix_HaltChannel(handler);
}
// Sets the sound volume, from 0 (mute) to 100
void CSoundHandler::setSoundVolume(unsigned int percent)
{
if (percent > 100)
percent = 100;
volume = percent;
Mix_Volume(-1, (MIX_MAX_VOLUME * percent)/100);
}
// Returns the current sound volume, from 0 (mute) to 100
unsigned int CSoundHandler::getSoundVolume()
{
return volume;
}
void CMusicHandler::initMusics()
{
// Map music IDs
@ -288,6 +304,22 @@ void CMusicHandler::stopMusic(int fade_ms)
musicMutex.unlock();
}
// Sets the music volume, from 0 (mute) to 100
void CMusicHandler::setMusicVolume(unsigned int percent)
{
if (percent > 100)
percent = 100;
volume = percent;
Mix_VolumeMusic((MIX_MAX_VOLUME * percent)/100);
}
// Returns the current music volume, from 0 (mute) to 100
unsigned int CMusicHandler::getMusicVolume()
{
return volume;
}
// Called by SDL when a music finished.
void CMusicHandler::musicFinishedCallback(void)
{
@ -308,7 +340,7 @@ void CMusicHandler::musicFinishedCallback(void)
musicMutex.unlock();
}
void CAudioHandler::initAudio()
void CAudioHandler::initAudio(unsigned int volume)
{
if (audioInitialized)
return;
@ -322,7 +354,9 @@ void CAudioHandler::initAudio()
audioInitialized = true;
initSounds();
setSoundVolume(volume);
initMusics();
setMusicVolume(volume);
}
CAudioHandler::~CAudioHandler()

View File

@ -31,9 +31,10 @@ private:
std::map<soundBase::soundID, Mix_Chunk *> soundChunks;
Mix_Chunk *GetSoundChunk(soundBase::soundID soundID);
int volume; // from 0 (mute) to 100
public:
CSoundHandler(): sndh(NULL) {};
CSoundHandler(): sndh(NULL), volume(0) {};
void initSounds();
void freeSounds();
@ -43,6 +44,8 @@ public:
int playSound(soundBase::soundID soundID, int repeats=0);
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
void stopSound(int handler);
void setSoundVolume(unsigned int percent);
unsigned int getSoundVolume();
// Sets
std::vector<soundBase::soundID> pickupSounds;
@ -58,9 +61,10 @@ private:
Mix_Music *currentMusic;
Mix_Music *nextMusic;
int nextMusicLoop;
int volume; // from 0 (mute) to 100
public:
CMusicHandler(): currentMusic(NULL), nextMusic(NULL) {};
CMusicHandler(): currentMusic(NULL), nextMusic(NULL), volume(0) {};
void initMusics();
void freeMusics();
@ -72,6 +76,8 @@ public:
void playMusic(musicBase::musicID musicID, int loop=1);
void playMusicFromSet(std::vector<musicBase::musicID> &music_vec, int loop=1);
void stopMusic(int fade_ms=1000);
void setMusicVolume(unsigned int percent);
unsigned int getMusicVolume();
void musicFinishedCallback(void);
};
@ -84,7 +90,7 @@ public:
CAudioHandler(): audioInitialized(false) {};
~CAudioHandler();
void initAudio();
void initAudio(unsigned int volume = 90);
};
#endif // __CMUSICHANDLER_H__