void update() { ALint processed; alGetSourceiv(src_, AL_BUFFERS_PROCESSED, &processed); std::vector<ALuint> unqueued(processed); alSourceUnqueueBuffers(src_, processed, &unqueued.front()); int queuing_count = 0; for (; queuing_count < processed; ++queuing_count) { if (not loop_play_ and loader_->is_end()) { loader_.reset(); ++queuing_count; break; } if (loader_->is_end()) { ticks_.push_back(0); } buf_sizes_.push_back(loader_->load_buffer(unqueued[queuing_count])); ticks_.push_back(loader_->midi_ticks()); } alSourceQueueBuffers(src_, queuing_count, &unqueued.front()); if (fade_milli_ != 0) { SET_CONTEXT(ctx_); loop_count_++; if (fade_ended()) { alSourceStop(src_); } else { alSourcef(src_, AL_GAIN, current_volume()); } } }
void set_buffer_loader(EASYRPG_SHARED_PTR<buffer_loader> const &l) { SET_CONTEXT(ctx_); alSourceStop(src_); alSourcei(src_, AL_BUFFER, AL_NONE); if (not l) { loader_.reset(); return; } ALint unqueuing_count; alGetSourceiv(src_, AL_BUFFERS_QUEUED, &unqueuing_count); std::vector<ALuint> unqueued(unqueuing_count); alSourceUnqueueBuffers(src_, unqueuing_count, &unqueued.front()); loader_ = l; int queuing_count = 0; BOOST_ASSERT(not l->is_end()); ticks_.push_back(0); for (; queuing_count < BUFFER_NUMBER; ++queuing_count) { buf_sizes_.push_back(loader_->load_buffer(buffers_[queuing_count])); ticks_.push_back(loader_->midi_ticks()); if (loader_->is_end()) { queuing_count++; break; } } alSourceQueueBuffers(src_, queuing_count, buffers_.data()); alSourcePlay(src_); }
void set_buffer_loader(std::shared_ptr<buffer_loader> const &l) { SET_CONTEXT(ctx_); alSourceStop(src_); alSourcei(src_, AL_BUFFER, AL_NONE); if (!l) { loader_.reset(); return; } ALint unqueuing_count; alGetSourceiv(src_, AL_BUFFERS_QUEUED, &unqueuing_count); std::vector<ALuint> unqueued(unqueuing_count); alSourceUnqueueBuffers(src_, unqueuing_count, &unqueued.front()); loader_ = l; int queuing_count = 0; assert(!l->is_end()); ticks_[0] = 0; for (; queuing_count < BUFFER_NUMBER; ++queuing_count) { buf_sizes_[queuing_count] = loader_->load_buffer(buffers_[queuing_count]); ticks_[queuing_count + 1] = loader_->midi_ticks(); if (loader_->is_end()) { queuing_count++; break; } } alSourceQueueBuffers(src_, queuing_count, buffers_.data()); alSourcePlay(src_); }