X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsource.cpp;h=c4bb6f8e1a8d415f03b3cd401b1caa36b8d3649c;hb=14008b157c64752ba7c1cef831124992c35c4646;hp=fec965c5d8ede45e6487b8a2f0e70a03ab233624;hpb=35ea5cc8d1eb8c806885d27441548f630e7b1266;p=libs%2Fal.git diff --git a/source/source.cpp b/source/source.cpp index fec965c..c4bb6f8 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" @@ -43,25 +36,116 @@ void Source::attribute(ALenum attr, const float *v) alSourcefv(id, attr, v); } -void Source::set_buffer(Buffer &buffer) +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); + return static_cast(state); +} + +void Source::set_position(float x, float y, float z) +{ + attribute(AL_POSITION, x, y, z); +} + +void Source::set_looping(bool l) +{ + attribute(AL_LOOPING, l); +} + +void Source::set_gain(float g) +{ + attribute(AL_GAIN, g); +} + +void Source::set_rolloff_factor(float f) +{ + attribute(AL_ROLLOFF_FACTOR, f); +} + +void Source::set_buffer(const Buffer &buffer) { attribute(AL_BUFFER, static_cast(buffer.get_id())); } -void Source::queue_buffers(const vector &buffers) +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() +{ + attribute(AL_BUFFER, AL_NONE); +} + +unsigned Source::get_buffers_queued() const +{ + int n = 0; + get_attribute(AL_BUFFERS_QUEUED, &n); + return n; +} + +unsigned Source::get_buffers_processed() const +{ + int n = 0; + get_attribute(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