forked from teamnwah/openmw-tes3coop
Add a skeleton output classs using OpenAL
This commit is contained in:
parent
42b445383f
commit
45b612ab3b
6 changed files with 199 additions and 87 deletions
|
@ -118,6 +118,12 @@ set(OENGINE_BULLET
|
|||
${LIBDIR}/openengine/bullet/BulletShapeLoader.h
|
||||
)
|
||||
|
||||
set(OENGINE_ALL ${OENGINE_OGRE} ${OENGINE_GUI} ${OENGINE_BULLET})
|
||||
source_group(libs\\openengine FILES ${OENGINE_ALL})
|
||||
|
||||
set(OPENMW_LIBS ${MANGLE_ALL} ${OENGINE_ALL})
|
||||
set(OPENMW_LIBS_HEADER)
|
||||
|
||||
# Sound setup
|
||||
if (USE_AUDIERE)
|
||||
find_package(Audiere REQUIRED)
|
||||
|
@ -141,12 +147,6 @@ if (USE_MPG123)
|
|||
set(SOUND_DEFINE -DOPENMW_USE_MPG123)
|
||||
endif (USE_MPG123)
|
||||
|
||||
set(OENGINE_ALL ${OENGINE_OGRE} ${OENGINE_GUI} ${OENGINE_BULLET})
|
||||
source_group(libs\\openengine FILES ${OENGINE_ALL})
|
||||
|
||||
set(OPENMW_LIBS ${MANGLE_ALL} ${OENGINE_ALL})
|
||||
set(OPENMW_LIBS_HEADER)
|
||||
|
||||
# Platform specific
|
||||
if (WIN32)
|
||||
set(PLATFORM_INCLUDE_DIR "platform")
|
||||
|
|
|
@ -38,7 +38,7 @@ add_openmw_dir (mwscript
|
|||
)
|
||||
|
||||
add_openmw_dir (mwsound
|
||||
soundmanager
|
||||
soundmanager openal_output
|
||||
)
|
||||
|
||||
add_openmw_dir (mwworld
|
||||
|
|
60
apps/openmw/mwsound/openal_output.cpp
Normal file
60
apps/openmw/mwsound/openal_output.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "openal_output.hpp"
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
|
||||
static void fail(const std::string &msg)
|
||||
{ throw std::runtime_error("OpenAL exception: " + msg); }
|
||||
|
||||
|
||||
bool OpenAL_Output::Initialize(const std::string &devname)
|
||||
{
|
||||
if(Context)
|
||||
fail("Device already initialized");
|
||||
|
||||
Device = alcOpenDevice(devname.c_str());
|
||||
if(!Device)
|
||||
{
|
||||
std::cout << "Failed to open \""<<devname<<"\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::cout << "Opened \""<<alcGetString(Device, ALC_DEVICE_SPECIFIER)<<"\"" << std::endl;
|
||||
|
||||
Context = alcCreateContext(Device, NULL);
|
||||
if(!Context || alcMakeContextCurrent(Context) == ALC_FALSE)
|
||||
{
|
||||
std::cout << "Failed to setup device context" << std::endl;
|
||||
if(Context)
|
||||
alcDestroyContext(Context);
|
||||
Context = 0;
|
||||
alcCloseDevice(Device);
|
||||
Device = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAL_Output::Deinitialize()
|
||||
{
|
||||
alcMakeContextCurrent(0);
|
||||
if(Context)
|
||||
alcDestroyContext(Context);
|
||||
Context = 0;
|
||||
if(Device)
|
||||
alcCloseDevice(Device);
|
||||
Device = 0;
|
||||
}
|
||||
|
||||
|
||||
OpenAL_Output::OpenAL_Output(SoundManager &mgr)
|
||||
: Sound_Output(mgr), Device(0), Context(0)
|
||||
{
|
||||
}
|
||||
|
||||
OpenAL_Output::~OpenAL_Output()
|
||||
{
|
||||
Deinitialize();
|
||||
}
|
||||
|
||||
}
|
29
apps/openmw/mwsound/openal_output.hpp
Normal file
29
apps/openmw/mwsound/openal_output.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef GAME_SOUND_OPENAL_OUTPUT_H
|
||||
#define GAME_SOUND_OPENAL_OUTPUT_H
|
||||
|
||||
#include "soundmanager.hpp"
|
||||
|
||||
#include "alc.h"
|
||||
#include "al.h"
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
class OpenAL_Output : public Sound_Output
|
||||
{
|
||||
ALCdevice *Device;
|
||||
ALCcontext *Context;
|
||||
|
||||
virtual bool Initialize(const std::string &devname="");
|
||||
virtual void Deinitialize();
|
||||
|
||||
OpenAL_Output(SoundManager &mgr);
|
||||
virtual ~OpenAL_Output();
|
||||
|
||||
friend class SoundManager;
|
||||
};
|
||||
#ifndef DEFAULT_OUTPUT
|
||||
#define DEFAULT_OUTPUT OpenAL_Output
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,32 +12,28 @@
|
|||
#include "../mwworld/world.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
|
||||
|
||||
#include "openal_output.hpp"
|
||||
#define SOUND_OUT "OpenAL"
|
||||
/* Set up the sound manager to use Audiere, FFMPEG or
|
||||
MPG123/libsndfile for input. The OPENMW_USE_x macros are set in
|
||||
CMakeLists.txt.
|
||||
*/
|
||||
#ifdef OPENMW_USE_AUDIERE
|
||||
#define SOUND_FACTORY OpenAL_Audiere_Factory
|
||||
#define SOUND_OUT "OpenAL"
|
||||
#define SOUND_IN "Audiere"
|
||||
#endif
|
||||
|
||||
#ifdef OPENMW_USE_FFMPEG
|
||||
#define SOUND_FACTORY OpenAL_FFMpeg_Factory
|
||||
#define SOUND_OUT "OpenAL"
|
||||
#define SOUND_IN "FFmpeg"
|
||||
#endif
|
||||
|
||||
#ifdef OPENMW_USE_MPG123
|
||||
#define SOUND_FACTORY OpenAL_SndFile_Mpg123_Factory
|
||||
#define SOUND_OUT "OpenAL"
|
||||
#define SOUND_IN "mpg123,sndfile"
|
||||
#endif
|
||||
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
|
||||
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera,
|
||||
const Files::PathContainer& dataDirs,
|
||||
bool useSound, bool fsstrict, MWWorld::Environment& environment)
|
||||
|
@ -48,6 +44,16 @@ namespace MWSound
|
|||
if(!useSound)
|
||||
return;
|
||||
|
||||
std::cout << "Sound output: " << SOUND_OUT << std::endl;
|
||||
std::cout << "Sound decoder: " << SOUND_IN << std::endl;
|
||||
|
||||
Output.reset(new DEFAULT_OUTPUT(*this));
|
||||
if(!Output->Initialize())
|
||||
{
|
||||
Output.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
// The music library will accept these filetypes
|
||||
// If none is given then it will accept all filetypes
|
||||
std::vector<std::string> acceptableExtensions;
|
||||
|
@ -66,13 +72,11 @@ namespace MWSound
|
|||
|
||||
std::string anything = "anything"; // anything is better that a segfault
|
||||
mCurrentPlaylist = mMusicLibrary.section(anything, mFSStrict); // now points to an empty path
|
||||
|
||||
std::cout << "Sound output: " << SOUND_OUT << std::endl;
|
||||
std::cout << "Sound decoder: " << SOUND_IN << std::endl;
|
||||
}
|
||||
|
||||
SoundManager::~SoundManager()
|
||||
{
|
||||
Output.reset();
|
||||
}
|
||||
|
||||
// Convert a soundId to file name, and modify the volume
|
||||
|
@ -258,7 +262,7 @@ namespace MWSound
|
|||
float min, max;
|
||||
const std::string &file = lookup(soundId, volume, min, max);
|
||||
if(file != "")
|
||||
add(file, ptr, soundId, volume, pitch, min, max, loop, untracked);
|
||||
std::cout << "Cannot play " << file << ", skipping.\n";
|
||||
}
|
||||
|
||||
void SoundManager::stopSound3D(MWWorld::Ptr ptr, const std::string& soundId)
|
||||
|
|
|
@ -21,9 +21,10 @@ namespace MWWorld
|
|||
|
||||
namespace MWSound
|
||||
{
|
||||
class Sound_Output;
|
||||
|
||||
class SoundManager
|
||||
{
|
||||
|
||||
// This is used for case insensitive and slash-type agnostic file
|
||||
// finding. It takes DOS paths (any case, \\ slashes or / slashes)
|
||||
// relative to the sound dir, and translates them into full paths
|
||||
|
@ -32,6 +33,8 @@ namespace MWSound
|
|||
|
||||
MWWorld::Environment& mEnvironment;
|
||||
|
||||
std::auto_ptr<Sound_Output> Output;
|
||||
|
||||
void streamMusicFull(const std::string& filename);
|
||||
///< Play a soundifle
|
||||
/// \param absolute filename
|
||||
|
@ -57,7 +60,6 @@ namespace MWSound
|
|||
void updatePositions(MWWorld::Ptr ptr);
|
||||
|
||||
public:
|
||||
|
||||
SoundManager(Ogre::Root*, Ogre::Camera*,
|
||||
const Files::PathContainer& dataDir, bool useSound, bool fsstrict,
|
||||
MWWorld::Environment& environment);
|
||||
|
@ -98,7 +100,8 @@ namespace MWSound
|
|||
///< Play a sound, independently of 3D-position
|
||||
|
||||
void playSound3D(MWWorld::Ptr reference, const std::string& soundId,
|
||||
float volume, float pitch, bool loop, bool untracked=false);
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked=false);
|
||||
///< Play a sound from an object
|
||||
|
||||
void stopSound3D(MWWorld::Ptr reference, const std::string& soundId="");
|
||||
|
@ -119,6 +122,22 @@ namespace MWSound
|
|||
|
||||
void update(float duration);
|
||||
};
|
||||
|
||||
class Sound_Output
|
||||
{
|
||||
SoundManager &mgr;
|
||||
|
||||
virtual bool Initialize(const std::string &devname="") = 0;
|
||||
virtual void Deinitialize() = 0;
|
||||
|
||||
Sound_Output(SoundManager &mgr) : mgr(mgr) { }
|
||||
|
||||
public:
|
||||
virtual ~Sound_Output() { }
|
||||
|
||||
friend class OpenAL_Output;
|
||||
friend class SoundManager;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue