fixed audio initialization
This commit is contained in:
parent
fef1dd3a85
commit
538f2c0b28
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// Version:
|
||||||
// $Id: AudioCore.hpp,v 1.8 2005/07/18 05:14:18 cozman Exp $
|
// $Id: AudioCore.hpp,v 1.9 2005/07/19 05:56:08 cozman Exp $
|
||||||
|
|
||||||
#ifdef PHOTON_USE_OPENAL
|
#ifdef PHOTON_USE_OPENAL
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ class AudioCore : public util::Singleton<AudioCore>
|
|||||||
public:
|
public:
|
||||||
// Function: AudioCore
|
// Function: AudioCore
|
||||||
// Initialize underlying APIs and setup <Task> internals.
|
// Initialize underlying APIs and setup <Task> internals.
|
||||||
AudioCore();
|
AudioCore(const std::string& deviceName);
|
||||||
|
|
||||||
// Function: ~AudioCore
|
// Function: ~AudioCore
|
||||||
// Shutdown underlying APIs.
|
// Shutdown underlying APIs.
|
||||||
@ -53,17 +53,17 @@ public:
|
|||||||
|
|
||||||
// Group: Initialization
|
// Group: Initialization
|
||||||
public:
|
public:
|
||||||
// Function: setDesiredDevice
|
// Function: initAudioDevice
|
||||||
// Set the name of the desired audio device to use. Static function of
|
// Initialize audio device. _MUST_ be called prior to any use of audio
|
||||||
// AudioCore, must be called before AudioCore::initialize() or not at all.
|
// functionality.
|
||||||
//
|
//
|
||||||
// If called, the initialization of the audio library will attempt to
|
// Takes an optional parameter, if existant the initialization of the audio
|
||||||
// use the specified audio device, otherwise the default device will be
|
// library will attempt to use the specified audio device, otherwise the
|
||||||
// used.
|
// default device will be used.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// name - Name of audio device to use.
|
// deviceName - Name of audio device to use. (optional, default=default)
|
||||||
static void setDesiredDevice(const std::string& name);
|
static void initAudioDevice(const std::string& deviceName="");
|
||||||
|
|
||||||
// Group: Error Checking
|
// Group: Error Checking
|
||||||
public:
|
public:
|
||||||
@ -91,11 +91,10 @@ public:
|
|||||||
|
|
||||||
// OpenAL specifics
|
// OpenAL specifics
|
||||||
private:
|
private:
|
||||||
util::VersionInfo initOpenAL();
|
util::VersionInfo initOpenAL(const std::string& deviceName);
|
||||||
|
|
||||||
// data members
|
// data members
|
||||||
private:
|
private:
|
||||||
static std::string deviceName_;
|
|
||||||
ALfloat listenerPos_[3];
|
ALfloat listenerPos_[3];
|
||||||
ALfloat listenerVel_[3];
|
ALfloat listenerVel_[3];
|
||||||
ALfloat listenerOri_[6];
|
ALfloat listenerOri_[6];
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// Version:
|
||||||
// $Id: AudioCore.cpp,v 1.8 2005/07/18 05:14:18 cozman Exp $
|
// $Id: AudioCore.cpp,v 1.9 2005/07/19 05:56:08 cozman Exp $
|
||||||
|
|
||||||
#ifdef PHOTON_USE_OPENAL
|
#ifdef PHOTON_USE_OPENAL
|
||||||
|
|
||||||
@ -19,12 +19,12 @@ namespace photon
|
|||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
|
|
||||||
AudioCore::AudioCore()
|
AudioCore::AudioCore(const std::string& deviceName)
|
||||||
{
|
{
|
||||||
//util::VersionInfo oalReq(0,0,7); // requires OpenAL 1.0 (TODO: check?)
|
//util::VersionInfo oalReq(0,0,7); // requires OpenAL 1.0 (TODO: check?)
|
||||||
//util::ensureVersion("OpenAL", initOpenAL(), oalReq);
|
//util::ensureVersion("OpenAL", initOpenAL(), oalReq);
|
||||||
|
|
||||||
initOpenAL(); // don't check version for now
|
initOpenAL(deviceName); // don't check version for now
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCore::~AudioCore()
|
AudioCore::~AudioCore()
|
||||||
@ -93,7 +93,7 @@ void AudioCore::throwOpenALError(const std::string& func)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
util::VersionInfo AudioCore::initOpenAL()
|
util::VersionInfo AudioCore::initOpenAL(const std::string& deviceName)
|
||||||
{
|
{
|
||||||
ALCdevice* device(0);
|
ALCdevice* device(0);
|
||||||
ALCcontext* context(0);
|
ALCcontext* context(0);
|
||||||
@ -103,12 +103,12 @@ util::VersionInfo AudioCore::initOpenAL()
|
|||||||
uint major,minor,patch; // version numbers
|
uint major,minor,patch; // version numbers
|
||||||
|
|
||||||
// obtain default device if no deviceName is set, otherwise use deviceName
|
// obtain default device if no deviceName is set, otherwise use deviceName
|
||||||
device = alcOpenDevice(deviceName_.empty() ? 0 :
|
device = alcOpenDevice(deviceName.empty() ? 0 :
|
||||||
reinterpret_cast<const ALubyte*>(deviceName_.c_str()) );
|
reinterpret_cast<const ALubyte*>(deviceName.c_str()) );
|
||||||
|
|
||||||
if(device == 0)
|
if(device == 0)
|
||||||
{
|
{
|
||||||
throw APIError("Failed to obtain OpenAL device " + deviceName_ + ": " +
|
throw APIError("Failed to obtain OpenAL device " + deviceName + ": " +
|
||||||
checkOpenALError());
|
checkOpenALError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,15 +143,11 @@ util::VersionInfo AudioCore::initOpenAL()
|
|||||||
return util::VersionInfo(major,minor,patch);
|
return util::VersionInfo(major,minor,patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioCore::setDesiredDevice(const std::string& name)
|
void AudioCore::initAudioDevice(const std::string& deviceName)
|
||||||
{
|
{
|
||||||
// deviceName_ is used inside initOpenAL, must be set prior to construction
|
new AudioCore(deviceName);
|
||||||
// or not set at all (in which case default device will be used)
|
|
||||||
deviceName_ = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static instance
|
|
||||||
std::string AudioCore::deviceName_;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user