- buffer_ = buf.buffer_;
- retain();
- }
-
- buffer& operator = (const buffer& buf)
- {
- buffer_ = buf.buffer_;
- retain();
- return *this;
- }
-
- ~buffer()
- {
- release();
- }
-
-
- void queue(ALuint source) const
- {
- if (*this)
- {
- alSourceQueueBuffers(source, 1, &buffer_);
- retain();
- log_warning("queued buffer:", buffer_);
- }
- }
-
- static buffer unqueue(ALuint source)
- {
- ALuint buf = (ALuint)-1;
- alSourceUnqueueBuffers(source, 1, &buf);
- log_warning("unqueued buffer:", buf);
- return buffer(buf);
- }
-
- void set(ALuint source) const
- {
- log_warning("set buffer:", buffer_);
- if (*this) alSourcei(source, AL_BUFFER, buffer_);
- }
-
- operator bool () const
- {
- return buffer_ != (ALuint)-1;
- }
-
-
-private:
-
- explicit buffer(ALuint buf) :
- buffer_(buf) {}
-
-
- void retain() const
- {
- retcount_lookup::iterator it = retain_counts_.find(buffer_);
- if (it.valid()) ++it->second;
- }
-
- void release() const
- {
- retcount_lookup::iterator it = retain_counts_.find(buffer_);
- if (it.valid() && --it->second <= 0)
- {
- alDeleteBuffers(1, &buffer_);
- retain_counts_.erase(it);
- log_warning("kill buffer:", buffer_);
- }
- }
-
-
- ALuint buffer_;
- sound_backend backend_;
-
- static retcount_lookup retain_counts_;
-};
-
-buffer::retcount_lookup buffer::retain_counts_;
-
-
-
-// SOUND RESOURCE
-
-class sound_resource
-{
-public:
-
- sound_resource(const std::string& path)
- {
- log_info("audio path is", path);