mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Store info calculated from the ESM::Sound record
This commit is contained in:
parent
edfcb45ad7
commit
e2beefd8b5
@ -57,7 +57,7 @@ add_openmw_dir (mwscript
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwsound
|
add_openmw_dir (mwsound
|
||||||
soundmanagerimp openal_output ffmpeg_decoder sound sound_decoder sound_output loudness movieaudiofactory
|
soundmanagerimp openal_output ffmpeg_decoder sound sound_buffer sound_decoder sound_output loudness movieaudiofactory
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwworld
|
add_openmw_dir (mwworld
|
||||||
|
26
apps/openmw/mwsound/sound_buffer.hpp
Normal file
26
apps/openmw/mwsound/sound_buffer.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef GAME_SOUND_SOUND_BUFFER_H
|
||||||
|
#define GAME_SOUND_SOUND_BUFFER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "soundmanagerimp.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace MWSound
|
||||||
|
{
|
||||||
|
class Sound_Buffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string mResourceName;
|
||||||
|
|
||||||
|
float mVolume;
|
||||||
|
float mMinDist, mMaxDist;
|
||||||
|
|
||||||
|
Sound_Buffer(std::string resname, float volume, float mindist, float maxdist)
|
||||||
|
: mResourceName(resname), mVolume(volume), mMinDist(mindist), mMaxDist(maxdist)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* GAME_SOUND_SOUND_BUFFER_H */
|
@ -18,6 +18,7 @@
|
|||||||
#include "../mwmechanics/actorutil.hpp"
|
#include "../mwmechanics/actorutil.hpp"
|
||||||
|
|
||||||
#include "sound_output.hpp"
|
#include "sound_output.hpp"
|
||||||
|
#include "sound_buffer.hpp"
|
||||||
#include "sound_decoder.hpp"
|
#include "sound_decoder.hpp"
|
||||||
#include "sound.hpp"
|
#include "sound.hpp"
|
||||||
|
|
||||||
@ -103,38 +104,48 @@ namespace MWSound
|
|||||||
return DecoderPtr(new DEFAULT_DECODER (mVFS));
|
return DecoderPtr(new DEFAULT_DECODER (mVFS));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert a soundId to file name, and modify the volume
|
// Lookup a soundid for its sound data (resource name, local volume,
|
||||||
// according to the sounds local volume setting, minRange and
|
// minRange and maxRange. The returned pointer is only valid temporarily.
|
||||||
// maxRange.
|
const Sound_Buffer *SoundManager::lookup(const std::string &soundId)
|
||||||
std::string SoundManager::lookup(const std::string &soundId,
|
|
||||||
float &volume, float &min, float &max)
|
|
||||||
{
|
{
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
NameBufferMap::iterator sfxiter = mSoundBuffers.find(soundId);
|
||||||
const ESM::Sound *snd = world->getStore().get<ESM::Sound>().find(soundId);
|
if(sfxiter == mSoundBuffers.end())
|
||||||
|
|
||||||
volume *= static_cast<float>(pow(10.0, (snd->mData.mVolume / 255.0*3348.0 - 3348.0) / 2000.0));
|
|
||||||
|
|
||||||
if(snd->mData.mMinRange == 0 && snd->mData.mMaxRange == 0)
|
|
||||||
{
|
{
|
||||||
static const float fAudioDefaultMinDistance = world->getStore().get<ESM::GameSetting>().find("fAudioDefaultMinDistance")->getFloat();
|
// TODO: We could process all available ESM::Sound records on init
|
||||||
static const float fAudioDefaultMaxDistance = world->getStore().get<ESM::GameSetting>().find("fAudioDefaultMaxDistance")->getFloat();
|
// to pre-fill a non-resizing list, which would allow subsystems to
|
||||||
min = fAudioDefaultMinDistance;
|
// reference sounds by index instead of string.
|
||||||
max = fAudioDefaultMaxDistance;
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
}
|
const ESM::Sound *snd = world->getStore().get<ESM::Sound>().find(soundId);
|
||||||
else
|
|
||||||
{
|
|
||||||
min = snd->mData.mMinRange;
|
|
||||||
max = snd->mData.mMaxRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const float fAudioMinDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMinDistanceMult")->getFloat();
|
float volume, min, max;
|
||||||
static const float fAudioMaxDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMaxDistanceMult")->getFloat();
|
volume = static_cast<float>(pow(10.0, (snd->mData.mVolume / 255.0*3348.0 - 3348.0) / 2000.0));
|
||||||
min *= fAudioMinDistanceMult;
|
|
||||||
max *= fAudioMaxDistanceMult;
|
|
||||||
min = std::max(min, 1.0f);
|
|
||||||
max = std::max(min, max);
|
|
||||||
|
|
||||||
return "Sound/"+snd->mSound;
|
if(snd->mData.mMinRange == 0 && snd->mData.mMaxRange == 0)
|
||||||
|
{
|
||||||
|
static const float fAudioDefaultMinDistance = world->getStore().get<ESM::GameSetting>().find("fAudioDefaultMinDistance")->getFloat();
|
||||||
|
static const float fAudioDefaultMaxDistance = world->getStore().get<ESM::GameSetting>().find("fAudioDefaultMaxDistance")->getFloat();
|
||||||
|
min = fAudioDefaultMinDistance;
|
||||||
|
max = fAudioDefaultMaxDistance;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
min = snd->mData.mMinRange;
|
||||||
|
max = snd->mData.mMaxRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const float fAudioMinDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMinDistanceMult")->getFloat();
|
||||||
|
static const float fAudioMaxDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMaxDistanceMult")->getFloat();
|
||||||
|
min *= fAudioMinDistanceMult;
|
||||||
|
max *= fAudioMaxDistanceMult;
|
||||||
|
min = std::max(min, 1.0f);
|
||||||
|
max = std::max(min, max);
|
||||||
|
|
||||||
|
sfxiter = mSoundBuffers.insert(std::make_pair(
|
||||||
|
soundId, Sound_Buffer("Sound/"+snd->mSound, volume, min, max)
|
||||||
|
)).first;
|
||||||
|
mVFS->normalizeFilename(sfxiter->second.mResourceName);
|
||||||
|
}
|
||||||
|
return &sfxiter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the combined volume settings for the given sound type
|
// Gets the combined volume settings for the given sound type
|
||||||
@ -268,7 +279,7 @@ namespace MWSound
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
float basevol = volumeFromType(Play_TypeVoice);
|
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 osg::Vec3f objpos(pos.asVec3());
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
|
|
||||||
@ -371,11 +382,12 @@ namespace MWSound
|
|||||||
return sound;
|
return sound;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const Sound_Buffer *sfx = lookup(Misc::StringUtils::lowerCase(soundId));
|
||||||
float basevol = volumeFromType(type);
|
float basevol = volumeFromType(type);
|
||||||
float min, max;
|
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
|
||||||
|
|
||||||
sound = mOutput->playSound(file, volume, basevol, pitch, mode|type, offset);
|
sound = mOutput->playSound(sfx->mResourceName,
|
||||||
|
volume * sfx->mVolume, basevol, pitch, mode|type, offset
|
||||||
|
);
|
||||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||||
}
|
}
|
||||||
catch(std::exception&)
|
catch(std::exception&)
|
||||||
@ -394,18 +406,17 @@ namespace MWSound
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Look up the sound in the ESM data
|
// Look up the sound in the ESM data
|
||||||
|
const Sound_Buffer *sfx = lookup(Misc::StringUtils::lowerCase(soundId));
|
||||||
float basevol = volumeFromType(type);
|
float basevol = volumeFromType(type);
|
||||||
float min, max;
|
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
const ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const osg::Vec3f objpos(pos.asVec3());
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
|
|
||||||
if ((mode & Play_RemoveAtDistance) && (mListenerPos-objpos).length2() > 2000*2000)
|
if((mode&Play_RemoveAtDistance) && (mListenerPos-objpos).length2() > 2000*2000)
|
||||||
{
|
|
||||||
return MWBase::SoundPtr();
|
return MWBase::SoundPtr();
|
||||||
}
|
|
||||||
|
|
||||||
sound = mOutput->playSound3D(file, objpos, volume, basevol, pitch, min, max, mode|type, offset);
|
sound = mOutput->playSound3D(sfx->mResourceName,
|
||||||
|
objpos, volume * sfx->mVolume, basevol, pitch, sfx->mMinDist, sfx->mMaxDist, mode|type, offset
|
||||||
|
);
|
||||||
if((mode&Play_NoTrack))
|
if((mode&Play_NoTrack))
|
||||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||||
else
|
else
|
||||||
@ -427,11 +438,12 @@ namespace MWSound
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Look up the sound in the ESM data
|
// Look up the sound in the ESM data
|
||||||
|
const Sound_Buffer *sfx = lookup(Misc::StringUtils::lowerCase(soundId));
|
||||||
float basevol = volumeFromType(type);
|
float basevol = volumeFromType(type);
|
||||||
float min, max;
|
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
|
||||||
|
|
||||||
sound = mOutput->playSound3D(file, initialPos, volume, basevol, pitch, min, max, mode|type, offset);
|
sound = mOutput->playSound3D(sfx->mResourceName,
|
||||||
|
initialPos, volume * sfx->mVolume, basevol, pitch, sfx->mMinDist, sfx->mMaxDist, mode|type, offset
|
||||||
|
);
|
||||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||||
}
|
}
|
||||||
catch(std::exception &)
|
catch(std::exception &)
|
||||||
|
@ -21,6 +21,7 @@ namespace MWSound
|
|||||||
class Sound_Output;
|
class Sound_Output;
|
||||||
struct Sound_Decoder;
|
struct Sound_Decoder;
|
||||||
class Sound;
|
class Sound;
|
||||||
|
class Sound_Buffer;
|
||||||
|
|
||||||
enum Environment {
|
enum Environment {
|
||||||
Env_Normal,
|
Env_Normal,
|
||||||
@ -43,6 +44,9 @@ namespace MWSound
|
|||||||
float mVoiceVolume;
|
float mVoiceVolume;
|
||||||
float mFootstepsVolume;
|
float mFootstepsVolume;
|
||||||
|
|
||||||
|
typedef std::map<std::string,Sound_Buffer> NameBufferMap;
|
||||||
|
NameBufferMap mSoundBuffers;
|
||||||
|
|
||||||
boost::shared_ptr<Sound> mMusic;
|
boost::shared_ptr<Sound> mMusic;
|
||||||
std::string mCurrentPlaylist;
|
std::string mCurrentPlaylist;
|
||||||
|
|
||||||
@ -59,8 +63,8 @@ namespace MWSound
|
|||||||
|
|
||||||
int mPausedSoundTypes;
|
int mPausedSoundTypes;
|
||||||
|
|
||||||
std::string lookup(const std::string &soundId,
|
const Sound_Buffer *lookup(const std::string &soundId);
|
||||||
float &volume, float &min, float &max);
|
|
||||||
void streamMusicFull(const std::string& filename);
|
void streamMusicFull(const std::string& filename);
|
||||||
bool isPlaying(const MWWorld::Ptr &ptr, const std::string &id) const;
|
bool isPlaying(const MWWorld::Ptr &ptr, const std::string &id) const;
|
||||||
void updateSounds(float duration);
|
void updateSounds(float duration);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user