From: Mikko Rasa Date: Sat, 17 Nov 2012 23:36:41 +0000 (+0200) Subject: Remove the general-purpose attribute functions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2964e0cbc2fd4d6b838cc5f0598db1318fb4c529;p=libs%2Fal.git Remove the general-purpose attribute functions --- diff --git a/source/listener.cpp b/source/listener.cpp index 74c50c9..0075148 100644 --- a/source/listener.cpp +++ b/source/listener.cpp @@ -3,35 +3,51 @@ 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 diff --git a/source/listener.h b/source/listener.h index 98e1638..0876815 100644 --- a/source/listener.h +++ b/source/listener.h @@ -12,14 +12,16 @@ Represents the listener in the 3D environment. This class is a singleton. 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); }; diff --git a/source/source.cpp b/source/source.cpp index c4bb6f8..df3063c 100644 --- a/source/source.cpp +++ b/source/source.cpp @@ -16,66 +16,41 @@ Source::~Source() 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(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(buffer.get_id())); + alSourcei(id, AL_BUFFER, buffer.get_id()); } void Source::queue_buffers(const vector &buffers) @@ -110,20 +85,20 @@ void Source::unqueue_buffer(const Buffer &buffer) 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; } diff --git a/source/source.h b/source/source.h index 769b354..8e1e947 100644 --- a/source/source.h +++ b/source/source.h @@ -30,15 +30,9 @@ public: 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);