mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 17:09:40 +00:00
Add a method to get the volume from the sound type
This commit is contained in:
parent
a5356e194e
commit
b4e36d4f31
3 changed files with 36 additions and 12 deletions
|
@ -30,6 +30,10 @@ namespace MWSound
|
||||||
void setPosition(const Ogre::Vector3 &pos) { mPos = pos; }
|
void setPosition(const Ogre::Vector3 &pos) { mPos = pos; }
|
||||||
void setVolume(float volume) { mVolume = volume; }
|
void setVolume(float volume) { mVolume = volume; }
|
||||||
|
|
||||||
|
MWBase::SoundManager::PlayType getPlayType() const
|
||||||
|
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
||||||
|
|
||||||
|
|
||||||
Sound(const Ogre::Vector3& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
Sound(const Ogre::Vector3& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
||||||
: mPos(pos)
|
: mPos(pos)
|
||||||
, mVolume(vol)
|
, mVolume(vol)
|
||||||
|
|
|
@ -137,6 +137,27 @@ namespace MWSound
|
||||||
return "Sound/"+snd->mSound;
|
return "Sound/"+snd->mSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets the combined volume settings for the given sound type
|
||||||
|
float SoundManager::volumeFromType(PlayType type) const
|
||||||
|
{
|
||||||
|
float volume = mMasterVolume;
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case Play_TypeSfx:
|
||||||
|
volume *= mSFXVolume;
|
||||||
|
break;
|
||||||
|
case Play_TypeVoice:
|
||||||
|
volume *= mVoiceVolume;
|
||||||
|
break;
|
||||||
|
case Play_TypeMusic:
|
||||||
|
case Play_TypeMovie:
|
||||||
|
volume *= mMusicVolume;
|
||||||
|
break;
|
||||||
|
case Play_TypeMask:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
bool SoundManager::isPlaying(MWWorld::Ptr ptr, const std::string &id) const
|
bool SoundManager::isPlaying(MWWorld::Ptr ptr, const std::string &id) const
|
||||||
{
|
{
|
||||||
|
@ -165,13 +186,13 @@ namespace MWSound
|
||||||
std::cout <<"Playing "<<filename<< std::endl;
|
std::cout <<"Playing "<<filename<< std::endl;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float basevol = mMasterVolume * mMusicVolume;
|
|
||||||
stopMusic();
|
stopMusic();
|
||||||
|
|
||||||
DecoderPtr decoder = getDecoder();
|
DecoderPtr decoder = getDecoder();
|
||||||
decoder->open(filename);
|
decoder->open(filename);
|
||||||
|
|
||||||
mMusic = mOutput->streamSound(decoder, basevol, 1.0f, Play_NoEnv|Play_TypeMusic);
|
mMusic = mOutput->streamSound(decoder, volumeFromType(Play_TypeMusic),
|
||||||
|
1.0f, Play_NoEnv|Play_TypeMusic);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -214,7 +235,7 @@ namespace MWSound
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// The range values are not tested
|
// The range values are not tested
|
||||||
float basevol = mMasterVolume * mVoiceVolume;
|
float basevol = volumeFromType(Play_TypeVoice);
|
||||||
std::string filePath = "Sound/"+filename;
|
std::string filePath = "Sound/"+filename;
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
const ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
||||||
|
@ -235,7 +256,7 @@ namespace MWSound
|
||||||
return;
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float basevol = mMasterVolume * mVoiceVolume;
|
float basevol = volumeFromType(Play_TypeVoice);
|
||||||
std::string filePath = "Sound/"+filename;
|
std::string filePath = "Sound/"+filename;
|
||||||
|
|
||||||
MWBase::SoundPtr sound = mOutput->playSound(filePath, 1.0f, basevol, 1.0f, Play_Normal|Play_TypeVoice);
|
MWBase::SoundPtr sound = mOutput->playSound(filePath, 1.0f, basevol, 1.0f, Play_Normal|Play_TypeVoice);
|
||||||
|
@ -275,7 +296,7 @@ namespace MWSound
|
||||||
return track;
|
return track;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
track = mOutput->streamSound(decoder, mMasterVolume, 1.0f, Play_NoEnv|type);
|
track = mOutput->streamSound(decoder, volumeFromType(type), 1.0f, Play_NoEnv|type);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -292,7 +313,7 @@ namespace MWSound
|
||||||
return sound;
|
return sound;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float basevol = mMasterVolume * mSFXVolume;
|
float basevol = volumeFromType((PlayType)(mode&Play_TypeMask));
|
||||||
float min, max;
|
float min, max;
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
std::string file = lookup(soundId, volume, min, max);
|
||||||
|
|
||||||
|
@ -315,7 +336,7 @@ namespace MWSound
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Look up the sound in the ESM data
|
// Look up the sound in the ESM data
|
||||||
float basevol = mMasterVolume * mSFXVolume;
|
float basevol = volumeFromType((PlayType)(mode&Play_TypeMask));
|
||||||
float min, max;
|
float min, max;
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
std::string file = lookup(soundId, volume, min, max);
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();;
|
const ESM::Position &pos = ptr.getRefData().getPosition();;
|
||||||
|
@ -536,16 +557,13 @@ namespace MWSound
|
||||||
SoundMap::iterator snditer = mActiveSounds.begin();
|
SoundMap::iterator snditer = mActiveSounds.begin();
|
||||||
while(snditer != mActiveSounds.end())
|
while(snditer != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
if((snditer->first->mFlags&MWBase::SoundManager::Play_TypeVoice))
|
snditer->first->mBaseVolume = volumeFromType(snditer->first->getPlayType());
|
||||||
snditer->first->mBaseVolume = mMasterVolume * mVoiceVolume;
|
|
||||||
else
|
|
||||||
snditer->first->mBaseVolume = mMasterVolume * mSFXVolume;
|
|
||||||
snditer->first->update();
|
snditer->first->update();
|
||||||
snditer++;
|
snditer++;
|
||||||
}
|
}
|
||||||
if(mMusic)
|
if(mMusic)
|
||||||
{
|
{
|
||||||
mMusic->mBaseVolume = mMasterVolume * mMusicVolume;
|
mMusic->mBaseVolume = volumeFromType(mMusic->getPlayType());
|
||||||
mMusic->update();
|
mMusic->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ namespace MWSound
|
||||||
void updateSounds(float duration);
|
void updateSounds(float duration);
|
||||||
void updateRegionSound(float duration);
|
void updateRegionSound(float duration);
|
||||||
|
|
||||||
|
float volumeFromType(PlayType type) const;
|
||||||
|
|
||||||
SoundManager(const SoundManager &rhs);
|
SoundManager(const SoundManager &rhs);
|
||||||
SoundManager& operator=(const SoundManager &rhs);
|
SoundManager& operator=(const SoundManager &rhs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue