+ inline void clear()
+ {
+ // try to remove expired buffers
+ std::vector<BufferP>::iterator it;
+ for (it = expired_.end() - 1; it >= expired_.begin(); --it)
+ {
+ if ((*it)->clear()) expired_.erase(it);
+ }
+ }
+
+
+ void stop()
+ {
+ alSourceStop(source_);
+ playing_ = false;
+ }
+
+ inline void pause()
+ {
+ alSourcePause(source_);
+ playing_ = false;
+ }
+
+ inline void resume()
+ {
+ alSourcePlay(source_);
+ playing_ = true;
+ }
+
+
+ inline void setSample(const std::string& name)
+ {
+ bool playing = isPlaying();
+ ALenum type;
+ alGetSourcei(source_, AL_SOURCE_TYPE, &type);
+
+ stop();
+
+ //alSourcei(source_, AL_BUFFER, AL_NONE);
+ buffer_ = Buffer::getInstance(name);
+
+ if (type == AL_STREAMING)
+ {
+ if (playing) stream();
+ }
+ else
+ {
+ if (playing) play();
+ }
+ }
+
+ inline void enqueue(const std::string& name)
+ {
+ BufferP buffer = Buffer::getInstance(name);
+ queue_.push(buffer);
+ }
+
+
+ inline bool isPlaying() const
+ {
+ if (playing_) return true;
+
+ ALenum state;
+ alGetSourcei(source_, AL_SOURCE_STATE, &state);
+
+ return state == AL_PLAYING;
+ }
+
+
+ inline void setLooping(bool looping)
+ {
+ looping_ = looping;
+
+ ALenum type;
+ alGetSourcei(source_, AL_SOURCE_TYPE, &type);
+
+ if (type != AL_STREAMING)
+ {
+ alSourcei(source_, AL_LOOPING, looping_);
+ }
+ }