2010-07-03 13:04:00 +00:00
|
|
|
|
|
|
|
#include "soundmanager.hpp"
|
|
|
|
|
2010-08-12 14:13:54 +00:00
|
|
|
#include <openengine/sound/sndmanager.hpp>
|
2010-08-12 15:58:29 +00:00
|
|
|
#include <mangle/sound/clients/ogre_listener_mover.hpp>
|
|
|
|
#include <mangle/sound/clients/ogre_output_updater.hpp>
|
2010-08-12 14:13:54 +00:00
|
|
|
|
2010-08-13 15:11:03 +00:00
|
|
|
/* Set up the sound manager to use Audiere of FFMPEG for input. The
|
|
|
|
OPENMW_USE_x macros are set in CMakeLists.txt.
|
2010-08-12 14:13:54 +00:00
|
|
|
*/
|
2010-08-13 15:11:03 +00:00
|
|
|
#ifdef OPENMW_USE_AUDIERE
|
2010-08-12 14:13:54 +00:00
|
|
|
#include <mangle/sound/filters/openal_audiere.hpp>
|
|
|
|
#define SOUND_FACTORY OpenAL_Audiere_Factory
|
2010-08-13 15:11:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENMW_USE_FFMPEG
|
|
|
|
#include <mangle/sound/filters/openal_ffmpeg.hpp>
|
|
|
|
#define SOUND_FACTORY OpenAL_FFMpeg_Factory
|
|
|
|
#endif
|
2010-08-12 14:13:54 +00:00
|
|
|
|
2010-08-13 20:30:22 +00:00
|
|
|
#ifdef OPENMW_USE_MPG123
|
|
|
|
#include <mangle/sound/filters/openal_mpg123.hpp>
|
|
|
|
#define SOUND_FACTORY OpenAL_Mpg123_Factory
|
|
|
|
#endif
|
|
|
|
|
2010-08-12 14:13:54 +00:00
|
|
|
using namespace Mangle::Sound;
|
2010-08-12 15:58:29 +00:00
|
|
|
typedef OEngine::Sound::SoundManager OEManager;
|
|
|
|
typedef OEngine::Sound::SoundManagerPtr OEManagerPtr;
|
2010-08-12 14:13:54 +00:00
|
|
|
|
|
|
|
/* Set the position on a sound based on a Ptr. TODO: We do not support
|
|
|
|
tracking moving objects yet, once a sound is started it stays in
|
|
|
|
the same place until it finishes.
|
|
|
|
|
|
|
|
This obviously has to be fixed at some point for player/npc
|
|
|
|
footstep sounds and the like. However, updating all sounds each
|
|
|
|
frame is expensive, so there should be a special flag for sounds
|
|
|
|
that need to track their attached object.
|
|
|
|
*/
|
2010-08-12 15:58:29 +00:00
|
|
|
static void setPos(SoundPtr snd, const MWWorld::Ptr ref)
|
2010-08-12 14:13:54 +00:00
|
|
|
{
|
|
|
|
// Get sound position from the reference
|
2010-08-12 15:58:29 +00:00
|
|
|
const float *pos = ref.getCellRef().pos.pos;
|
2010-08-12 14:13:54 +00:00
|
|
|
|
|
|
|
// Move the sound. Might need to convert coordinates, test.
|
|
|
|
snd->setPos(pos[0], pos[1], pos[2]);
|
|
|
|
}
|
|
|
|
|
2010-07-03 13:04:00 +00:00
|
|
|
namespace MWSound
|
|
|
|
{
|
2010-08-12 14:13:54 +00:00
|
|
|
struct SoundManager::SoundImpl
|
|
|
|
{
|
2010-08-12 15:58:29 +00:00
|
|
|
/* This is the sound manager. It loades, stores and deletes
|
|
|
|
sounds based on the sound factory it is given.
|
|
|
|
*/
|
|
|
|
OEManagerPtr mgr;
|
|
|
|
|
|
|
|
/* This class calls update() on the sound manager each frame
|
|
|
|
using and Ogre::FrameListener
|
|
|
|
*/
|
|
|
|
Mangle::Sound::OgreOutputUpdater updater;
|
|
|
|
|
|
|
|
/* This class tracks the movement of an Ogre::Camera and moves
|
|
|
|
a sound listener automatically to follow it.
|
|
|
|
*/
|
|
|
|
Mangle::Sound::OgreListenerMover cameraTracker;
|
2010-08-12 14:13:54 +00:00
|
|
|
|
|
|
|
SoundImpl()
|
2010-08-12 15:58:29 +00:00
|
|
|
: mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY)))
|
|
|
|
, updater(mgr)
|
|
|
|
, cameraTracker(mgr)
|
2010-08-12 14:13:54 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera)
|
|
|
|
{
|
|
|
|
mData = new SoundImpl;
|
|
|
|
|
2010-08-12 15:58:29 +00:00
|
|
|
// Attach the camera to the camera tracker
|
|
|
|
mData->cameraTracker.followCamera(camera);
|
2010-08-12 14:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundManager::~SoundManager()
|
|
|
|
{
|
|
|
|
delete mData;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:58:29 +00:00
|
|
|
void SoundManager::say (MWWorld::Ptr reference, const std::string& filename)
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
2010-08-12 15:58:29 +00:00
|
|
|
// Play the sound at the correct position
|
|
|
|
SoundPtr snd = mData->mgr->play(filename);
|
|
|
|
setPos(snd, reference);
|
|
|
|
// TODO: We need to attach it to the reference somehow. A weak
|
|
|
|
// pointer is probably the best bet
|
2010-07-03 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 14:29:22 +00:00
|
|
|
bool SoundManager::sayDone (MWWorld::Ptr reference) const
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
2010-08-12 15:58:29 +00:00
|
|
|
return true;
|
|
|
|
// TODO: Ask the reference to check its attached 'say' sound.
|
2010-07-03 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 14:29:22 +00:00
|
|
|
void SoundManager::streamMusic (const std::string& filename)
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
2010-08-12 15:58:29 +00:00
|
|
|
// Play the sound and tell it to stream, if possible.
|
|
|
|
mData->mgr->play(filename)->setStreaming(true);
|
2010-07-03 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 14:29:22 +00:00
|
|
|
void SoundManager::playSound (const std::string& soundId, float volume, float pitch)
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-03 15:59:30 +00:00
|
|
|
void SoundManager::playSound3D (MWWorld::Ptr reference, const std::string& soundId,
|
2010-08-12 14:29:22 +00:00
|
|
|
float volume, float pitch, bool loop)
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
2010-08-12 15:58:29 +00:00
|
|
|
// Not implemented - need both a way to find sounds by id and
|
|
|
|
// a way to attach them to the reference
|
2010-07-03 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 14:29:22 +00:00
|
|
|
void SoundManager::stopSound3D (MWWorld::Ptr reference, const std::string& soundId)
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-12 14:29:22 +00:00
|
|
|
bool SoundManager::getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId) const
|
2010-07-03 13:04:00 +00:00
|
|
|
{
|
2010-08-12 15:58:29 +00:00
|
|
|
return false;
|
2010-07-03 13:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|