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 
12 #include "sound_output.hpp"
13 
14 namespace MWSound
15 {
16  class SoundManager;
17  class Sound;
18 
19  class OpenAL_Output : public Sound_Output
20  {
21  ALCdevice *mDevice;
22  ALCcontext *mContext;
23 
24  typedef std::deque<ALuint> IDDq;
26 
27  typedef std::vector<MWBase::SoundPtr> SoundVec;
29  typedef std::vector<MWBase::SoundStreamPtr> StreamVec;
31 
32  osg::Vec3f mListenerPos;
34 
35  struct StreamThread;
36  std::auto_ptr<StreamThread> mStreamThread;
37 
38  void initCommon2D(ALuint source, const osg::Vec3f &pos, ALfloat gain, ALfloat pitch, bool loop, bool useenv);
39  void initCommon3D(ALuint source, const osg::Vec3f &pos, ALfloat mindist, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool loop, bool useenv);
40 
41  void updateCommon(ALuint source, const osg::Vec3f &pos, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool useenv, bool is3d);
42 
44  OpenAL_Output(const OpenAL_Output &rhs);
45 
46  public:
47  virtual std::vector<std::string> enumerate();
48  virtual void init(const std::string &devname=std::string());
49  virtual void deinit();
50 
51  virtual std::vector<std::string> enumerateHrtf();
52  virtual void enableHrtf(const std::string &hrtfname, bool auto_enable);
53  virtual void disableHrtf();
54 
55  virtual Sound_Handle loadSound(const std::string &fname);
56  virtual void unloadSound(Sound_Handle data);
57  virtual size_t getSoundDataSize(Sound_Handle data) const;
58 
59  virtual void playSound(MWBase::SoundPtr sound, Sound_Handle data, float offset);
60  virtual void playSound3D(MWBase::SoundPtr sound, Sound_Handle data, float offset);
61  virtual void finishSound(MWBase::SoundPtr sound);
62  virtual bool isSoundPlaying(MWBase::SoundPtr sound);
63  virtual void updateSound(MWBase::SoundPtr sound);
64 
65  virtual void streamSound(DecoderPtr decoder, MWBase::SoundStreamPtr sound);
66  virtual void streamSound3D(DecoderPtr decoder, MWBase::SoundStreamPtr sound, bool getLoudnessData);
67  virtual void finishStream(MWBase::SoundStreamPtr sound);
68  virtual double getStreamDelay(MWBase::SoundStreamPtr sound);
69  virtual double getStreamOffset(MWBase::SoundStreamPtr sound);
70  virtual float getStreamLoudness(MWBase::SoundStreamPtr sound);
71  virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound);
72  virtual void updateStream(MWBase::SoundStreamPtr sound);
73 
74  virtual void startUpdate();
75  virtual void finishUpdate();
76 
77  virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env);
78 
79  virtual void pauseSounds(int types);
80  virtual void resumeSounds(int types);
81 
83  virtual ~OpenAL_Output();
84  };
85 #ifndef DEFAULT_OUTPUT
86 #define DEFAULT_OUTPUT(x) ::MWSound::OpenAL_Output((x))
87 #endif
88 }
89 
90 #endif
virtual void streamSound3D(DecoderPtr decoder, MWBase::SoundStreamPtr sound, bool getLoudnessData)
Definition: openal_output.cpp:974
void * Sound_Handle
Definition: sound_output.hpp:14
Definition: openal_output.hpp:19
osg::Vec3f mListenerPos
Definition: openal_output.hpp:32
virtual void init(const std::string &devname=std::string())
Definition: openal_output.cpp:515
Environment mListenerEnv
Definition: openal_output.hpp:33
OpenAL_Output(const OpenAL_Output &rhs)
std::auto_ptr< StreamThread > mStreamThread
Definition: openal_output.hpp:35
virtual std::vector< std::string > enumerate()
Definition: openal_output.cpp:498
std::vector< MWBase::SoundPtr > SoundVec
Definition: openal_output.hpp:27
ALCdevice * mDevice
Definition: openal_output.hpp:21
virtual void unloadSound(Sound_Handle data)
Definition: openal_output.cpp:745
virtual ~OpenAL_Output()
Definition: openal_output.cpp:1155
virtual void finishSound(MWBase::SoundPtr sound)
Definition: openal_output.cpp:905
virtual size_t getSoundDataSize(Sound_Handle data) const
Definition: openal_output.cpp:767
void initCommon3D(ALuint source, const osg::Vec3f &pos, ALfloat mindist, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool loop, bool useenv)
Definition: openal_output.cpp:800
std::vector< MWBase::SoundStreamPtr > StreamVec
Definition: openal_output.hpp:29
virtual void updateSound(MWBase::SoundPtr sound)
Definition: openal_output.cpp:933
ALCcontext * mContext
Definition: openal_output.hpp:22
virtual void finishUpdate()
Definition: openal_output.cpp:1073
virtual void enableHrtf(const std::string &hrtfname, bool auto_enable)
Definition: openal_output.cpp:621
virtual float getStreamLoudness(MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:1041
virtual void resumeSounds(int types)
Definition: openal_output.cpp:1122
virtual void pauseSounds(int types)
Definition: openal_output.cpp:1097
boost::shared_ptr< Sound_Decoder > DecoderPtr
Definition: soundmanager.hpp:19
virtual void startUpdate()
Definition: openal_output.cpp:1068
virtual void updateStream(MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:1057
IDDq mFreeSources
Definition: openal_output.hpp:25
virtual bool isSoundPlaying(MWBase::SoundPtr sound)
Definition: openal_output.cpp:921
virtual void streamSound(DecoderPtr decoder, MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:943
Definition: openal_output.cpp:250
virtual void deinit()
Definition: openal_output.cpp:577
boost::shared_ptr< MWSound::Stream > SoundStreamPtr
Definition: soundmanager.hpp:26
void initCommon2D(ALuint source, const osg::Vec3f &pos, ALfloat gain, ALfloat pitch, bool loop, bool useenv)
Definition: openal_output.cpp:779
virtual double getStreamDelay(MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:1026
virtual void disableHrtf()
Definition: openal_output.cpp:676
StreamVec mActiveStreams
Definition: openal_output.hpp:30
virtual double getStreamOffset(MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:1033
virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env)
Definition: openal_output.cpp:1079
SoundVec mActiveSounds
Definition: openal_output.hpp:28
Definition: soundmanagerimp.hpp:45
Definition: sound_output.hpp:21
void updateCommon(ALuint source, const osg::Vec3f &pos, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool useenv, bool is3d)
Definition: openal_output.cpp:823
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:1049
virtual void playSound(MWBase::SoundPtr sound, Sound_Handle data, float offset)
Definition: openal_output.cpp:844
virtual void playSound3D(MWBase::SoundPtr sound, Sound_Handle data, float offset)
Definition: openal_output.cpp:874
std::deque< ALuint > IDDq
Definition: openal_output.hpp:24
virtual std::vector< std::string > enumerateHrtf()
Definition: openal_output.cpp:597
virtual void finishStream(MWBase::SoundStreamPtr sound)
Definition: openal_output.cpp:1005
virtual Sound_Handle loadSound(const std::string &fname)
Definition: openal_output.cpp:702
boost::shared_ptr< MWSound::Sound > SoundPtr
Definition: soundmanager.hpp:25
Environment
Definition: soundmanagerimp.hpp:35
OpenAL_Output & operator=(const OpenAL_Output &rhs)