post-Kernel
This commit is contained in:
parent
23324b1508
commit
51f0f64807
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// 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
|
#ifndef PHOTON_AUDIO_AUDIOCORE_HPP
|
||||||
#define PHOTON_AUDIO_AUDIOCORE_HPP
|
#define PHOTON_AUDIO_AUDIOCORE_HPP
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#include "al.h"
|
#include "al.h"
|
||||||
#include "alc.h"
|
#include "alc.h"
|
||||||
|
|
||||||
#include "util/Singleton.hpp"
|
#include "Task.hpp"
|
||||||
#include "util/VersionInfo.hpp"
|
#include "util/VersionInfo.hpp"
|
||||||
|
|
||||||
namespace photon
|
namespace photon
|
||||||
@ -22,14 +22,24 @@ namespace audio
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Class: AudioCore
|
// 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.
|
// interface through which all audio related functions are performed.
|
||||||
//
|
//
|
||||||
// Parent:
|
// Parent:
|
||||||
// <Singleton>
|
// <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
|
// Group: Accessors
|
||||||
public:
|
public:
|
||||||
// Function: getAudioDeviceName
|
// Function: getAudioDeviceName
|
||||||
@ -38,21 +48,21 @@ public:
|
|||||||
// Returns:
|
// Returns:
|
||||||
// Name of audio device currently in use.
|
// Name of audio device currently in use.
|
||||||
std::string getAudioDeviceName() const;
|
std::string getAudioDeviceName() const;
|
||||||
|
|
||||||
// Group: Initialization
|
// Group: Initialization
|
||||||
public:
|
public:
|
||||||
// Function: setDesiredDevice
|
// 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.
|
// 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
|
// use the specified audio device, otherwise the default device will be
|
||||||
// used.
|
// used.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// name - Name of audio device to use.
|
// name - Name of audio device to use.
|
||||||
static void setDesiredDevice(const std::string& name);
|
static void setDesiredDevice(const std::string& name);
|
||||||
|
|
||||||
// OpenAL specifics
|
// OpenAL specifics
|
||||||
private:
|
private:
|
||||||
util::VersionInfo initOpenAL();
|
util::VersionInfo initOpenAL();
|
||||||
@ -60,15 +70,7 @@ private:
|
|||||||
|
|
||||||
// data members
|
// data members
|
||||||
private:
|
private:
|
||||||
static std::string deviceName_;
|
static std::string deviceName_;
|
||||||
|
|
||||||
// Singleton-required code
|
|
||||||
private:
|
|
||||||
AudioCore();
|
|
||||||
~AudioCore();
|
|
||||||
|
|
||||||
friend class util::Singleton<AudioCore>;
|
|
||||||
friend class std::auto_ptr<AudioCore>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// 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"
|
#include "audio/AudioCore.hpp"
|
||||||
|
|
||||||
@ -16,7 +16,29 @@ namespace photon
|
|||||||
{
|
{
|
||||||
namespace audio
|
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
|
std::string AudioCore::getAudioDeviceName() const
|
||||||
{
|
{
|
||||||
ALCdevice* device (alcGetContextsDevice( alcGetCurrentContext() ));
|
ALCdevice* device (alcGetContextsDevice( alcGetCurrentContext() ));
|
||||||
@ -35,12 +57,12 @@ util::VersionInfo AudioCore::initOpenAL()
|
|||||||
uint major,minor;
|
uint major,minor;
|
||||||
|
|
||||||
// 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,11 +71,11 @@ util::VersionInfo AudioCore::initOpenAL()
|
|||||||
|
|
||||||
if(context == 0)
|
if(context == 0)
|
||||||
{
|
{
|
||||||
throw APIError("Failed to obtain an OpenAL context: " +
|
throw APIError("Failed to obtain an OpenAL context: " +
|
||||||
checkOpenALError());
|
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"
|
// Version is in format "OpenAL 1.0"
|
||||||
ss << alGetString(AL_VERSION);
|
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_ is used inside initOpenAL, must be set prior to construction
|
||||||
deviceName_ = name;
|
deviceName_ = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AudioCore::deviceName_;
|
|
||||||
|
|
||||||
AudioCore::AudioCore()
|
std::string AudioCore::deviceName_;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user