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 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 ALAudio::SE_Play(std::string const &file, int volume, int pitch) { SET_CONTEXT(ctx_); EASYRPG_SHARED_PTR<source> src = create_source(false); alSourcef(src->get(), AL_PITCH, pitch * 0.01f); src->set_volume(volume * 0.01f); src->set_buffer_loader(getSound(*src, file)); se_src_.push_back(src); }
bool Bitmap::WritePNG(std::ostream& os) const { size_t const width = GetWidth(), height = GetHeight(); size_t const stride = width * 4; std::vector<uint32_t> data(width * height); EASYRPG_SHARED_PTR<pixman_image_t> dst (pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height, &data.front(), stride), pixman_image_unref); pixman_image_composite32(PIXMAN_OP_SRC, bitmap, NULL, dst.get(), 0, 0, 0, 0, 0, 0, width, height); return ImagePNG::WritePNG(os, width, height, &data.front()); }
bool ALAudio::load_sndfile(std::string const& filename, EASYRPG_SHARED_PTR<buffer> const& buf) { SF_INFO info; EASYRPG_SHARED_PTR<SNDFILE> file(sf_open(filename.c_str(), SFM_READ, &info), sf_close); if(! file) { return false; } // load data std::vector<int16_t> data; EASYRPG_ARRAY<int16_t, 4096> read_buf; size_t read_size = 0; while((read_size = sf_read_short(file.get(), read_buf.data(), read_buf.size())) != 0) { data.insert(data.end(), read_buf.begin(), read_buf.begin() + read_size); } // channel check ALsizei const channels = (info.channels == 1)? AL_FORMAT_MONO16: (info.channels == 2)? AL_FORMAT_STEREO16: AL_INVALID_VALUE; if(channels == AL_INVALID_VALUE) { return false; } alBufferData(buf->get(), channels, &data.front(), data.size() * sizeof(int16_t), info.samplerate); return true; }
void ALAudio::source::play_buffer(EASYRPG_SHARED_PTR<buffer> const& buf) { SET_CONTEXT(ctx_); buf_ = buf; ALenum state = AL_INVALID_VALUE; alGetSourcei(src_, AL_SOURCE_STATE, &state); if(state != AL_STOPPED) { alSourceStop(src_); } if(buf_) { alSourcei(src_, AL_BUFFER, buf->get()); alSourcei(src_, AL_SAMPLE_OFFSET, 0); alSourcePlay(src_); } else { alSourcei(src_, AL_BUFFER, AL_NONE); } }