post-Kernel
This commit is contained in:
parent
23324b1508
commit
51f0f64807
@ -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 <Singleton> core for audio manipulation/control. Defines the
|
||||
// Photon's <Singleton> core for audio manipulation/control. Defines the
|
||||
// interface through which all audio related functions are performed.
|
||||
//
|
||||
// Parent:
|
||||
// <Singleton>
|
||||
class AudioCore : public util::Singleton<AudioCore>
|
||||
class AudioCore : public Singleton<AudioCore>
|
||||
{
|
||||
|
||||
// Group: (Con/De)structors
|
||||
public:
|
||||
// Function: AudioCore
|
||||
// Initialize underlying APIs and setup <Task> 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<AudioCore>;
|
||||
friend class std::auto_ptr<AudioCore>;
|
||||
static std::string deviceName_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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<const ALubyte*>(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_;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user