diff --git a/include/audio/AudioCore.hpp b/include/audio/AudioCore.hpp index 89085a1..687466e 100644 --- a/include/audio/AudioCore.hpp +++ b/include/audio/AudioCore.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // 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 @@ -36,7 +36,7 @@ class AudioCore : public util::Singleton public: // Function: AudioCore // Initialize underlying APIs and setup internals. - AudioCore(); + AudioCore(const std::string& deviceName); // Function: ~AudioCore // Shutdown underlying APIs. @@ -53,17 +53,17 @@ public: // Group: Initialization public: - // Function: setDesiredDevice - // Set the name of the desired audio device to use. Static function of - // AudioCore, must be called before AudioCore::initialize() or not at all. + // Function: initAudioDevice + // Initialize audio device. _MUST_ be called prior to any use of audio + // functionality. // - // If called, the initialization of the audio library will attempt to - // use the specified audio device, otherwise the default device will be - // used. + // Takes an optional parameter, if existant the initialization of the audio + // library will attempt to use the specified audio device, otherwise the + // default device will be used. // // Parameters: - // name - Name of audio device to use. - static void setDesiredDevice(const std::string& name); + // deviceName - Name of audio device to use. (optional, default=default) + static void initAudioDevice(const std::string& deviceName=""); // Group: Error Checking public: @@ -91,11 +91,10 @@ public: // OpenAL specifics private: - util::VersionInfo initOpenAL(); + util::VersionInfo initOpenAL(const std::string& deviceName); // data members private: - static std::string deviceName_; ALfloat listenerPos_[3]; ALfloat listenerVel_[3]; ALfloat listenerOri_[6]; diff --git a/src/audio/AudioCore.cpp b/src/audio/AudioCore.cpp index cfcdb83..aade8b0 100644 --- a/src/audio/AudioCore.cpp +++ b/src/audio/AudioCore.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // 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 @@ -19,12 +19,12 @@ namespace photon namespace audio { -AudioCore::AudioCore() +AudioCore::AudioCore(const std::string& deviceName) { //util::VersionInfo oalReq(0,0,7); // requires OpenAL 1.0 (TODO: check?) //util::ensureVersion("OpenAL", initOpenAL(), oalReq); - initOpenAL(); // don't check version for now + initOpenAL(deviceName); // don't check version for now } 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); ALCcontext* context(0); @@ -103,12 +103,12 @@ util::VersionInfo AudioCore::initOpenAL() uint major,minor,patch; // version numbers // obtain default device if no deviceName is set, otherwise use deviceName - device = alcOpenDevice(deviceName_.empty() ? 0 : - reinterpret_cast(deviceName_.c_str()) ); + device = alcOpenDevice(deviceName.empty() ? 0 : + reinterpret_cast(deviceName.c_str()) ); if(device == 0) { - throw APIError("Failed to obtain OpenAL device " + deviceName_ + ": " + + throw APIError("Failed to obtain OpenAL device " + deviceName + ": " + checkOpenALError()); } @@ -143,15 +143,11 @@ util::VersionInfo AudioCore::initOpenAL() 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 - // or not set at all (in which case default device will be used) - deviceName_ = name; + new AudioCore(deviceName); } -// static instance -std::string AudioCore::deviceName_; } }