2009-12-29 14:54:05 +00:00
|
|
|
#ifndef MANGLE_SOUND_OPENAL_OUT_H
|
|
|
|
#define MANGLE_SOUND_OPENAL_OUT_H
|
|
|
|
|
|
|
|
#include "../output.h"
|
2009-12-30 11:29:24 +00:00
|
|
|
#include "../../stream/filters/buffer_stream.h"
|
2009-12-29 14:54:05 +00:00
|
|
|
|
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
namespace Mangle {
|
|
|
|
namespace Sound {
|
|
|
|
|
|
|
|
/// OpenAL sound output
|
|
|
|
class OpenAL_Sound : public Sound
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ALuint inst;
|
2009-12-30 11:29:24 +00:00
|
|
|
ALuint bufferID;
|
2009-12-29 14:54:05 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
OpenAL_Sound(SampleSource *input);
|
|
|
|
~OpenAL_Sound();
|
|
|
|
|
|
|
|
/// Play or resume the sound
|
|
|
|
void play();
|
|
|
|
|
|
|
|
/// Stop the sound
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
/// Pause the sound, may be resumed later
|
|
|
|
void pause();
|
|
|
|
|
|
|
|
/// Check if the sound is still playing
|
|
|
|
bool isPlaying();
|
|
|
|
|
|
|
|
/// Set the volume. The parameter must be between 0.0 and 1.0.
|
|
|
|
void setVolume(float);
|
|
|
|
|
|
|
|
/// Set the 3D position.
|
|
|
|
void setPos(float x, float y, float z);
|
|
|
|
};
|
|
|
|
|
2009-12-30 11:29:24 +00:00
|
|
|
class OpenAL_Factory : public SoundFactory
|
2009-12-29 14:54:05 +00:00
|
|
|
{
|
|
|
|
ALCdevice *Device;
|
|
|
|
ALCcontext *Context;
|
|
|
|
bool didSetup;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Initialize object. Pass true (default) if you want the
|
|
|
|
/// constructor to set up the current ALCdevice and ALCcontext for
|
|
|
|
/// you.
|
2009-12-30 11:29:24 +00:00
|
|
|
OpenAL_Factory(bool doSetup = true)
|
2009-12-29 14:54:05 +00:00
|
|
|
: didSetup(doSetup)
|
|
|
|
{
|
|
|
|
needsUpdate = false;
|
|
|
|
has3D = true;
|
|
|
|
canRepeatStream = false;
|
|
|
|
canLoadFile = false;
|
|
|
|
canLoadStream = false;
|
|
|
|
canLoadSource = true;
|
|
|
|
|
|
|
|
if(doSetup)
|
|
|
|
{
|
|
|
|
// Set up sound system
|
|
|
|
Device = alcOpenDevice(NULL);
|
|
|
|
Context = alcCreateContext(Device, NULL);
|
|
|
|
|
|
|
|
if(!Device || !Context)
|
|
|
|
fail("Failed to initialize context or device");
|
|
|
|
|
|
|
|
alcMakeContextCurrent(Context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-30 11:29:24 +00:00
|
|
|
~OpenAL_Factory()
|
2009-12-29 14:54:05 +00:00
|
|
|
{
|
|
|
|
// Deinitialize sound system
|
|
|
|
if(didSetup)
|
|
|
|
{
|
|
|
|
alcMakeContextCurrent(NULL);
|
|
|
|
if(Context) alcDestroyContext(Context);
|
|
|
|
if(Device) alcCloseDevice(Device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Sound *load(const std::string &file, bool stream=false) { assert(0); }
|
|
|
|
Sound *load(Stream::Stream *input, bool stream=false) { assert(0); }
|
|
|
|
Sound *load(SampleSource* input, bool stream=false)
|
|
|
|
{ return new OpenAL_Sound(input); }
|
|
|
|
|
|
|
|
void update() {}
|
|
|
|
setListenerPos(float x, float y, float z,
|
|
|
|
float fx, float fy, float fz,
|
|
|
|
float ux, float uy, float uz)
|
|
|
|
{
|
|
|
|
ALfloat orient[6];
|
|
|
|
orient[0] = fx;
|
|
|
|
orient[1] = fy;
|
|
|
|
orient[2] = fz;
|
|
|
|
orient[3] = ux;
|
|
|
|
orient[4] = uy;
|
|
|
|
orient[5] = uz;
|
|
|
|
alListener3f(AL_POSITION, x, y, z);
|
|
|
|
alListenerfv(AL_ORIENTATION, orient);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}} // namespaces
|
|
|
|
#endif
|