1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 15:49:56 +00:00
openmw-tes3mp/apps/openmw/mwsound/sound.hpp

102 lines
3.1 KiB
C++
Raw Normal View History

2012-03-17 09:45:18 +00:00
#ifndef GAME_SOUND_SOUND_H
#define GAME_SOUND_SOUND_H
2017-06-13 09:55:22 +00:00
#include <algorithm>
#include "sound_output.hpp"
2012-03-17 09:45:18 +00:00
namespace MWSound
{
// Extra play flags, not intended for caller use
enum PlayModeEx
{
Play_2D = 0,
Play_3D = 1 << 31,
};
// For testing individual PlayMode flags
inline int operator&(int a, PlayMode b) { return a & static_cast<int>(b); }
inline int operator&(PlayMode a, PlayMode b) { return static_cast<int>(a) & static_cast<int>(b); }
2020-07-12 13:25:14 +00:00
struct SoundParams
{
osg::Vec3f mPos;
float mVolume = 1;
float mBaseVolume = 1;
float mPitch = 1;
float mMinDistance = 1;
float mMaxDistance = 1000;
int mFlags = 0;
float mFadeOutTime = 0;
};
class SoundBase {
SoundBase& operator=(const SoundBase&) = delete;
SoundBase(const SoundBase&) = delete;
SoundBase(SoundBase&&) = delete;
2020-07-12 13:25:14 +00:00
SoundParams mParams;
protected:
2020-07-12 13:25:14 +00:00
Sound_Instance mHandle = nullptr;
friend class OpenAL_Output;
2012-03-17 09:45:18 +00:00
public:
2020-07-12 13:25:14 +00:00
void setPosition(const osg::Vec3f &pos) { mParams.mPos = pos; }
void setVolume(float volume) { mParams.mVolume = volume; }
void setBaseVolume(float volume) { mParams.mBaseVolume = volume; }
void setFadeout(float duration) { mParams.mFadeOutTime = duration; }
2015-11-26 17:11:52 +00:00
void updateFade(float duration)
{
2020-07-12 13:25:14 +00:00
if (mParams.mFadeOutTime > 0.0f)
2015-11-26 17:11:52 +00:00
{
2020-07-12 13:25:14 +00:00
float soundDuration = std::min(duration, mParams.mFadeOutTime);
mParams.mVolume *= (mParams.mFadeOutTime - soundDuration) / mParams.mFadeOutTime;
mParams.mFadeOutTime -= soundDuration;
2015-11-26 17:11:52 +00:00
}
}
2020-07-12 13:25:14 +00:00
const osg::Vec3f &getPosition() const { return mParams.mPos; }
float getRealVolume() const { return mParams.mVolume * mParams.mBaseVolume; }
float getPitch() const { return mParams.mPitch; }
float getMinDistance() const { return mParams.mMinDistance; }
float getMaxDistance() const { return mParams.mMaxDistance; }
2015-11-30 22:34:14 +00:00
MWSound::Type getPlayType() const
2020-07-12 13:25:14 +00:00
{ return static_cast<MWSound::Type>(mParams.mFlags & MWSound::Type::Mask); }
bool getUseEnv() const { return !(mParams.mFlags & MWSound::PlayMode::NoEnv); }
bool getIsLooping() const { return mParams.mFlags & MWSound::PlayMode::Loop; }
bool getDistanceCull() const { return mParams.mFlags & MWSound::PlayMode::RemoveAtDistance; }
bool getIs3D() const { return mParams.mFlags & Play_3D; }
2020-07-12 13:25:14 +00:00
void init(const SoundParams& params)
{
2020-07-12 13:25:14 +00:00
mParams = params;
mHandle = nullptr;
}
2020-07-12 13:25:14 +00:00
SoundBase() = default;
};
class Sound : public SoundBase {
Sound& operator=(const Sound&) = delete;
Sound(const Sound&) = delete;
Sound(Sound&&) = delete;
public:
Sound() { }
};
class Stream : public SoundBase {
Stream& operator=(const Stream&) = delete;
Stream(const Stream&) = delete;
Stream(Stream&&) = delete;
public:
Stream() { }
2012-03-17 09:45:18 +00:00
};
}
#endif