2010-07-03 13:04:00 +00:00
|
|
|
#ifndef GAME_SOUND_SOUNDMANAGER_H
|
|
|
|
#define GAME_SOUND_SOUNDMANAGER_H
|
|
|
|
|
2015-11-30 16:42:25 +00:00
|
|
|
#include <memory>
|
2010-07-03 13:04:00 +00:00
|
|
|
#include <string>
|
2012-03-27 09:50:45 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <map>
|
2017-08-25 20:08:49 +00:00
|
|
|
#include <unordered_map>
|
2010-07-03 13:04:00 +00:00
|
|
|
|
2012-05-24 02:34:53 +00:00
|
|
|
#include <components/settings/settings.hpp>
|
2020-06-28 15:17:43 +00:00
|
|
|
#include <components/misc/objectpool.hpp>
|
2016-11-27 20:19:52 +00:00
|
|
|
#include <components/fallback/fallback.hpp>
|
|
|
|
|
2012-08-09 12:33:21 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2011-10-09 07:28:36 +00:00
|
|
|
|
2020-06-28 11:12:42 +00:00
|
|
|
#include "regionsoundselector.hpp"
|
2020-06-28 12:41:05 +00:00
|
|
|
#include "watersoundupdater.hpp"
|
2020-07-01 16:37:31 +00:00
|
|
|
#include "type.hpp"
|
|
|
|
#include "volumesettings.hpp"
|
2020-07-18 21:56:14 +00:00
|
|
|
#include "sound_buffer.hpp"
|
2020-06-28 11:12:42 +00:00
|
|
|
|
2015-04-13 20:48:37 +00:00
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
class Manager;
|
|
|
|
}
|
|
|
|
|
2015-11-24 09:40:14 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
struct Sound;
|
2020-06-28 12:52:50 +00:00
|
|
|
struct Cell;
|
2015-11-24 09:40:14 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 13:04:00 +00:00
|
|
|
namespace MWSound
|
|
|
|
{
|
2012-03-17 05:12:17 +00:00
|
|
|
class Sound_Output;
|
2012-03-26 22:36:53 +00:00
|
|
|
struct Sound_Decoder;
|
2012-03-17 09:45:18 +00:00
|
|
|
class Sound;
|
2017-09-12 04:33:18 +00:00
|
|
|
class Stream;
|
2012-03-31 17:06:12 +00:00
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
using SoundPtr = Misc::ObjectPtr<Sound>;
|
|
|
|
using StreamPtr = Misc::ObjectPtr<Stream>;
|
|
|
|
|
2012-08-09 12:33:21 +00:00
|
|
|
class SoundManager : public MWBase::SoundManager
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
2015-04-13 20:48:37 +00:00
|
|
|
const VFS::Manager* mVFS;
|
2012-03-17 05:12:17 +00:00
|
|
|
|
2017-04-28 15:30:26 +00:00
|
|
|
std::unique_ptr<Sound_Output> mOutput;
|
2012-03-17 05:12:17 +00:00
|
|
|
|
2014-06-11 16:10:58 +00:00
|
|
|
// Caches available music tracks by <playlist name, (sound files) >
|
2017-09-13 02:03:17 +00:00
|
|
|
std::unordered_map<std::string, std::vector<std::string>> mMusicFiles;
|
2017-08-25 20:08:49 +00:00
|
|
|
std::unordered_map<std::string, std::vector<int>> mMusicToPlay; // A list with music files not yet played
|
2014-06-11 16:10:58 +00:00
|
|
|
std::string mLastPlayedMusic; // The music file that was last played
|
|
|
|
|
2020-07-01 16:37:31 +00:00
|
|
|
VolumeSettings mVolumeSettings;
|
2012-04-07 23:00:30 +00:00
|
|
|
|
2020-06-28 12:41:05 +00:00
|
|
|
WaterSoundUpdater mWaterSoundUpdater;
|
|
|
|
|
2020-07-18 21:56:14 +00:00
|
|
|
SoundBufferPool mSoundBuffers;
|
2015-11-23 14:35:01 +00:00
|
|
|
|
2020-06-28 15:17:43 +00:00
|
|
|
Misc::ObjectPool<Sound> mSounds;
|
2017-09-12 04:33:18 +00:00
|
|
|
|
2020-06-28 15:17:43 +00:00
|
|
|
Misc::ObjectPool<Stream> mStreams;
|
2017-09-12 04:33:18 +00:00
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
typedef std::pair<SoundPtr, Sound_Buffer*> SoundBufferRefPair;
|
2015-11-26 09:26:33 +00:00
|
|
|
typedef std::vector<SoundBufferRefPair> SoundBufferRefPairList;
|
2015-12-18 17:11:30 +00:00
|
|
|
typedef std::map<MWWorld::ConstPtr,SoundBufferRefPairList> SoundMap;
|
2012-03-18 18:17:45 +00:00
|
|
|
SoundMap mActiveSounds;
|
2012-03-17 15:02:46 +00:00
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
typedef std::map<MWWorld::ConstPtr, StreamPtr> SaySoundMap;
|
2019-05-26 11:55:29 +00:00
|
|
|
SaySoundMap mSaySoundsQueue;
|
2015-11-23 12:00:10 +00:00
|
|
|
SaySoundMap mActiveSaySounds;
|
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
typedef std::vector<StreamPtr> TrackList;
|
2015-12-01 19:28:37 +00:00
|
|
|
TrackList mActiveTracks;
|
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
StreamPtr mMusic;
|
2015-12-01 19:28:37 +00:00
|
|
|
std::string mCurrentPlaylist;
|
2013-08-27 20:48:20 +00:00
|
|
|
|
2014-06-25 16:10:26 +00:00
|
|
|
bool mListenerUnderwater;
|
2015-05-12 17:02:56 +00:00
|
|
|
osg::Vec3f mListenerPos;
|
|
|
|
osg::Vec3f mListenerDir;
|
|
|
|
osg::Vec3f mListenerUp;
|
2012-08-09 13:01:03 +00:00
|
|
|
|
2020-04-05 14:10:05 +00:00
|
|
|
int mPausedSoundTypes[BlockerType::MaxCount] = {};
|
2012-12-18 12:35:24 +00:00
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
Sound *mUnderwaterSound;
|
|
|
|
Sound *mNearWaterSound;
|
2015-12-01 19:28:37 +00:00
|
|
|
|
2020-03-31 09:15:26 +00:00
|
|
|
std::string mNextMusic;
|
|
|
|
bool mPlaybackPaused;
|
|
|
|
|
2020-06-28 11:12:42 +00:00
|
|
|
RegionSoundSelector mRegionSoundSelector;
|
|
|
|
|
2020-10-28 14:02:31 +00:00
|
|
|
float mTimePassed;
|
2020-06-28 11:49:05 +00:00
|
|
|
|
2020-10-28 14:02:31 +00:00
|
|
|
const ESM::Cell *mLastCell;
|
2020-06-28 12:52:50 +00:00
|
|
|
|
2020-10-25 11:20:14 +00:00
|
|
|
Sound* mCurrentRegionSound;
|
|
|
|
|
2015-11-26 09:26:33 +00:00
|
|
|
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
|
2015-11-24 09:40:14 +00:00
|
|
|
|
2015-11-26 09:26:33 +00:00
|
|
|
Sound_Buffer *lookupSound(const std::string &soundId) const;
|
|
|
|
Sound_Buffer *loadSound(const std::string &soundId);
|
2015-11-24 11:18:23 +00:00
|
|
|
|
2018-10-18 10:59:39 +00:00
|
|
|
// returns a decoder to start streaming, or nullptr if the sound was not found
|
2016-06-27 18:54:42 +00:00
|
|
|
DecoderPtr loadVoice(const std::string &voicefile);
|
2015-11-22 12:53:24 +00:00
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
SoundPtr getSoundRef();
|
|
|
|
StreamPtr getStreamRef();
|
2017-09-12 04:33:18 +00:00
|
|
|
|
2020-06-28 16:25:23 +00:00
|
|
|
StreamPtr playVoice(DecoderPtr decoder, const osg::Vec3f &pos, bool playlocal);
|
2015-11-27 17:47:14 +00:00
|
|
|
|
2012-03-20 19:39:49 +00:00
|
|
|
void streamMusicFull(const std::string& filename);
|
2017-08-06 18:10:56 +00:00
|
|
|
void advanceMusic(const std::string& filename);
|
2017-09-18 04:44:16 +00:00
|
|
|
void startRandomTitle();
|
2017-08-06 18:10:56 +00:00
|
|
|
|
2012-03-22 02:21:36 +00:00
|
|
|
void updateSounds(float duration);
|
2012-03-17 13:18:59 +00:00
|
|
|
void updateRegionSound(float duration);
|
2020-06-28 11:50:02 +00:00
|
|
|
void updateWaterSound();
|
2017-08-06 18:10:56 +00:00
|
|
|
void updateMusic(float duration);
|
|
|
|
|
2017-09-15 08:03:41 +00:00
|
|
|
float volumeFromType(Type type) const;
|
2012-12-18 10:01:04 +00:00
|
|
|
|
2020-06-28 13:38:30 +00:00
|
|
|
enum class WaterSoundAction
|
|
|
|
{
|
|
|
|
DoNothing,
|
|
|
|
SetVolume,
|
|
|
|
FinishSound,
|
|
|
|
PlaySound,
|
|
|
|
};
|
|
|
|
|
|
|
|
std::pair<WaterSoundAction, Sound_Buffer*> getWaterSoundAction(const WaterSoundUpdate& update,
|
|
|
|
const ESM::Cell* cell) const;
|
|
|
|
|
2012-03-24 10:49:03 +00:00
|
|
|
SoundManager(const SoundManager &rhs);
|
|
|
|
SoundManager& operator=(const SoundManager &rhs);
|
|
|
|
|
2012-03-18 06:30:43 +00:00
|
|
|
protected:
|
|
|
|
DecoderPtr getDecoder();
|
|
|
|
friend class OpenAL_Output;
|
|
|
|
|
2018-05-07 16:40:53 +00:00
|
|
|
void stopSound(Sound_Buffer *sfx, const MWWorld::ConstPtr &ptr);
|
|
|
|
///< Stop the given object from playing given sound buffer.
|
|
|
|
|
2012-03-17 05:12:17 +00:00
|
|
|
public:
|
2019-01-22 06:08:48 +00:00
|
|
|
SoundManager(const VFS::Manager* vfs, bool useSound);
|
2012-08-09 12:33:21 +00:00
|
|
|
virtual ~SoundManager();
|
2012-03-07 00:20:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void processChangedSettings(const Settings::CategorySettingVector& settings) override;
|
2012-05-24 02:34:53 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopMusic() override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Stops music if it's playing
|
2012-03-07 15:46:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void streamMusic(const std::string& filename) override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Play a soundifle
|
|
|
|
/// \param filename name of a sound file in "Music/" in the data directory.
|
2012-03-07 00:20:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool isMusicPlaying() override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Returns true if music is playing
|
2011-06-12 00:01:21 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void playPlaylist(const std::string &playlist) override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Start playing music from the selected folder
|
|
|
|
/// \param name of the folder that contains the playlist
|
2012-03-09 01:56:29 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void playTitleMusic() override;
|
2019-03-03 22:31:51 +00:00
|
|
|
///< Start playing title music
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void say(const MWWorld::ConstPtr &reference, const std::string& filename) override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Make an actor say some text.
|
2012-05-02 03:30:31 +00:00
|
|
|
/// \param filename name of a sound file in "Sound/" in the data directory.
|
2011-06-15 20:33:31 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void say(const std::string& filename) override;
|
2012-05-02 03:30:31 +00:00
|
|
|
///< Say some text, without an actor ref
|
|
|
|
/// \param filename name of a sound file in "Sound/" in the data directory.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool sayActive(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Is actor not speaking?
|
2011-06-15 20:33:31 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const override;
|
2019-09-06 05:19:41 +00:00
|
|
|
///< For scripting backward compatibility
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) override;
|
2012-05-02 03:30:31 +00:00
|
|
|
///< Stop an actor speaking
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
float getSaySoundLoudness(const MWWorld::ConstPtr& reference) const override;
|
2014-07-28 22:26:26 +00:00
|
|
|
///< Check the currently playing say sound for this actor
|
|
|
|
/// and get an average loudness value (scale [0,1]) at the current time position.
|
|
|
|
/// If the actor is not saying anything, returns 0.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
Stream *playTrack(const DecoderPtr& decoder, Type type) override;
|
2012-12-13 08:05:57 +00:00
|
|
|
///< Play a 2D audio track, using a custom decoder
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopTrack(Stream *stream) override;
|
2015-11-30 13:42:51 +00:00
|
|
|
///< Stop the given audio track from playing
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
double getTrackTimeDelay(Stream *stream) override;
|
2015-11-30 13:42:51 +00:00
|
|
|
///< Retives the time delay, in seconds, of the audio track (must be a sound
|
|
|
|
/// returned by \ref playTrack). Only intended to be called by the track
|
|
|
|
/// decoder's read method.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
Sound *playSound(const std::string& soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Play a sound, independently of 3D-position
|
2015-11-27 07:40:02 +00:00
|
|
|
///< @param offset Number of seconds into the sound to start playback.
|
2010-10-31 16:23:03 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
Sound *playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId,
|
2017-09-15 08:03:41 +00:00
|
|
|
float volume, float pitch, Type type=Type::Sfx,
|
2020-10-16 18:18:54 +00:00
|
|
|
PlayMode mode=PlayMode::Normal, float offset=0) override;
|
2014-05-16 11:09:23 +00:00
|
|
|
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
2015-11-27 07:40:02 +00:00
|
|
|
///< @param offset Number of seconds into the sound to start playback.
|
2014-05-16 11:09:23 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
|
|
|
float volume, float pitch, Type type, PlayMode mode, float offset=0) override;
|
2015-11-25 07:24:42 +00:00
|
|
|
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition.
|
2015-11-27 07:40:02 +00:00
|
|
|
///< @param offset Number of seconds into the sound to start playback.
|
2012-03-07 15:46:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopSound(Sound *sound) override;
|
2015-11-30 13:42:51 +00:00
|
|
|
///< Stop the given sound from playing
|
2015-12-05 00:54:16 +00:00
|
|
|
/// @note no-op if \a sound is null
|
2015-11-30 13:42:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) override;
|
2012-03-27 10:20:50 +00:00
|
|
|
///< Stop the given object from playing the given sound,
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopSound3D(const MWWorld::ConstPtr &reference) override;
|
2012-03-27 10:20:50 +00:00
|
|
|
///< Stop the given object from playing all sounds.
|
2012-03-07 15:46:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void stopSound(const MWWorld::CellStore *cell) override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Stop all sounds for the given cell.
|
2010-08-14 05:54:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) override;
|
2013-07-26 16:43:06 +00:00
|
|
|
///< Fade out given sound (that is already playing) of given object
|
|
|
|
///< @param reference Reference to object, whose sound is faded out
|
|
|
|
///< @param soundId ID of the sound to fade out.
|
|
|
|
///< @param duration Time until volume reaches 0.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const override;
|
2012-03-17 05:12:17 +00:00
|
|
|
///< Is the given sound currently playing on the given object?
|
2010-08-14 05:54:51 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) override;
|
2012-12-12 10:33:12 +00:00
|
|
|
///< Pauses all currently playing sounds, including music.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void resumeSounds(MWSound::BlockerType blocker) override;
|
2012-12-12 10:33:12 +00:00
|
|
|
///< Resumes all previously paused sounds.
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void pausePlayback() override;
|
|
|
|
void resumePlayback() override;
|
2020-03-31 09:15:26 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void update(float duration) override;
|
2012-08-09 13:01:03 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) override;
|
2014-01-20 11:05:13 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void updatePtr (const MWWorld::ConstPtr& old, const MWWorld::ConstPtr& updated) override;
|
2014-02-01 17:16:32 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void clear() override;
|
2012-03-17 05:12:17 +00:00
|
|
|
};
|
2010-07-03 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|