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
|
|
|
|
2009-12-30 15:15:46 +00:00
|
|
|
// Poor mans reference counting. Might improve this later.
|
|
|
|
int *refCnt;
|
|
|
|
|
2009-12-29 14:54:05 +00:00
|
|
|
public:
|
2010-01-01 13:34:46 +00:00
|
|
|
OpenAL_Sound(SampleSourcePtr input);
|
2009-12-30 15:15:46 +00:00
|
|
|
OpenAL_Sound(ALuint buf, int *ref); // Used for cloning
|
2009-12-29 14:54:05 +00:00
|
|
|
~OpenAL_Sound();
|
|
|
|
|
|
|
|
void play();
|
|
|
|
void stop();
|
|
|
|
void pause();
|
2009-12-30 15:15:46 +00:00
|
|
|
bool isPlaying() const;
|
2009-12-29 14:54:05 +00:00
|
|
|
void setVolume(float);
|
|
|
|
void setPos(float x, float y, float z);
|
2009-12-30 15:15:46 +00:00
|
|
|
void setRepeat(bool);
|
|
|
|
void setStreaming(bool) {} // Not implemented yet
|
|
|
|
Sound* clone() const;
|
|
|
|
|
|
|
|
/// Not implemented
|
|
|
|
void setPan(float) {}
|
2009-12-29 14:54:05 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-01 13:34:46 +00:00
|
|
|
SoundPtr load(const std::string &file, bool stream=false) { assert(0); }
|
|
|
|
SoundPtr load(Stream::StreamPtr input, bool stream=false) { assert(0); }
|
|
|
|
SoundPtr load(SampleSourcePtr input, bool stream=false)
|
|
|
|
{ return SoundPtr(new OpenAL_Sound(input)); }
|
2009-12-29 14:54:05 +00:00
|
|
|
|
|
|
|
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
|