XPMP2
X-Plane multiplayer library 2 - using instancing
SoundFMOD.h
Go to the documentation of this file.
1 
27 #pragma once
28 
29 // Only included if specified. Understand FMOD licensing and attribution first!
30 #if INCLUDE_FMOD_SOUND + 0 >= 1
31 
32 namespace XPMP2 {
33 
34 class SoundSystemFMOD;
35 
37 class SoundFMOD : public SoundFile {
38 protected:
39  FMOD_SOUND* pSound = nullptr;
40  bool bLoaded = false;
41 
42 public:
44  SoundFMOD (SoundSystemFMOD* _pSndSys,
45  const std::string& _filePath, bool _bLoop,
46  float _coneDir, float _conePitch,
47  float _coneInAngle, float _coneOutAngle, float _coneOutVol);
49  ~SoundFMOD() override;
50 
52  bool isReady () override;
53 
55  FMOD_SOUND* GetSnd() const { return pSound; }
57  SoundSystemFMOD* GetFmodSys() const;
58 };
59 
60 
62 class SoundSystemFMOD : public SoundSystem {
63 protected:
64  static SoundSystemFMOD* me;
65  FMOD_SYSTEM* pFmodSystem = nullptr;
66  unsigned int fmodVer = 0;
67  FMOD_CHANNELGROUP* pChnGrp = nullptr;
68  bool bLowPass = false;
69 public:
73  ~SoundSystemFMOD() override;
74 
77  bool LoadSoundFile (const std::string& _sndName,
78  const std::string& _filePath, bool _bLoop,
79  float _coneDir, float _conePitch,
80  float _coneInAngle, float _coneOutAngle, float _coneOutVol) override;
81 
83  bool UsePreV2Fmod() { return fmodVer < 0x00020000; }
85  FMOD_SYSTEM* GetSys() const { return pFmodSystem; }
87  unsigned int GetVer() const { return fmodVer; }
88 
91  void SoundLogEnable (bool bEnable = true);
92 
94  uint64_t Play (const std::string& sndName, float vol, const Aircraft& ac) override;
96  void Unpause (uint64_t sndId) override;
98  void Stop (uint64_t sndId) override;
100  void SetPosOrientation (uint64_t sndId, const Aircraft& ac, bool bDoOrientation) override;
102  void SetVolume (uint64_t sndId, float vol) override;
104  void SetMute (uint64_t sndId, bool bMute) override;
105 
107  void Update () override;
108 
110  void SetMasterVolume (float volMaster) override;
112  void SetAllMute (bool bMute) override;
113 
115  bool IsValid (uint64_t sndId) override;
116 
117 protected:
119  void SetLowPassGain (bool bOn);
120 
122  static FMOD_RESULT F_CALLBACK ChnCB(FMOD_CHANNELCONTROL *channelcontrol,
123  FMOD_CHANNELCONTROL_TYPE controltype,
124  FMOD_CHANNELCONTROL_CALLBACK_TYPE callbacktype,
125  void *commanddata1,
126  void *commanddata2);
127 
132  static FMOD_RESULT F_CALLBACK SoundLogCB(FMOD_DEBUG_FLAGS flags,
133  const char * file,
134  int line,
135  const char * func,
136  const char *message);
137 
142  template<class T_ADVSET>
143  void SoundSetFmodSettings(T_ADVSET& advSet);
144 
146  static uint64_t GetSndId (FMOD_CHANNEL* pFmodChn);
147 };
148 
149 }
150 
151 #endif // INCLUDE_FMOD_SOUND
Actual representation of all aircraft in XPMP2.
Definition: XPMPAircraft.h:178
Represents a sound file to be passed on to FMOD to be played.
Definition: SoundFMOD.h:37
bool bLoaded
cached version of the sound's openstate
Definition: SoundFMOD.h:40
FMOD_SOUND * GetSnd() const
Return the FMOD sound.
Definition: SoundFMOD.h:55
SoundSystemFMOD * GetFmodSys() const
Return the FMOD sound system (a type cast of pSndSys)
Definition: SoundFMOD.cpp:104
SoundFMOD(SoundSystemFMOD *_pSndSys, const std::string &_filePath, bool _bLoop, float _coneDir, float _conePitch, float _coneInAngle, float _coneOutAngle, float _coneOutVol)
Constructor creates the FMOD sound object and initiates loading of the file.
Definition: SoundFMOD.cpp:63
~SoundFMOD() override
Destructor removes the sound object.
Definition: SoundFMOD.cpp:78
FMOD_SOUND * pSound
FMOD sound object.
Definition: SoundFMOD.h:39
bool isReady() override
Finished loading, ready to play?
Definition: SoundFMOD.cpp:87
Represents a sound file.
Definition: Sound.h:101
Encapsulates direct access to the FMOD Sound System.
Definition: SoundFMOD.h:62
void SetLowPassGain(bool bOn)
Set low pass gain on all active sounds.
Definition: SoundFMOD.cpp:466
SoundSystemFMOD()
Construtor, throws exception if FMOD sound system cannot be initialized.
Definition: SoundFMOD.cpp:118
void Stop(uint64_t sndId) override
Stop the sound.
Definition: SoundFMOD.cpp:347
void SetAllMute(bool bMute) override
Mute all sounds (temporarily)
Definition: SoundFMOD.cpp:460
void SetMasterVolume(float volMaster) override
Set Master Volume on our channel group.
Definition: SoundFMOD.cpp:454
void Unpause(uint64_t sndId) override
Unpause a sound, which got started in a paused state to avoid crackling.
Definition: SoundFMOD.cpp:336
static uint64_t GetSndId(FMOD_CHANNEL *pFmodChn)
Read SoundChannel from FMOD Channel's user data.
Definition: SoundFMOD.cpp:504
uint64_t Play(const std::string &sndName, float vol, const Aircraft &ac) override
Play a new sound, returns an id for that sound.
Definition: SoundFMOD.cpp:280
bool bLowPass
Low Pass filter currently active?
Definition: SoundFMOD.h:68
static FMOD_RESULT F_CALLBACK SoundLogCB(FMOD_DEBUG_FLAGS flags, const char *file, int line, const char *func, const char *message)
Callback function called by FMOD for logging purposes.
Definition: SoundFMOD.cpp:195
unsigned int fmodVer
FMOD version.
Definition: SoundFMOD.h:66
unsigned int GetVer() const
Return the FMOD version.
Definition: SoundFMOD.h:87
void SetPosOrientation(uint64_t sndId, const Aircraft &ac, bool bDoOrientation) override
Update sound's position and orientation.
Definition: SoundFMOD.cpp:361
void SetMute(uint64_t sndId, bool bMute) override
Mute the sound (temporarily)
Definition: SoundFMOD.cpp:399
~SoundSystemFMOD() override
Destructor.
Definition: SoundFMOD.cpp:184
bool UsePreV2Fmod()
Use pre-v2 FMOD version structures?
Definition: SoundFMOD.h:83
FMOD_CHANNELGROUP * pChnGrp
Our channel group that we place everything under.
Definition: SoundFMOD.h:67
bool IsValid(uint64_t sndId) override
Is the sound id available?
Definition: SoundFMOD.cpp:483
static SoundSystemFMOD * me
static pointer to myself
Definition: SoundFMOD.h:64
void SetVolume(uint64_t sndId, float vol) override
Set sound's volume.
Definition: SoundFMOD.cpp:389
FMOD_SYSTEM * pFmodSystem
FMOD system.
Definition: SoundFMOD.h:65
void SoundSetFmodSettings(T_ADVSET &advSet)
Helper functon to set FMOD settings.
Definition: SoundFMOD.cpp:495
FMOD_SYSTEM * GetSys() const
Return the FMOD sound system.
Definition: SoundFMOD.h:85
void Update() override
Any updates to be done at the end of the frame.
Definition: SoundFMOD.cpp:409
bool LoadSoundFile(const std::string &_sndName, const std::string &_filePath, bool _bLoop, float _coneDir, float _conePitch, float _coneInAngle, float _coneOutAngle, float _coneOutVol) override
Loads a sound file so it becomes ready to play.
Definition: SoundFMOD.cpp:226
static FMOD_RESULT F_CALLBACK ChnCB(FMOD_CHANNELCONTROL *channelcontrol, FMOD_CHANNELCONTROL_TYPE controltype, FMOD_CHANNELCONTROL_CALLBACK_TYPE callbacktype, void *commanddata1, void *commanddata2)
Callback function for when sound ends, allows for internal bookkeeping.
Definition: SoundFMOD.cpp:258
void SoundLogEnable(bool bEnable=true)
Enables/disables FMOD logging.
Definition: SoundFMOD.cpp:210
Base class for sound systems, practically empty.
Definition: Sound.h:198
Definition: XPMPAircraft.h:70