From 51f0f648071d4864ad922dce92f38f3f328f303d Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 14 Mar 2005 05:34:08 +0000 Subject: [PATCH] post-Kernel --- include/audio/AudioCore.hpp | 36 ++++++++++++----------- src/audio/AudioCore.cpp | 57 +++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/include/audio/AudioCore.hpp b/include/audio/AudioCore.hpp index f7f4da2..950df85 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.2 2005/03/01 07:51:23 cozman Exp $ +// $Id: AudioCore.hpp,v 1.3 2005/03/14 05:34:08 cozman Exp $ #ifndef PHOTON_AUDIO_AUDIOCORE_HPP #define PHOTON_AUDIO_AUDIOCORE_HPP @@ -13,7 +13,7 @@ #include "al.h" #include "alc.h" -#include "util/Singleton.hpp" +#include "Task.hpp" #include "util/VersionInfo.hpp" namespace photon @@ -22,14 +22,24 @@ namespace audio { // Class: AudioCore -// Photon's core for audio manipulation/control. Defines the +// Photon's core for audio manipulation/control. Defines the // interface through which all audio related functions are performed. // // Parent: // -class AudioCore : public util::Singleton +class AudioCore : public Singleton { +// Group: (Con/De)structors +public: + // Function: AudioCore + // Initialize underlying APIs and setup internals. + AudioCore(); + + // Function: ~AudioCore + // Shutdown underlying APIs. + ~AudioCore(); + // Group: Accessors public: // Function: getAudioDeviceName @@ -38,21 +48,21 @@ public: // Returns: // Name of audio device currently in use. std::string getAudioDeviceName() const; - + // Group: Initialization public: // Function: setDesiredDevice - // Set the name of the desired audio device to use. Static function of + // Set the name of the desired audio device to use. Static function of // AudioCore, must be called before AudioCore::initialize() or not at all. // - // If called, the initialization of the audio library will attempt to + // If called, 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); - + // OpenAL specifics private: util::VersionInfo initOpenAL(); @@ -60,15 +70,7 @@ private: // data members private: - static std::string deviceName_; - -// Singleton-required code -private: - AudioCore(); - ~AudioCore(); - - friend class util::Singleton; - friend class std::auto_ptr; + static std::string deviceName_; }; diff --git a/src/audio/AudioCore.cpp b/src/audio/AudioCore.cpp index 107287f..f8f0ca8 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.2 2005/03/03 09:25:47 cozman Exp $ +// $Id: AudioCore.cpp,v 1.3 2005/03/14 05:34:25 cozman Exp $ #include "audio/AudioCore.hpp" @@ -16,7 +16,29 @@ namespace photon { namespace audio { - + +AudioCore::AudioCore() : + Task("AudioCore",PRI_CORE) +{ + util::VersionInfo oalReq(1,0,0); // requires OpenAL 1.0 (TODO: check?) + + util::ensureVersion("OpenAL", initOpenAL(), oalReq); +} + +AudioCore::~AudioCore() +{ + // retrieve both the context and device + ALCcontext* context( alcGetCurrentContext() ); + ALCdevice* device( alcGetContextsDevice(context) ); + + // set current context to null + alcMakeContextCurrent(0); + + // destroy context & device + alcDestroyContext(context); + alcCloseDevice(device); +} + std::string AudioCore::getAudioDeviceName() const { ALCdevice* device (alcGetContextsDevice( alcGetCurrentContext() )); @@ -35,12 +57,12 @@ util::VersionInfo AudioCore::initOpenAL() uint major,minor; // obtain default device if no deviceName is set, otherwise use deviceName - device = alcOpenDevice(deviceName_.empty() ? 0 : + 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()); } @@ -49,11 +71,11 @@ util::VersionInfo AudioCore::initOpenAL() if(context == 0) { - throw APIError("Failed to obtain an OpenAL context: " + + throw APIError("Failed to obtain an OpenAL context: " + checkOpenALError()); } - alcMakeContextCurrent(context); // context must be current to get version + alcMakeContextCurrent(context); // context must be current to get version // Version is in format "OpenAL 1.0" ss << alGetString(AL_VERSION); @@ -99,29 +121,8 @@ void AudioCore::setDesiredDevice(const std::string& name) // deviceName_ is used inside initOpenAL, must be set prior to construction deviceName_ = name; } - -std::string AudioCore::deviceName_; -AudioCore::AudioCore() -{ - util::VersionInfo oalReq(1,0,0); // requires OpenAL 1.0 (TODO: check?) - - util::ensureVersion("OpenAL", initOpenAL(), oalReq); -} - -AudioCore::~AudioCore() -{ - // retrieve both the context and device - ALCcontext* context( alcGetCurrentContext() ); - ALCdevice* device( alcGetContextsDevice(context) ); - - // set current context to null - alcMakeContextCurrent(0); - - // destroy context & device - alcDestroyContext(context); - alcCloseDevice(device); -} +std::string AudioCore::deviceName_; } }