X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsource.cpp;h=df3063ce50e909c156b5d2322745d7d40f4eb6d5;hb=HEAD;hp=fec965c5d8ede45e6487b8a2f0e70a03ab233624;hpb=35ea5cc8d1eb8c806885d27441548f630e7b1266;p=libs%2Fal.git diff --git a/source/source.cpp b/source/source.cpp index fec965c..df3063c 100644 --- a/source/source.cpp +++ b/source/source.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspal -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Diestributed under the LGPL -*/ - #include "buffer.h" #include "source.h" @@ -23,45 +16,111 @@ Source::~Source() alDeleteSources(1, &id); } -void Source::attribute(ALenum attr, int v) +SourceState Source::get_state() const +{ + int state = INITIAL; + alGetSourcei(id, AL_SOURCE_STATE, &state); + return static_cast(state); +} + +void Source::set_position(float x, float y, float z) { - alSourcei(id, attr, v); + alSource3f(id, AL_POSITION, x, y, z); } -void Source::attribute(ALenum attr, float v) +void Source::set_velocity(float x, float y, float z) { - alSourcef(id, attr, v); + alSource3f(id, AL_VELOCITY, x, y, z); } -void Source::attribute(ALenum attr, float v0, float v1, float v2) +void Source::set_looping(bool l) { - alSource3f(id, attr, v0, v1, v2); + alSourcei(id, AL_LOOPING, l); } -void Source::attribute(ALenum attr, const float *v) +void Source::set_gain(float g) { - alSourcefv(id, attr, v); + alSourcef(id, AL_GAIN, g); } -void Source::set_buffer(Buffer &buffer) +void Source::set_rolloff_factor(float f) { - attribute(AL_BUFFER, static_cast(buffer.get_id())); + alSourcef(id, AL_ROLLOFF_FACTOR, f); } -void Source::queue_buffers(const vector &buffers) +void Source::set_buffer(const Buffer &buffer) +{ + alSourcei(id, AL_BUFFER, buffer.get_id()); +} + +void Source::queue_buffers(const vector &buffers) { vector ids; ids.reserve(buffers.size()); - for(vector::const_iterator i=buffers.begin(); i!=buffers.end(); ++i) + for(vector::const_iterator i=buffers.begin(); i!=buffers.end(); ++i) ids.push_back((*i)->get_id()); alSourceQueueBuffers(id, ids.size(), &ids.front()); } -void Source::queue_buffer(Buffer &buffer) +void Source::queue_buffer(const Buffer &buffer) { - uint bid=buffer.get_id(); + uint bid = buffer.get_id(); alSourceQueueBuffers(id, 1, &bid); } +void Source::unqueue_buffers(const vector &buffers) +{ + vector ids; + ids.reserve(buffers.size()); + for(vector::const_iterator i=buffers.begin(); i!=buffers.end(); ++i) + ids.push_back((*i)->get_id()); + alSourceUnqueueBuffers(id, ids.size(), &ids.front()); +} + +void Source::unqueue_buffer(const Buffer &buffer) +{ + uint bid = buffer.get_id(); + alSourceUnqueueBuffers(id, 1, &bid); +} + +void Source::clear_buffers() +{ + alSourcei(id, AL_BUFFER, AL_NONE); +} + +unsigned Source::get_buffers_queued() const +{ + int n = 0; + alGetSourceiv(id, AL_BUFFERS_QUEUED, &n); + return n; +} + +unsigned Source::get_buffers_processed() const +{ + int n = 0; + alGetSourceiv(id, AL_BUFFERS_PROCESSED, &n); + return n; +} + +void Source::play() +{ + alSourcePlay(id); +} + +void Source::pause() +{ + alSourcePause(id); +} + +void Source::stop() +{ + alSourceStop(id); +} + +void Source::rewind() +{ + alSourceRewind(id); +} + } // namespace AL } // namespace Msp