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::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()); }
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); } }