OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
soundmanager.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWBASE_SOUNDMANAGER_H
2 #define GAME_MWBASE_SOUNDMANAGER_H
3 
4 #include <memory>
5 #include <string>
6 #include <set>
7 
8 #include "../mwworld/ptr.hpp"
9 
10 namespace MWWorld
11 {
12  class CellStore;
13 }
14 
15 namespace MWSound
16 {
17  class Sound;
18  class Stream;
19  struct Sound_Decoder;
20  typedef std::shared_ptr<Sound_Decoder> DecoderPtr;
21 
22  /* These must all fit together */
23  enum class PlayMode {
24  Normal = 0, /* non-looping, affected by environment */
25  Loop = 1<<0, /* Sound will continually loop until explicitly stopped */
26  NoEnv = 1<<1, /* Do not apply environment effects (eg, underwater filters) */
27  RemoveAtDistance = 1<<2, /* (3D only) If the listener gets further than 2000 units away
28  * from the sound source, the sound is removed.
29  * This is weird stuff but apparently how vanilla works for sounds
30  * played by the PlayLoopSound family of script functions. Perhaps
31  * we can make this cut off a more subtle fade later, but have to
32  * be careful to not change the overall volume of areas by too
33  * much. */
34  NoPlayerLocal = 1<<3, /* (3D only) Don't play the sound local to the listener even if the
35  * player is making it. */
36  LoopNoEnv = Loop | NoEnv,
38  };
39  enum class Type {
40  Sfx = 1<<4, /* Normal SFX sound */
41  Voice = 1<<5, /* Voice sound */
42  Foot = 1<<6, /* Footstep sound */
43  Music = 1<<7, /* Music track */
44  Movie = 1<<8, /* Movie audio track */
45  Mask = Sfx | Voice | Foot | Music | Movie
46  };
47  // Used for creating a type mask for SoundManager::pauseSounds and resumeSounds
48  inline int operator~(Type a) { return ~static_cast<int>(a); }
49  inline int operator&(Type a, Type b) { return static_cast<int>(a) & static_cast<int>(b); }
50  inline int operator&(int a, Type b) { return a & static_cast<int>(b); }
51  inline int operator|(Type a, Type b) { return static_cast<int>(a) | static_cast<int>(b); }
52 }
53 
54 namespace MWBase
55 {
58 
61  {
62  SoundManager (const SoundManager&);
64 
67 
68  protected:
71 
72  public:
74  virtual ~SoundManager() {}
75 
76  virtual void processChangedSettings(const std::set< std::pair<std::string, std::string> >& settings) = 0;
77 
78  virtual void stopMusic() = 0;
80 
81  virtual void streamMusic(const std::string& filename) = 0;
84 
85  virtual bool isMusicPlaying() = 0;
87 
88  virtual void playPlaylist(const std::string &playlist) = 0;
91 
92  virtual void say(const MWWorld::ConstPtr &reference, const std::string& filename) = 0;
95 
96  virtual void say(const std::string& filename) = 0;
99 
100  virtual bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const = 0;
102 
103  virtual void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) = 0;
105 
106  virtual float getSaySoundLoudness(const MWWorld::ConstPtr& reference) const = 0;
110 
111  virtual SoundStream *playTrack(const MWSound::DecoderPtr& decoder, Type type) = 0;
114 
115  virtual void stopTrack(SoundStream *stream) = 0;
117 
118  virtual double getTrackTimeDelay(SoundStream *stream) = 0;
122 
123  virtual Sound *playSound(const std::string& soundId, float volume, float pitch,
124  Type type=Type::Sfx, PlayMode mode=PlayMode::Normal,
125  float offset=0) = 0;
128 
129  virtual Sound *playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId,
130  float volume, float pitch, Type type=Type::Sfx,
131  PlayMode mode=PlayMode::Normal, float offset=0) = 0;
134 
135  virtual Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
136  float volume, float pitch, Type type=Type::Sfx,
137  PlayMode mode=PlayMode::Normal, float offset=0) = 0;
139 
140  virtual void stopSound(Sound *sound) = 0;
142 
143  virtual void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) = 0;
145 
146  virtual void stopSound3D(const MWWorld::ConstPtr &reference) = 0;
148 
149  virtual void stopSound(const MWWorld::CellStore *cell) = 0;
151 
152  virtual void stopSound(const std::string& soundId) = 0;
154 
155  virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) = 0;
160 
161  virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const = 0;
164 
165  virtual void pauseSounds(int types=static_cast<int>(Type::Mask)) = 0;
167 
168  virtual void resumeSounds(int types=static_cast<int>(Type::Mask)) = 0;
170 
171  virtual void update(float duration) = 0;
172 
173  virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) = 0;
174 
175  virtual void updatePtr(const MWWorld::ConstPtr& old, const MWWorld::ConstPtr& updated) = 0;
176 
177  virtual void clear() = 0;
178  };
179 }
180 
181 #endif
virtual void playPlaylist(const std::string &playlist)=0
SoundManager & operator=(const SoundManager &)
not implemented
virtual void stopSound(Sound *sound)=0
Stop the given sound from playing.
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater)=0
MWSound::Type Type
Definition: soundmanager.hpp:70
virtual Sound * playSound(const std::string &soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0)=0
int operator~(Type a)
Definition: soundmanager.hpp:48
MWSound::Sound Sound
Definition: soundmanager.hpp:56
virtual double getTrackTimeDelay(SoundStream *stream)=0
PlayMode
Definition: soundmanager.hpp:23
Definition: sound.hpp:95
virtual void resumeSounds(int types=static_cast< int >(Type::Mask))=0
Resumes all previously paused sounds.
virtual void stopMusic()=0
Stops music if it's playing.
virtual bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const =0
Is actor not speaking?
virtual Sound * playSound3D(const MWWorld::ConstPtr &reference, const std::string &soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0)=0
virtual void streamMusic(const std::string &filename)=0
virtual void say(const MWWorld::ConstPtr &reference, const std::string &filename)=0
int operator|(Type a, Type b)
Definition: soundmanager.hpp:51
virtual void updatePtr(const MWWorld::ConstPtr &old, const MWWorld::ConstPtr &updated)=0
virtual bool isMusicPlaying()=0
Returns true if music is playing.
int operator&(Type a, Type b)
Definition: soundmanager.hpp:49
virtual void update(float duration)=0
virtual void clear()=0
Mutable state of a cell.
Definition: cellstore.hpp:51
virtual void processChangedSettings(const std::set< std::pair< std::string, std::string > > &settings)=0
virtual void stopTrack(SoundStream *stream)=0
Stop the given audio track from playing.
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
virtual float getSaySoundLoudness(const MWWorld::ConstPtr &reference) const =0
virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string &soundId) const =0
MWSound::PlayMode PlayMode
Definition: soundmanager.hpp:69
Interface for sound manager (implemented in MWSound)
Definition: soundmanager.hpp:60
virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string &soundId, float duration)=0
virtual ~SoundManager()
Definition: soundmanager.hpp:74
virtual void stopSound3D(const MWWorld::ConstPtr &reference, const std::string &soundId)=0
Stop the given object from playing the given sound,.
virtual void pauseSounds(int types=static_cast< int >(Type::Mask))=0
Pauses all currently playing sounds, including music.
virtual void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr())=0
Stop an actor speaking.
SoundManager()
Definition: soundmanager.hpp:73
std::shared_ptr< Sound_Decoder > DecoderPtr
Definition: soundmanager.hpp:19
Mask
Definition: mask.hpp:11
Definition: sound_decoder.hpp:33
virtual SoundStream * playTrack(const MWSound::DecoderPtr &decoder, Type type)=0
Type
Definition: soundmanager.hpp:39
Definition: sound.hpp:104