diff --git a/include/audio/AudioCore.hpp b/include/audio/AudioCore.hpp index 97f75d3..db00e84 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.14 2005/10/15 04:57:19 cozman Exp $ +// $Id: AudioCore.hpp,v 1.15 2005/10/28 22:13:33 cozman Exp $ #ifdef PHOTON_USE_OPENAL @@ -37,25 +37,34 @@ class AudioCore public: // Function: AudioCore // Initialize underlying APIs and setup internals. - //AudioCore(); - AudioCore(const std::string& deviceName); + AudioCore(const std::string& deviceName) {}; // Function: ~AudioCore // Shutdown underlying APIs. - ~AudioCore(); + virtual ~AudioCore() { }; // Group: Accessors public: // Function: getAudioDeviceName - // Get name of active audio device. // - // Returns: - // Name of audio device currently in use. - std::string getAudioDeviceName() const; - -// Group: Error Checking + // Returns name of audio device currently in use, if available from + // underlying audio API.. + virtual std::string getAudioDeviceName() const=0; +}; + +class OALAudioCore : public AudioCore +{ + public: - // Function: checkOpenALError + OALAudioCore(const std::string& deviceName); + ~OALAudioCore(); + +public: + std::string getAudioDeviceName() const; + + +public: + // No-Doc Function: checkOpenALError // Checks for OpenAL internal errors, returning a descriptive string if // the OpenAL error state is currently set. Will return an empty string // if there is no error set. @@ -64,7 +73,7 @@ public: // String describing OpenAL error, empty string if no error exists. static std::string checkOpenALError(); - // Function: throwOpenALError + // No-Doc Function: throwOpenALError // Checks for OpenAL internal errors, throwing an if the OpenAL // error state is set and doing nothing if not. Optionally makes the // thrown exception more descriptive by adding in a function string @@ -81,14 +90,13 @@ public: private: util::VersionInfo initOpenAL(const std::string& deviceName); -// data members +// data members specific to implementation private: ALfloat listenerPos_[3]; ALfloat listenerVel_[3]; ALfloat listenerOri_[6]; }; - } } diff --git a/include/audio/Source.hpp b/include/audio/Source.hpp index 9d0e41c..5407e43 100644 --- a/include/audio/Source.hpp +++ b/include/audio/Source.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Source.hpp,v 1.4 2005/08/08 21:39:41 cozman Exp $ +// $Id: Source.hpp,v 1.5 2005/10/28 22:13:33 cozman Exp $ #ifdef PHOTON_USE_OPENAL @@ -23,17 +23,20 @@ namespace audio { // Class: Source -// Simple OO wrapper around an OpenAL source, defines the interface used for -// Sample and Music. +// Simple wrapper object around an OpenAL source, defines the interface used +// for Sample and Music. // // Source is a template class and can not be used directly, use either Sample // or Music. Sample is for playing small files such as sound effects. Music // is for streaming files such as background music. +// +// Source is a resource managed class, and therefore all resources should +// be registered using and then loaded by their assigned +// name via or the appropriate constructor. // // Operators: // - Source = Source // - bool : True if source has loaded buffer, false if not. -// - ostream& << Source template class Source : public ResourceManaged { @@ -69,7 +72,7 @@ public: public: // Function: open - // Opens an audio file, supported formats are WAV and Ogg. + // Opens an audio file, supported formats are WAV and Ogg Vorbis. // // Parameters: // name - Name of the Source to open. @@ -168,7 +171,7 @@ template Source::Source() { alGenSources(1, &sourceID_); - AudioCore::throwOpenALError("Source::Source()"); + OALAudioCore::throwOpenALError("Source::Source()"); } template @@ -176,14 +179,14 @@ Source::Source(const Source &rhs) : ResourceManaged(rhs) { alGenSources(1, &sourceID_); - AudioCore::throwOpenALError("Source::Source(const Source&)"); + OALAudioCore::throwOpenALError("Source::Source(const Source&)"); } template Source::Source(const std::string& name) { alGenSources(1, &sourceID_); - AudioCore::throwOpenALError("Source::Source(const std::string&)"); + OALAudioCore::throwOpenALError("Source::Source(const std::string&)"); open(name); } @@ -205,14 +208,14 @@ void Source::open(const std::string& name) ResourceManaged::resMgr_.getAudioData( ResourceManaged::getName(), bufferID); - // attach buffer to source + // attach buffer to source and set default settings alSourcei(sourceID_, AL_BUFFER, bufferID); alSourcef(sourceID_, AL_PITCH, 1.0); alSourcef(sourceID_, AL_GAIN, 1.0); alSourcefv(sourceID_, AL_POSITION, ORIGIN); alSourcefv(sourceID_, AL_VELOCITY, ORIGIN); - AudioCore::throwOpenALError("Source::open"); + OALAudioCore::throwOpenALError("Source::open"); } template @@ -233,7 +236,7 @@ Source& Source::operator=(const Source& rhs) alSourcefv(sourceID_, AL_POSITION, ORIGIN); alSourcefv(sourceID_, AL_VELOCITY, ORIGIN); - AudioCore::throwOpenALError("Source::operator="); + OALAudioCore::throwOpenALError("Source::operator="); } return *this; } @@ -241,7 +244,7 @@ Source& Source::operator=(const Source& rhs) template Source::operator bool() const { - return isValid(); + return isValid(); // do the work in isValid to avoid split implementation } template @@ -252,7 +255,7 @@ void Source::play() throw PreconditionException("Invalid Source::play call."); } - alSourcePlay(sourceID_); + alSourcePlay(sourceID_); // play it } template @@ -263,7 +266,7 @@ void Source::stop() throw PreconditionException("Invalid Source::stop call."); } - alSourceStop(sourceID_); + alSourceStop(sourceID_); // stop it } template @@ -274,7 +277,7 @@ void Source::pause() throw PreconditionException("Invalid Source::pause call."); } - alSourcePause(sourceID_); + alSourcePause(sourceID_); // pause it } template @@ -285,7 +288,7 @@ void Source::rewind() throw PreconditionException("Invalid Source::rewind call."); } - alSourceRewind(sourceID_); + alSourceRewind(sourceID_); // rewind it (doesn't stop) } template @@ -296,13 +299,13 @@ void Source::setLooping(bool loop) throw PreconditionException("Invalid Source::setLooping call."); } - alSourcei(sourceID_, AL_LOOPING, loop); + alSourcei(sourceID_, AL_LOOPING, loop); // toggle looping } template bool Source::isValid() const { - return alIsSource(sourceID_) == AL_TRUE; + return alIsSource(sourceID_) == AL_TRUE; // true if valid audio loaded } template @@ -313,7 +316,7 @@ bool Source::isPlaying() const throw PreconditionException("Invalid Source::isPlaying call."); } - // check state + // check state using OpenAL query function int state; alGetSourcei(sourceID_, AL_SOURCE_STATE, &state); return state == AL_PLAYING; @@ -327,7 +330,7 @@ bool Source::isLooping() const throw PreconditionException("Invalid Source::isLooping call."); } - // check looping status + // query looping status int loop; alGetSourcei(sourceID_, AL_LOOPING, &loop); return loop == AL_TRUE; @@ -337,6 +340,7 @@ template void Source::addResource(const std::string& name, const std::string& path) { + // adds an aliased resource ResourceManaged::resMgr_.newResource(name, ResourceDescriptor(path)); } @@ -344,6 +348,7 @@ void Source::addResource(const std::string& name, template void Source::addResource(const std::string& path) { + // add non-aliased resource ResourceManaged::resMgr_.newResource(path, ResourceDescriptor(path)); } diff --git a/src/audio/AudioCore.cpp b/src/audio/AudioCore.cpp index 88ff413..d586510 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.14 2005/10/15 04:57:19 cozman Exp $ +// $Id: AudioCore.cpp,v 1.15 2005/10/28 22:13:03 cozman Exp $ #ifdef PHOTON_USE_OPENAL @@ -19,8 +19,9 @@ namespace photon namespace audio { -//AudioCore::AudioCore() -AudioCore::AudioCore(const std::string& deviceName) + +OALAudioCore::OALAudioCore(const std::string& deviceName) : + AudioCore(deviceName) { //util::VersionInfo oalReq(0,0,7); // requires OpenAL 1.0 (TODO: check?) //util::ensureVersion("OpenAL", initOpenAL(), oalReq); @@ -28,7 +29,7 @@ AudioCore::AudioCore(const std::string& deviceName) initOpenAL(deviceName); // don't check version for now } -AudioCore::~AudioCore() +OALAudioCore::~OALAudioCore() { // retrieve both the context and device ALCcontext* context( alcGetCurrentContext() ); @@ -42,7 +43,7 @@ AudioCore::~AudioCore() alcMakeContextCurrent(0); } -std::string AudioCore::getAudioDeviceName() const +std::string OALAudioCore::getAudioDeviceName() const { ALCdevice* device (alcGetContextsDevice( alcGetCurrentContext() )); std::string name ( reinterpret_cast( @@ -51,7 +52,7 @@ std::string AudioCore::getAudioDeviceName() const return name; } -std::string AudioCore::checkOpenALError() +std::string OALAudioCore::checkOpenALError() { ALenum errCode = alGetError(); // fetch error code std::string err; @@ -85,7 +86,7 @@ std::string AudioCore::checkOpenALError() return err; } -void AudioCore::throwOpenALError(const std::string& func) +void OALAudioCore::throwOpenALError(const std::string& func) { std::string err( checkOpenALError() ); if(err.length()) // throw exception if non-empty string @@ -94,7 +95,7 @@ void AudioCore::throwOpenALError(const std::string& func) } } -util::VersionInfo AudioCore::initOpenAL(const std::string& deviceName) +util::VersionInfo OALAudioCore::initOpenAL(const std::string& deviceName) { ALCdevice* device(0); ALCcontext* context(0); @@ -135,7 +136,7 @@ util::VersionInfo AudioCore::initOpenAL(const std::string& deviceName) ss << alGetString(AL_VERSION); ss >> major >> junkc >> minor >> extra; - throwOpenALError("AudioCore::initOpenAL"); + throwOpenALError("OALAudioCore::initOpenAL"); return util::VersionInfo(major,minor,0,extra); } diff --git a/src/audio/SampleResourceManager.cpp b/src/audio/SampleResourceManager.cpp index 05cc086..d402a61 100644 --- a/src/audio/SampleResourceManager.cpp +++ b/src/audio/SampleResourceManager.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: SampleResourceManager.cpp,v 1.4 2005/08/10 05:36:30 cozman Exp $ +// $Id: SampleResourceManager.cpp,v 1.5 2005/10/28 22:13:03 cozman Exp $ #ifdef PHOTON_USE_OPENAL @@ -46,14 +46,14 @@ void SampleResourceManager::loadResourceData(SampleResource &res, alGenBuffers(1, &res.bufferID); // create OpenAL buffer - AudioCore::throwOpenALError("alGenBuffers"); + OALAudioCore::throwOpenALError("alGenBuffers"); // load WAV and pass it into OpenAL buffer loadWAVMemory(&filedata[0], format, data, size, freq); alBufferData(res.bufferID, format, (ALvoid*)data, size, freq); freeWAVMemory(data); - AudioCore::throwOpenALError("alBufferData"); + OALAudioCore::throwOpenALError("alBufferData"); } void SampleResourceManager::freeResourceData(SampleResource& res)