mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Added volume support.
This commit is contained in:
@@ -206,6 +206,22 @@ void CSoundHandler::stopSound( int handler )
|
|||||||
Mix_HaltChannel(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()
|
void CMusicHandler::initMusics()
|
||||||
{
|
{
|
||||||
// Map music IDs
|
// Map music IDs
|
||||||
@@ -288,6 +304,22 @@ void CMusicHandler::stopMusic(int fade_ms)
|
|||||||
musicMutex.unlock();
|
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.
|
// Called by SDL when a music finished.
|
||||||
void CMusicHandler::musicFinishedCallback(void)
|
void CMusicHandler::musicFinishedCallback(void)
|
||||||
{
|
{
|
||||||
@@ -308,7 +340,7 @@ void CMusicHandler::musicFinishedCallback(void)
|
|||||||
musicMutex.unlock();
|
musicMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioHandler::initAudio()
|
void CAudioHandler::initAudio(unsigned int volume)
|
||||||
{
|
{
|
||||||
if (audioInitialized)
|
if (audioInitialized)
|
||||||
return;
|
return;
|
||||||
@@ -322,7 +354,9 @@ void CAudioHandler::initAudio()
|
|||||||
audioInitialized = true;
|
audioInitialized = true;
|
||||||
|
|
||||||
initSounds();
|
initSounds();
|
||||||
|
setSoundVolume(volume);
|
||||||
initMusics();
|
initMusics();
|
||||||
|
setMusicVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAudioHandler::~CAudioHandler()
|
CAudioHandler::~CAudioHandler()
|
||||||
|
@@ -31,9 +31,10 @@ private:
|
|||||||
std::map<soundBase::soundID, Mix_Chunk *> soundChunks;
|
std::map<soundBase::soundID, Mix_Chunk *> soundChunks;
|
||||||
|
|
||||||
Mix_Chunk *GetSoundChunk(soundBase::soundID soundID);
|
Mix_Chunk *GetSoundChunk(soundBase::soundID soundID);
|
||||||
|
int volume; // from 0 (mute) to 100
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CSoundHandler(): sndh(NULL) {};
|
CSoundHandler(): sndh(NULL), volume(0) {};
|
||||||
|
|
||||||
void initSounds();
|
void initSounds();
|
||||||
void freeSounds();
|
void freeSounds();
|
||||||
@@ -43,6 +44,8 @@ public:
|
|||||||
int playSound(soundBase::soundID soundID, int repeats=0);
|
int playSound(soundBase::soundID soundID, int repeats=0);
|
||||||
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
|
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
|
||||||
void stopSound(int handler);
|
void stopSound(int handler);
|
||||||
|
void setSoundVolume(unsigned int percent);
|
||||||
|
unsigned int getSoundVolume();
|
||||||
|
|
||||||
// Sets
|
// Sets
|
||||||
std::vector<soundBase::soundID> pickupSounds;
|
std::vector<soundBase::soundID> pickupSounds;
|
||||||
@@ -58,9 +61,10 @@ private:
|
|||||||
Mix_Music *currentMusic;
|
Mix_Music *currentMusic;
|
||||||
Mix_Music *nextMusic;
|
Mix_Music *nextMusic;
|
||||||
int nextMusicLoop;
|
int nextMusicLoop;
|
||||||
|
int volume; // from 0 (mute) to 100
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMusicHandler(): currentMusic(NULL), nextMusic(NULL) {};
|
CMusicHandler(): currentMusic(NULL), nextMusic(NULL), volume(0) {};
|
||||||
|
|
||||||
void initMusics();
|
void initMusics();
|
||||||
void freeMusics();
|
void freeMusics();
|
||||||
@@ -72,6 +76,8 @@ public:
|
|||||||
void playMusic(musicBase::musicID musicID, int loop=1);
|
void playMusic(musicBase::musicID musicID, int loop=1);
|
||||||
void playMusicFromSet(std::vector<musicBase::musicID> &music_vec, int loop=1);
|
void playMusicFromSet(std::vector<musicBase::musicID> &music_vec, int loop=1);
|
||||||
void stopMusic(int fade_ms=1000);
|
void stopMusic(int fade_ms=1000);
|
||||||
|
void setMusicVolume(unsigned int percent);
|
||||||
|
unsigned int getMusicVolume();
|
||||||
void musicFinishedCallback(void);
|
void musicFinishedCallback(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -84,7 +90,7 @@ public:
|
|||||||
CAudioHandler(): audioInitialized(false) {};
|
CAudioHandler(): audioInitialized(false) {};
|
||||||
~CAudioHandler();
|
~CAudioHandler();
|
||||||
|
|
||||||
void initAudio();
|
void initAudio(unsigned int volume = 90);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __CMUSICHANDLER_H__
|
#endif // __CMUSICHANDLER_H__
|
||||||
|
Reference in New Issue
Block a user