2012-03-17 02:45:18 -07:00
|
|
|
#ifndef GAME_SOUND_SOUND_H
|
|
|
|
#define GAME_SOUND_SOUND_H
|
|
|
|
|
2017-06-13 18:55:22 +09:00
|
|
|
#include <algorithm>
|
|
|
|
|
2015-12-02 05:18:43 -08:00
|
|
|
#include "sound_output.hpp"
|
2012-07-16 23:54:04 +04:00
|
|
|
|
2012-03-17 02:45:18 -07:00
|
|
|
namespace MWSound
|
|
|
|
{
|
2015-11-30 07:32:42 -08:00
|
|
|
class Sound {
|
2012-03-24 03:49:03 -07:00
|
|
|
Sound& operator=(const Sound &rhs);
|
|
|
|
Sound(const Sound &rhs);
|
|
|
|
|
2015-05-12 19:02:56 +02:00
|
|
|
osg::Vec3f mPos;
|
2012-03-28 04:58:47 -07:00
|
|
|
float mVolume; /* NOTE: Real volume = mVolume*mBaseVolume */
|
|
|
|
float mBaseVolume;
|
2012-03-31 10:41:12 -07:00
|
|
|
float mPitch;
|
2012-03-28 04:58:47 -07:00
|
|
|
float mMinDistance;
|
|
|
|
float mMaxDistance;
|
2012-03-31 08:14:39 -07:00
|
|
|
int mFlags;
|
2015-11-26 09:11:52 -08:00
|
|
|
|
2013-07-26 18:43:06 +02:00
|
|
|
float mFadeOutTime;
|
2012-03-28 04:58:47 -07:00
|
|
|
|
2015-11-30 05:42:51 -08:00
|
|
|
protected:
|
2015-12-02 05:18:43 -08:00
|
|
|
Sound_Instance mHandle;
|
2015-11-30 05:42:51 -08:00
|
|
|
|
|
|
|
friend class OpenAL_Output;
|
|
|
|
|
2012-03-17 02:45:18 -07:00
|
|
|
public:
|
2015-05-12 19:02:56 +02:00
|
|
|
void setPosition(const osg::Vec3f &pos) { mPos = pos; }
|
2012-03-30 07:10:34 -07:00
|
|
|
void setVolume(float volume) { mVolume = volume; }
|
2015-11-26 09:11:52 -08:00
|
|
|
void setBaseVolume(float volume) { mBaseVolume = volume; }
|
|
|
|
void setFadeout(float duration) { mFadeOutTime = duration; }
|
|
|
|
void updateFade(float duration)
|
|
|
|
{
|
|
|
|
if(mFadeOutTime > 0.0f)
|
|
|
|
{
|
|
|
|
float soundDuration = std::min(duration, mFadeOutTime);
|
|
|
|
mVolume *= (mFadeOutTime-soundDuration) / mFadeOutTime;
|
|
|
|
mFadeOutTime -= soundDuration;
|
|
|
|
}
|
|
|
|
}
|
2014-07-29 00:26:26 +02:00
|
|
|
|
2015-11-30 14:34:14 -08:00
|
|
|
const osg::Vec3f &getPosition() const { return mPos; }
|
|
|
|
float getRealVolume() const { return mVolume * mBaseVolume; }
|
|
|
|
float getPitch() const { return mPitch; }
|
2015-12-02 06:35:35 -08:00
|
|
|
float getMinDistance() const { return mMinDistance; }
|
2015-11-30 14:34:14 -08:00
|
|
|
float getMaxDistance() const { return mMaxDistance; }
|
|
|
|
|
2012-12-18 02:01:04 -08:00
|
|
|
MWBase::SoundManager::PlayType getPlayType() const
|
|
|
|
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
2015-11-30 14:34:14 -08:00
|
|
|
bool getUseEnv() const { return !(mFlags&MWBase::SoundManager::Play_NoEnv); }
|
2015-12-02 06:35:35 -08:00
|
|
|
bool getIsLooping() const { return mFlags&MWBase::SoundManager::Play_Loop; }
|
2015-11-26 09:11:52 -08:00
|
|
|
bool getDistanceCull() const { return mFlags&MWBase::SoundManager::Play_RemoveAtDistance; }
|
2015-11-26 09:33:16 -08:00
|
|
|
bool getIs3D() const { return mFlags&Play_3D; }
|
2012-12-18 02:01:04 -08:00
|
|
|
|
2015-05-12 19:02:56 +02:00
|
|
|
Sound(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
2015-11-30 05:42:51 -08:00
|
|
|
: mPos(pos), mVolume(vol), mBaseVolume(basevol), mPitch(pitch)
|
|
|
|
, mMinDistance(mindist), mMaxDistance(maxdist), mFlags(flags)
|
|
|
|
, mFadeOutTime(0.0f), mHandle(0)
|
2012-03-28 04:58:47 -07:00
|
|
|
{ }
|
2015-11-30 14:51:41 -08:00
|
|
|
Sound(float vol, float basevol, float pitch, int flags)
|
|
|
|
: mPos(0.0f, 0.0f, 0.0f), mVolume(vol), mBaseVolume(basevol), mPitch(pitch)
|
|
|
|
, mMinDistance(1.0f), mMaxDistance(1000.0f), mFlags(flags)
|
|
|
|
, mFadeOutTime(0.0f), mHandle(0)
|
|
|
|
{ }
|
2015-11-30 07:32:42 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Same as above, but it's a different type since the output handles them differently
|
|
|
|
class Stream : public Sound {
|
|
|
|
Stream& operator=(const Stream &rhs);
|
|
|
|
Stream(const Stream &rhs);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Stream(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
|
|
|
: Sound(pos, vol, basevol, pitch, mindist, maxdist, flags)
|
|
|
|
{ }
|
2015-11-30 14:51:41 -08:00
|
|
|
Stream(float vol, float basevol, float pitch, int flags)
|
|
|
|
: Sound(vol, basevol, pitch, flags)
|
|
|
|
{ }
|
2012-03-17 02:45:18 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|