+ 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_);
+ }
+ }
+
+
+ ALuint source_;
+ BufferP buffer_;
+
+ bool playing_;
+ bool looping_;
+
+ std::queue<BufferP> queue_;
+ std::vector<BufferP> expired_;
+};