namespace Msp {
namespace AL {
+Listener::Listener()
+{
+ orientation[0] = 0;
+ orientation[1] = 0;
+ orientation[2] = -1;
+ orientation[3] = 0;
+ orientation[4] = 1;
+ orientation[5] = 0;
+}
+
Listener &Listener::instance()
{
static Listener listener;
return listener;
}
-void Listener::attribute(ALenum attr, float v)
+void Listener::set_position(float x, float y, float z)
{
- alListenerf(attr, v);
+ alListener3f(AL_POSITION, x, y, z);
}
-void Listener::attribute(ALenum attr, float v0, float v1, float v2)
+void Listener::set_forward_direction(float x, float y, float z)
{
- alListener3f(attr, v0, v1, v2);
+ orientation[0] = x;
+ orientation[1] = y;
+ orientation[2] = z;
+ alListenerfv(AL_ORIENTATION, orientation);
}
-void Listener::attribute(ALenum attr, const float *v)
+void Listener::set_up_direction(float x, float y, float z)
{
- alListenerfv(attr, v);
+ orientation[3] = x;
+ orientation[4] = y;
+ orientation[5] = z;
+ alListenerfv(AL_ORIENTATION, orientation);
}
-void Listener::set_position(float x, float y, float z)
+void Listener::set_velocity(float x, float y, float z)
{
- attribute(AL_POSITION, x, y, z);
+ alListener3f(AL_VELOCITY, x, y, z);
}
void Listener::set_gain(float g)
{
- attribute(AL_GAIN, g);
+ alListenerf(AL_GAIN, g);
}
} // namespace AL
class Listener
{
private:
- Listener() { }
+ float orientation[6];
+
+ Listener();
public:
static Listener &instance();
- void attribute(ALenum, float);
- void attribute(ALenum, float, float, float);
- void attribute(ALenum, const float *);
void set_position(float, float, float);
+ void set_forward_direction(float, float, float);
+ void set_up_direction(float, float, float);
+ void set_velocity(float, float, float);
void set_gain(float);
};
alDeleteSources(1, &id);
}
-void Source::attribute(ALenum attr, int v)
-{
- alSourcei(id, attr, v);
-}
-
-void Source::attribute(ALenum attr, float v)
-{
- alSourcef(id, attr, v);
-}
-
-void Source::attribute(ALenum attr, float v0, float v1, float v2)
-{
- alSource3f(id, attr, v0, v1, v2);
-}
-
-void Source::attribute(ALenum attr, const float *v)
-{
- alSourcefv(id, attr, v);
-}
-
-void Source::get_attribute(ALenum attr, int *v) const
-{
- alGetSourcei(id, attr, v);
-}
-
-void Source::get_attribute(ALenum attr, float *v) const
-{
- alGetSourcef(id, attr, v);
-}
-
SourceState Source::get_state() const
{
- int state;
- get_attribute(AL_SOURCE_STATE, &state);
+ int state = INITIAL;
+ alGetSourcei(id, AL_SOURCE_STATE, &state);
return static_cast<SourceState>(state);
}
void Source::set_position(float x, float y, float z)
{
- attribute(AL_POSITION, x, y, z);
+ alSource3f(id, AL_POSITION, x, y, z);
+}
+
+void Source::set_velocity(float x, float y, float z)
+{
+ alSource3f(id, AL_VELOCITY, x, y, z);
}
void Source::set_looping(bool l)
{
- attribute(AL_LOOPING, l);
+ alSourcei(id, AL_LOOPING, l);
}
void Source::set_gain(float g)
{
- attribute(AL_GAIN, g);
+ alSourcef(id, AL_GAIN, g);
}
void Source::set_rolloff_factor(float f)
{
- attribute(AL_ROLLOFF_FACTOR, f);
+ alSourcef(id, AL_ROLLOFF_FACTOR, f);
}
void Source::set_buffer(const Buffer &buffer)
{
- attribute(AL_BUFFER, static_cast<int>(buffer.get_id()));
+ alSourcei(id, AL_BUFFER, buffer.get_id());
}
void Source::queue_buffers(const vector<const Buffer *> &buffers)
void Source::clear_buffers()
{
- attribute(AL_BUFFER, AL_NONE);
+ alSourcei(id, AL_BUFFER, AL_NONE);
}
unsigned Source::get_buffers_queued() const
{
int n = 0;
- get_attribute(AL_BUFFERS_QUEUED, &n);
+ alGetSourceiv(id, AL_BUFFERS_QUEUED, &n);
return n;
}
unsigned Source::get_buffers_processed() const
{
int n = 0;
- get_attribute(AL_BUFFERS_PROCESSED, &n);
+ alGetSourceiv(id, AL_BUFFERS_PROCESSED, &n);
return n;
}
Source();
~Source();
- void attribute(ALenum, int);
- void attribute(ALenum, float);
- void attribute(ALenum, float, float, float);
- void attribute(ALenum, const float *);
- void get_attribute(ALenum, int *) const;
- void get_attribute(ALenum, float *) const;
-
SourceState get_state() const;
void set_position(float, float, float);
+ void set_velocity(float, float, float);
void set_gain(float);
void set_rolloff_factor(float);