2012-03-16 22:12:17 -07:00
|
|
|
#ifndef GAME_SOUND_OPENAL_OUTPUT_H
|
|
|
|
#define GAME_SOUND_OPENAL_OUTPUT_H
|
|
|
|
|
2012-03-16 23:40:07 -07:00
|
|
|
#include <string>
|
2012-03-19 07:11:01 -07:00
|
|
|
#include <vector>
|
2012-03-19 10:33:06 -07:00
|
|
|
#include <map>
|
|
|
|
#include <deque>
|
2012-03-16 22:12:17 -07:00
|
|
|
|
|
|
|
#include "alc.h"
|
|
|
|
#include "al.h"
|
2017-09-11 22:17:36 -07:00
|
|
|
#include "alext.h"
|
2012-03-16 22:12:17 -07:00
|
|
|
|
2012-03-16 23:40:07 -07:00
|
|
|
#include "sound_output.hpp"
|
|
|
|
|
2012-03-16 22:12:17 -07:00
|
|
|
namespace MWSound
|
|
|
|
{
|
2012-03-16 23:40:07 -07:00
|
|
|
class SoundManager;
|
2012-03-17 02:55:08 -07:00
|
|
|
class Sound;
|
2017-09-11 21:33:18 -07:00
|
|
|
class Stream;
|
2012-03-16 23:40:07 -07:00
|
|
|
|
2012-03-16 22:12:17 -07:00
|
|
|
class OpenAL_Output : public Sound_Output
|
|
|
|
{
|
2012-03-18 11:30:53 -07:00
|
|
|
ALCdevice *mDevice;
|
|
|
|
ALCcontext *mContext;
|
2012-03-16 22:12:17 -07:00
|
|
|
|
2017-09-12 03:53:53 -07:00
|
|
|
struct {
|
2017-09-14 04:48:12 -07:00
|
|
|
bool EXT_EFX : 1;
|
|
|
|
bool SOFT_HRTF : 1;
|
2018-09-08 19:54:22 +04:00
|
|
|
} ALC = {false, false};
|
2017-09-13 03:27:48 -07:00
|
|
|
struct {
|
2017-09-14 04:48:12 -07:00
|
|
|
bool SOFT_source_spatialize : 1;
|
2018-09-08 19:54:22 +04:00
|
|
|
} AL = {false};
|
2017-09-12 03:53:53 -07:00
|
|
|
|
2012-03-28 05:35:51 -07:00
|
|
|
typedef std::deque<ALuint> IDDq;
|
|
|
|
IDDq mFreeSources;
|
2012-03-19 13:19:22 -07:00
|
|
|
|
2017-09-11 21:33:18 -07:00
|
|
|
typedef std::vector<Sound*> SoundVec;
|
2012-12-17 21:50:01 -08:00
|
|
|
SoundVec mActiveSounds;
|
2017-09-11 21:33:18 -07:00
|
|
|
typedef std::vector<Stream*> StreamVec;
|
2015-11-23 07:51:52 -08:00
|
|
|
StreamVec mActiveStreams;
|
2012-12-17 21:50:01 -08:00
|
|
|
|
2015-11-30 08:00:02 -08:00
|
|
|
osg::Vec3f mListenerPos;
|
|
|
|
Environment mListenerEnv;
|
2012-03-31 10:06:12 -07:00
|
|
|
|
2017-09-12 03:53:53 -07:00
|
|
|
ALuint mWaterFilter;
|
|
|
|
ALuint mWaterEffect;
|
2017-09-12 20:20:23 -07:00
|
|
|
ALuint mDefaultEffect;
|
2017-09-12 03:53:53 -07:00
|
|
|
ALuint mEffectSlot;
|
|
|
|
|
2015-11-30 08:00:02 -08:00
|
|
|
struct StreamThread;
|
2017-04-28 17:30:26 +02:00
|
|
|
std::unique_ptr<StreamThread> mStreamThread;
|
2015-11-30 08:00:02 -08:00
|
|
|
|
2015-12-02 09:55:51 -08:00
|
|
|
void initCommon2D(ALuint source, const osg::Vec3f &pos, ALfloat gain, ALfloat pitch, bool loop, bool useenv);
|
|
|
|
void initCommon3D(ALuint source, const osg::Vec3f &pos, ALfloat mindist, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool loop, bool useenv);
|
|
|
|
|
|
|
|
void updateCommon(ALuint source, const osg::Vec3f &pos, ALfloat maxdist, ALfloat gain, ALfloat pitch, bool useenv, bool is3d);
|
|
|
|
|
2015-11-30 08:00:02 -08:00
|
|
|
OpenAL_Output& operator=(const OpenAL_Output &rhs);
|
|
|
|
OpenAL_Output(const OpenAL_Output &rhs);
|
|
|
|
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
std::vector<std::string> enumerate() override;
|
|
|
|
bool init(const std::string &devname, const std::string &hrtfname, HrtfMode hrtfmode) override;
|
|
|
|
void deinit() override;
|
2012-03-16 22:12:17 -07:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
std::vector<std::string> enumerateHrtf() override;
|
|
|
|
void setHrtf(const std::string &hrtfname, HrtfMode hrtfmode) override;
|
2015-12-04 12:54:41 -08:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
std::pair<Sound_Handle,size_t> loadSound(const std::string &fname) override;
|
|
|
|
size_t unloadSound(Sound_Handle data) override;
|
2015-11-23 01:01:20 -08:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool playSound(Sound *sound, Sound_Handle data, float offset) override;
|
|
|
|
bool playSound3D(Sound *sound, Sound_Handle data, float offset) override;
|
|
|
|
void finishSound(Sound *sound) override;
|
|
|
|
bool isSoundPlaying(Sound *sound) override;
|
|
|
|
void updateSound(Sound *sound) override;
|
2017-09-11 21:33:18 -07:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool streamSound(DecoderPtr decoder, Stream *sound, bool getLoudnessData=false) override;
|
|
|
|
bool streamSound3D(DecoderPtr decoder, Stream *sound, bool getLoudnessData) override;
|
|
|
|
void finishStream(Stream *sound) override;
|
|
|
|
double getStreamDelay(Stream *sound) override;
|
|
|
|
double getStreamOffset(Stream *sound) override;
|
|
|
|
float getStreamLoudness(Stream *sound) override;
|
|
|
|
bool isStreamPlaying(Stream *sound) override;
|
|
|
|
void updateStream(Stream *sound) override;
|
2012-03-17 02:55:08 -07:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void startUpdate() override;
|
|
|
|
void finishUpdate() override;
|
2015-11-24 20:37:38 -08:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env) override;
|
2012-03-17 04:22:54 -07:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void pauseSounds(int types) override;
|
|
|
|
void resumeSounds(int types) override;
|
2012-12-12 02:33:12 -08:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void pauseActiveDevice() override;
|
|
|
|
void resumeActiveDevice() override;
|
2020-03-31 13:15:26 +04:00
|
|
|
|
2012-03-16 22:12:17 -07:00
|
|
|
OpenAL_Output(SoundManager &mgr);
|
|
|
|
virtual ~OpenAL_Output();
|
|
|
|
};
|
|
|
|
#ifndef DEFAULT_OUTPUT
|
2012-12-18 10:22:40 -08:00
|
|
|
#define DEFAULT_OUTPUT(x) ::MWSound::OpenAL_Output((x))
|
2012-03-16 22:12:17 -07:00
|
|
|
#endif
|
2012-10-09 17:10:25 +02:00
|
|
|
}
|
2012-03-16 22:12:17 -07:00
|
|
|
|
|
|
|
#endif
|