2012-08-09 12:33:21 +00:00
|
|
|
#ifndef GAME_MWBASE_SOUNDMANAGER_H
|
|
|
|
#define GAME_MWBASE_SOUNDMANAGER_H
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
#include <memory>
|
2012-08-09 12:33:21 +00:00
|
|
|
#include <string>
|
2015-02-02 23:53:30 +00:00
|
|
|
#include <set>
|
2012-08-09 12:33:21 +00:00
|
|
|
|
|
|
|
#include "../mwworld/ptr.hpp"
|
2020-07-01 16:37:31 +00:00
|
|
|
#include "../mwsound/type.hpp"
|
2012-08-09 12:33:21 +00:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class CellStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWSound
|
|
|
|
{
|
2020-04-05 14:10:05 +00:00
|
|
|
// Each entry excepts of MaxCount should be used only in one place
|
|
|
|
enum BlockerType
|
|
|
|
{
|
|
|
|
VideoPlayback,
|
|
|
|
|
|
|
|
MaxCount
|
|
|
|
};
|
|
|
|
|
2012-08-09 12:33:21 +00:00
|
|
|
class Sound;
|
2015-11-30 15:32:42 +00:00
|
|
|
class Stream;
|
2015-03-06 08:36:42 +00:00
|
|
|
struct Sound_Decoder;
|
2017-05-05 17:26:09 +00:00
|
|
|
typedef std::shared_ptr<Sound_Decoder> DecoderPtr;
|
2017-09-15 08:03:41 +00:00
|
|
|
|
|
|
|
/* These must all fit together */
|
|
|
|
enum class PlayMode {
|
|
|
|
Normal = 0, /* non-looping, affected by environment */
|
|
|
|
Loop = 1<<0, /* Sound will continually loop until explicitly stopped */
|
|
|
|
NoEnv = 1<<1, /* Do not apply environment effects (eg, underwater filters) */
|
|
|
|
RemoveAtDistance = 1<<2, /* (3D only) If the listener gets further than 2000 units away
|
|
|
|
* from the sound source, the sound is removed.
|
|
|
|
* This is weird stuff but apparently how vanilla works for sounds
|
|
|
|
* played by the PlayLoopSound family of script functions. Perhaps
|
|
|
|
* we can make this cut off a more subtle fade later, but have to
|
|
|
|
* be careful to not change the overall volume of areas by too
|
|
|
|
* much. */
|
|
|
|
NoPlayerLocal = 1<<3, /* (3D only) Don't play the sound local to the listener even if the
|
|
|
|
* player is making it. */
|
|
|
|
LoopNoEnv = Loop | NoEnv,
|
|
|
|
LoopRemoveAtDistance = Loop | RemoveAtDistance
|
|
|
|
};
|
2020-07-01 16:37:31 +00:00
|
|
|
|
2017-09-15 08:03:41 +00:00
|
|
|
// Used for creating a type mask for SoundManager::pauseSounds and resumeSounds
|
|
|
|
inline int operator~(Type a) { return ~static_cast<int>(a); }
|
|
|
|
inline int operator&(Type a, Type b) { return static_cast<int>(a) & static_cast<int>(b); }
|
|
|
|
inline int operator&(int a, Type b) { return a & static_cast<int>(b); }
|
|
|
|
inline int operator|(Type a, Type b) { return static_cast<int>(a) | static_cast<int>(b); }
|
2012-08-09 12:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWBase
|
|
|
|
{
|
2017-09-12 04:33:18 +00:00
|
|
|
using Sound = MWSound::Sound;
|
|
|
|
using SoundStream = MWSound::Stream;
|
2012-08-09 12:33:21 +00:00
|
|
|
|
|
|
|
/// \brief Interface for sound manager (implemented in MWSound)
|
|
|
|
class SoundManager
|
|
|
|
{
|
|
|
|
SoundManager (const SoundManager&);
|
|
|
|
///< not implemented
|
|
|
|
|
|
|
|
SoundManager& operator= (const SoundManager&);
|
|
|
|
///< not implemented
|
|
|
|
|
2017-09-15 08:03:41 +00:00
|
|
|
protected:
|
|
|
|
using PlayMode = MWSound::PlayMode;
|
|
|
|
using Type = MWSound::Type;
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2017-09-15 08:03:41 +00:00
|
|
|
public:
|
2012-08-09 12:33:21 +00:00
|
|
|
SoundManager() {}
|
|
|
|
virtual ~SoundManager() {}
|
|
|
|
|
2015-02-02 23:53:30 +00:00
|
|
|
virtual void processChangedSettings(const std::set< std::pair<std::string, std::string> >& settings) = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
|
|
|
|
virtual void stopMusic() = 0;
|
|
|
|
///< Stops music if it's playing
|
|
|
|
|
|
|
|
virtual void streamMusic(const std::string& filename) = 0;
|
|
|
|
///< Play a soundifle
|
|
|
|
/// \param filename name of a sound file in "Music/" in the data directory.
|
|
|
|
|
|
|
|
virtual bool isMusicPlaying() = 0;
|
|
|
|
///< Returns true if music is playing
|
|
|
|
|
|
|
|
virtual void playPlaylist(const std::string &playlist) = 0;
|
|
|
|
///< Start playing music from the selected folder
|
|
|
|
/// \param name of the folder that contains the playlist
|
|
|
|
|
2019-03-03 22:31:51 +00:00
|
|
|
virtual void playTitleMusic() = 0;
|
|
|
|
///< Start playing title music
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual void say(const MWWorld::ConstPtr &reference, const std::string& filename) = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
///< Make an actor say some text.
|
|
|
|
/// \param filename name of a sound file in "Sound/" in the data directory.
|
|
|
|
|
|
|
|
virtual void say(const std::string& filename) = 0;
|
|
|
|
///< Say some text, without an actor ref
|
|
|
|
/// \param filename name of a sound file in "Sound/" in the data directory.
|
|
|
|
|
2019-09-06 05:19:41 +00:00
|
|
|
virtual bool sayActive(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
///< Is actor not speaking?
|
|
|
|
|
2019-09-06 05:19:41 +00:00
|
|
|
virtual bool sayDone(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) const = 0;
|
|
|
|
///< For scripting backward compatibility
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual void stopSay(const MWWorld::ConstPtr &reference=MWWorld::ConstPtr()) = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
///< Stop an actor speaking
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual float getSaySoundLoudness(const MWWorld::ConstPtr& reference) const = 0;
|
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.
|
|
|
|
|
2017-09-15 08:03:41 +00:00
|
|
|
virtual SoundStream *playTrack(const MWSound::DecoderPtr& decoder, Type type) = 0;
|
2017-09-12 08:02:08 +00:00
|
|
|
///< Play a 2D audio track, using a custom decoder. The caller is expected to call
|
|
|
|
/// stopTrack with the returned handle when done.
|
2012-12-13 08:05:57 +00:00
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
virtual void stopTrack(SoundStream *stream) = 0;
|
2015-11-30 13:42:51 +00:00
|
|
|
///< Stop the given audio track from playing
|
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
virtual double getTrackTimeDelay(SoundStream *stream) = 0;
|
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.
|
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
virtual Sound *playSound(const std::string& soundId, float volume, float pitch,
|
2017-09-15 08:03:41 +00:00
|
|
|
Type type=Type::Sfx, PlayMode mode=PlayMode::Normal,
|
2017-09-12 04:33:18 +00:00
|
|
|
float offset=0) = 0;
|
2012-08-09 12:33:21 +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.
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
virtual 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,
|
|
|
|
PlayMode mode=PlayMode::Normal, float offset=0) = 0;
|
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.
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
virtual Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
2017-09-15 08:03:41 +00:00
|
|
|
float volume, float pitch, Type type=Type::Sfx,
|
|
|
|
PlayMode mode=PlayMode::Normal, float offset=0) = 0;
|
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.
|
2014-05-16 11:09:23 +00:00
|
|
|
|
2017-09-12 04:33:18 +00:00
|
|
|
virtual void stopSound(Sound *sound) = 0;
|
2015-11-30 13:42:51 +00:00
|
|
|
///< Stop the given sound from playing
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
///< Stop the given object from playing the given sound,
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual void stopSound3D(const MWWorld::ConstPtr &reference) = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
///< Stop the given object from playing all sounds.
|
|
|
|
|
|
|
|
virtual void stopSound(const MWWorld::CellStore *cell) = 0;
|
|
|
|
///< Stop all sounds for the given cell.
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) = 0;
|
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.
|
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
///< Is the given sound currently playing on the given object?
|
2013-08-08 17:16:05 +00:00
|
|
|
/// If you want to check if sound played with playSound is playing, use empty Ptr
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2020-04-05 14:10:05 +00:00
|
|
|
virtual void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) = 0;
|
2012-12-12 10:33:12 +00:00
|
|
|
///< Pauses all currently playing sounds, including music.
|
|
|
|
|
2020-04-05 14:10:05 +00:00
|
|
|
virtual void resumeSounds(MWSound::BlockerType blocker) = 0;
|
2012-12-12 10:33:12 +00:00
|
|
|
///< Resumes all previously paused sounds.
|
|
|
|
|
2020-03-31 09:15:26 +00:00
|
|
|
virtual void pausePlayback() = 0;
|
|
|
|
virtual void resumePlayback() = 0;
|
|
|
|
|
2012-08-09 12:33:21 +00:00
|
|
|
virtual void update(float duration) = 0;
|
2012-08-09 14:12:10 +00:00
|
|
|
|
2015-12-03 14:16:20 +00:00
|
|
|
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) = 0;
|
2014-01-20 11:05:13 +00:00
|
|
|
|
2015-12-18 17:11:30 +00:00
|
|
|
virtual void updatePtr(const MWWorld::ConstPtr& old, const MWWorld::ConstPtr& updated) = 0;
|
2014-02-01 17:16:32 +00:00
|
|
|
|
2014-01-21 13:13:13 +00:00
|
|
|
virtual void clear() = 0;
|
2012-08-09 12:33:21 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|