diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 81b874dbf8..3e07c3f64e 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -53,8 +53,8 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type) // class OpenAL_SoundStream : public Sound { - static const ALuint sNumBuffers = 4; - static const ALuint sBufferSize = 32768; + static const ALuint sNumBuffers = 6; + static const ALfloat sBufferLength = 0.125f; OpenAL_Output &mOutput; @@ -63,6 +63,7 @@ class OpenAL_SoundStream : public Sound ALenum mFormat; ALsizei mSampleRate; + ALuint mBufferSize; DecoderPtr mDecoder; @@ -171,6 +172,9 @@ OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, DecoderPtr decoder mDecoder->getInfo(&srate, &chans, &type); mFormat = getALFormat(chans, type); mSampleRate = srate; + + mBufferSize = static_cast(sBufferLength*srate); + mBufferSize = framesToBytes(mBufferSize, chans, type); } catch(std::exception &e) { @@ -193,7 +197,7 @@ OpenAL_SoundStream::~OpenAL_SoundStream() void OpenAL_SoundStream::play(float volume, float pitch) { - std::vector data(sBufferSize); + std::vector data(mBufferSize); alSourceStop(mSource); alSourcei(mSource, AL_BUFFER, 0); @@ -251,7 +255,7 @@ bool OpenAL_SoundStream::process() if(processed > 0) { - std::vector data(sBufferSize); + std::vector data(mBufferSize); do { ALuint bufid; size_t got; diff --git a/apps/openmw/mwsound/sound_decoder.hpp b/apps/openmw/mwsound/sound_decoder.hpp index 957681e93a..2b16eaeeed 100644 --- a/apps/openmw/mwsound/sound_decoder.hpp +++ b/apps/openmw/mwsound/sound_decoder.hpp @@ -17,6 +17,9 @@ namespace MWSound }; const char *getChannelConfigName(ChannelConfig config); + size_t framesToBytes(size_t frames, ChannelConfig config, SampleType type); + size_t bytesToFrames(size_t bytes, ChannelConfig config, SampleType type); + class Sound_Decoder { public: diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index a263fb1ac0..d86c5c2f50 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -485,4 +485,24 @@ namespace MWSound } return "(unknown channel config)"; } + + size_t framesToBytes(size_t frames, ChannelConfig config, SampleType type) + { + switch(config) + { + case ChannelConfig_Mono: frames *= 1; break; + case ChannelConfig_Stereo: frames *= 2; break; + } + switch(type) + { + case SampleType_UInt8: frames *= 1; break; + case SampleType_Int16: frames *= 2; break; + } + return frames; + } + + size_t bytesToFrames(size_t bytes, ChannelConfig config, SampleType type) + { + return bytes / framesToBytes(1, config, type); + } }