OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
openal_output.hpp
Go to the documentation of this file.
1 #ifndef GAME_SOUND_OPENAL_OUTPUT_H
2 #define GAME_SOUND_OPENAL_OUTPUT_H
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <deque>
8 
9 #include "alc.h"
10 #include "al.h"
11 #include "alext.h"
12 
13 #include "sound_output.hpp"
14 
15 namespace MWSound
16 {
17  class SoundManager;
18  class Sound;
19  class Stream;
20 
21  class OpenAL_Output : public Sound_Output
22  {
23  ALCdevice *mDevice;
24  ALCcontext *mContext;
25 
26  struct {
27  bool EXT_EFX : 1;
28  bool SOFT_HRTF : 1;
29  } ALC = {false, false};
30  struct {
32  } AL = {false};
33 
34  typedef std::deque<ALuint> IDDq;
36 
37  typedef std::vector<Sound*> SoundVec;
39  typedef std::vector<Stream*> StreamVec;
41 
42  osg::Vec3f mListenerPos;
44 
45  ALuint mWaterFilter;
46  ALuint mWaterEffect;
48  ALuint mEffectSlot;
49 
50  struct StreamThread;
51  std::unique_ptr<StreamThread> mStreamThread;
52 
53  void initCommon2D(ALuint source, const osg::Vec3f &pos, ALfloat gain, ALfloat pitch, bool loop, bool useenv);
54  void initCommon3D(ALuint source, const osg::Vec3f &pos, ALfloat mindist, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool loop, bool useenv);
55 
56  void updateCommon(ALuint source, const osg::Vec3f &pos, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool useenv, bool is3d);
57 
59  OpenAL_Output(const OpenAL_Output &rhs);
60 
61  public:
62  virtual std::vector<std::string> enumerate();
63  virtual bool init(const std::string &devname, const std::string &hrtfname, HrtfMode hrtfmode);
64  virtual void deinit();
65 
66  virtual std::vector<std::string> enumerateHrtf();
67  virtual void setHrtf(const std::string &hrtfname, HrtfMode hrtfmode);
68 
69  virtual std::pair<Sound_Handle,size_t> loadSound(const std::string &fname);
70  virtual size_t unloadSound(Sound_Handle data);
71 
72  virtual bool playSound(Sound *sound, Sound_Handle data, float offset);
73  virtual bool playSound3D(Sound *sound, Sound_Handle data, float offset);
74  virtual void finishSound(Sound *sound);
75  virtual bool isSoundPlaying(Sound *sound);
76  virtual void updateSound(Sound *sound);
77 
78  virtual bool streamSound(DecoderPtr decoder, Stream *sound);
79  virtual bool streamSound3D(DecoderPtr decoder, Stream *sound, bool getLoudnessData);
80  virtual void finishStream(Stream *sound);
81  virtual double getStreamDelay(Stream *sound);
82  virtual double getStreamOffset(Stream *sound);
83  virtual float getStreamLoudness(Stream *sound);
84  virtual bool isStreamPlaying(Stream *sound);
85  virtual void updateStream(Stream *sound);
86 
87  virtual void startUpdate();
88  virtual void finishUpdate();
89 
90  virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env);
91 
92  virtual void pauseSounds(int types);
93  virtual void resumeSounds(int types);
94 
96  virtual ~OpenAL_Output();
97  };
98 #ifndef DEFAULT_OUTPUT
99 #define DEFAULT_OUTPUT(x) ::MWSound::OpenAL_Output((x))
100 #endif
101 }
102 
103 #endif
virtual float getStreamLoudness(Stream *sound)
Definition: openal_output.cpp:1348
void * Sound_Handle
Definition: sound_output.hpp:15
virtual double getStreamDelay(Stream *sound)
Definition: openal_output.cpp:1333
virtual bool isStreamPlaying(Stream *sound)
Definition: openal_output.cpp:1356
Definition: openal_output.hpp:21
struct MWSound::OpenAL_Output::@4 AL
osg::Vec3f mListenerPos
Definition: openal_output.hpp:42
Environment mListenerEnv
Definition: openal_output.hpp:43
virtual void updateStream(Stream *sound)
Definition: openal_output.cpp:1364
virtual bool playSound(Sound *sound, Sound_Handle data, float offset)
Definition: openal_output.cpp:1132
OpenAL_Output(const OpenAL_Output &rhs)
virtual void finishSound(Sound *sound)
Definition: openal_output.cpp:1211
virtual size_t unloadSound(Sound_Handle data)
Definition: openal_output.cpp:1002
virtual std::vector< std::string > enumerate()
Definition: openal_output.cpp:570
MWSound::Sound Sound
Definition: soundmanager.hpp:56
ALCdevice * mDevice
Definition: openal_output.hpp:23
ALuint mWaterFilter
Definition: openal_output.hpp:45
virtual ~OpenAL_Output()
Definition: openal_output.cpp:1490
Definition: sound.hpp:95
void initCommon3D(ALuint source, const osg::Vec3f &pos, ALfloat mindist, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool loop, bool useenv)
Definition: openal_output.cpp:1070
virtual bool playSound3D(Sound *sound, Sound_Handle data, float offset)
Definition: openal_output.cpp:1171
ALCcontext * mContext
Definition: openal_output.hpp:24
virtual std::pair< Sound_Handle, size_t > loadSound(const std::string &fname)
Definition: openal_output.cpp:945
virtual bool init(const std::string &devname, const std::string &hrtfname, HrtfMode hrtfmode)
Definition: openal_output.cpp:587
virtual void finishUpdate()
Definition: openal_output.cpp:1381
bool SOFT_HRTF
Definition: openal_output.hpp:28
struct MWSound::OpenAL_Output::@3 ALC
virtual void updateSound(Sound *sound)
Definition: openal_output.cpp:1239
virtual void resumeSounds(int types)
Definition: openal_output.cpp:1457
virtual void pauseSounds(int types)
Definition: openal_output.cpp:1434
virtual void finishStream(Stream *sound)
Definition: openal_output.cpp:1312
std::vector< Stream * > StreamVec
Definition: openal_output.hpp:39
ALuint mEffectSlot
Definition: openal_output.hpp:48
virtual void startUpdate()
Definition: openal_output.cpp:1376
IDDq mFreeSources
Definition: openal_output.hpp:35
Definition: openal_output.cpp:312
virtual void deinit()
Definition: openal_output.cpp:831
virtual bool isSoundPlaying(Sound *sound)
Definition: openal_output.cpp:1227
void initCommon2D(ALuint source, const osg::Vec3f &pos, ALfloat gain, ALfloat pitch, bool loop, bool useenv)
Definition: openal_output.cpp:1031
StreamVec mActiveStreams
Definition: openal_output.hpp:40
HrtfMode
Definition: sound_output.hpp:22
virtual bool streamSound3D(DecoderPtr decoder, Stream *sound, bool getLoudnessData)
Definition: openal_output.cpp:1281
virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env)
Definition: openal_output.cpp:1387
SoundVec mActiveSounds
Definition: openal_output.hpp:38
virtual double getStreamOffset(Stream *sound)
Definition: openal_output.cpp:1340
Definition: soundmanagerimp.hpp:45
bool EXT_EFX
Definition: openal_output.hpp:27
Definition: sound_output.hpp:28
void updateCommon(ALuint source, const osg::Vec3f &pos, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool useenv, bool is3d)
Definition: openal_output.cpp:1111
std::vector< Sound * > SoundVec
Definition: openal_output.hpp:37
std::shared_ptr< Sound_Decoder > DecoderPtr
Definition: soundmanager.hpp:19
virtual void setHrtf(const std::string &hrtfname, HrtfMode hrtfmode)
Definition: openal_output.cpp:886
ALuint mDefaultEffect
Definition: openal_output.hpp:47
bool SOFT_source_spatialize
Definition: openal_output.hpp:31
ALuint mWaterEffect
Definition: openal_output.hpp:46
virtual bool streamSound(DecoderPtr decoder, Stream *sound)
Definition: openal_output.cpp:1250
std::deque< ALuint > IDDq
Definition: openal_output.hpp:34
virtual std::vector< std::string > enumerateHrtf()
Definition: openal_output.cpp:864
Environment
Definition: soundmanagerimp.hpp:35
std::unique_ptr< StreamThread > mStreamThread
Definition: openal_output.hpp:50
OpenAL_Output & operator=(const OpenAL_Output &rhs)
Definition: sound.hpp:104