OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sound.hpp
Go to the documentation of this file.
1 #ifndef GAME_SOUND_SOUND_H
2 #define GAME_SOUND_SOUND_H
3 
4 #include "sound_output.hpp"
5 
6 namespace MWSound
7 {
8  class Sound {
9  Sound& operator=(const Sound &rhs);
10  Sound(const Sound &rhs);
11 
12  osg::Vec3f mPos;
13  float mVolume; /* NOTE: Real volume = mVolume*mBaseVolume */
14  float mBaseVolume;
15  float mPitch;
16  float mMinDistance;
17  float mMaxDistance;
18  int mFlags;
19 
20  float mFadeOutTime;
21 
22  protected:
24 
25  friend class OpenAL_Output;
26 
27  public:
28  void setPosition(const osg::Vec3f &pos) { mPos = pos; }
29  void setVolume(float volume) { mVolume = volume; }
30  void setBaseVolume(float volume) { mBaseVolume = volume; }
31  void setFadeout(float duration) { mFadeOutTime = duration; }
32  void updateFade(float duration)
33  {
34  if(mFadeOutTime > 0.0f)
35  {
36  float soundDuration = std::min(duration, mFadeOutTime);
37  mVolume *= (mFadeOutTime-soundDuration) / mFadeOutTime;
38  mFadeOutTime -= soundDuration;
39  }
40  }
41 
42  const osg::Vec3f &getPosition() const { return mPos; }
43  float getRealVolume() const { return mVolume * mBaseVolume; }
44  float getPitch() const { return mPitch; }
45  float getMinDistance() const { return mMinDistance; }
46  float getMaxDistance() const { return mMaxDistance; }
47 
53  bool getIs3D() const { return mFlags&Play_3D; }
54 
55  Sound(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
56  : mPos(pos), mVolume(vol), mBaseVolume(basevol), mPitch(pitch)
57  , mMinDistance(mindist), mMaxDistance(maxdist), mFlags(flags)
58  , mFadeOutTime(0.0f), mHandle(0)
59  { }
60  Sound(float vol, float basevol, float pitch, int flags)
61  : mPos(0.0f, 0.0f, 0.0f), mVolume(vol), mBaseVolume(basevol), mPitch(pitch)
62  , mMinDistance(1.0f), mMaxDistance(1000.0f), mFlags(flags)
63  , mFadeOutTime(0.0f), mHandle(0)
64  { }
65  };
66 
67  // Same as above, but it's a different type since the output handles them differently
68  class Stream : public Sound {
69  Stream& operator=(const Stream &rhs);
70  Stream(const Stream &rhs);
71 
72  public:
73  Stream(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
74  : Sound(pos, vol, basevol, pitch, mindist, maxdist, flags)
75  { }
76  Stream(float vol, float basevol, float pitch, int flags)
77  : Sound(vol, basevol, pitch, flags)
78  { }
79  };
80 }
81 
82 #endif
float mBaseVolume
Definition: sound.hpp:14
Sound(float vol, float basevol, float pitch, int flags)
Definition: sound.hpp:60
const osg::Vec3f & getPosition() const
Definition: sound.hpp:42
Definition: openal_output.hpp:19
bool getIsLooping() const
Definition: sound.hpp:51
bool getIs3D() const
Definition: sound.hpp:53
float getRealVolume() const
Definition: sound.hpp:43
float getMaxDistance() const
Definition: sound.hpp:46
Definition: soundmanager.hpp:54
Stream(const osg::Vec3f &pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
Definition: sound.hpp:73
void setPosition(const osg::Vec3f &pos)
Definition: sound.hpp:28
float getMinDistance() const
Definition: sound.hpp:45
float getPitch() const
Definition: sound.hpp:44
osg::Vec3f mPos
Definition: sound.hpp:12
Sound_Instance mHandle
Definition: sound.hpp:23
Definition: sound.hpp:8
Stream & operator=(const Stream &rhs)
PlayType
Definition: soundmanager.hpp:48
bool getUseEnv() const
Definition: sound.hpp:50
void * Sound_Instance
Definition: sound_output.hpp:19
Definition: soundmanagerimp.hpp:42
float mMaxDistance
Definition: sound.hpp:17
Definition: soundmanager.hpp:35
Stream(const Stream &rhs)
void setVolume(float volume)
Definition: sound.hpp:29
float mPitch
Definition: sound.hpp:15
void updateFade(float duration)
Definition: sound.hpp:32
Sound & operator=(const Sound &rhs)
float mMinDistance
Definition: sound.hpp:16
float mFadeOutTime
Definition: sound.hpp:20
int mFlags
Definition: sound.hpp:18
float mVolume
Definition: sound.hpp:13
MWBase::SoundManager::PlayType getPlayType() const
Definition: sound.hpp:48
Sound(const Sound &rhs)
Sound(const osg::Vec3f &pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
Definition: sound.hpp:55
Stream(float vol, float basevol, float pitch, int flags)
Definition: sound.hpp:76
bool getDistanceCull() const
Definition: sound.hpp:52
Definition: soundmanager.hpp:37
Definition: soundmanager.hpp:36
void setFadeout(float duration)
Definition: sound.hpp:31
void setBaseVolume(float volume)
Definition: sound.hpp:30
Definition: sound.hpp:68