1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-28 08:37:12 +00:00

Use 6 125ms buffers for OpenAL streams

This commit is contained in:
Chris Robinson 2012-03-19 05:29:04 -07:00
parent dc6354b2f9
commit 8f9d4ff841
3 changed files with 31 additions and 4 deletions

@ -53,8 +53,8 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
// //
class OpenAL_SoundStream : public Sound class OpenAL_SoundStream : public Sound
{ {
static const ALuint sNumBuffers = 4; static const ALuint sNumBuffers = 6;
static const ALuint sBufferSize = 32768; static const ALfloat sBufferLength = 0.125f;
OpenAL_Output &mOutput; OpenAL_Output &mOutput;
@ -63,6 +63,7 @@ class OpenAL_SoundStream : public Sound
ALenum mFormat; ALenum mFormat;
ALsizei mSampleRate; ALsizei mSampleRate;
ALuint mBufferSize;
DecoderPtr mDecoder; DecoderPtr mDecoder;
@ -171,6 +172,9 @@ OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, DecoderPtr decoder
mDecoder->getInfo(&srate, &chans, &type); mDecoder->getInfo(&srate, &chans, &type);
mFormat = getALFormat(chans, type); mFormat = getALFormat(chans, type);
mSampleRate = srate; mSampleRate = srate;
mBufferSize = static_cast<ALuint>(sBufferLength*srate);
mBufferSize = framesToBytes(mBufferSize, chans, type);
} }
catch(std::exception &e) catch(std::exception &e)
{ {
@ -193,7 +197,7 @@ OpenAL_SoundStream::~OpenAL_SoundStream()
void OpenAL_SoundStream::play(float volume, float pitch) void OpenAL_SoundStream::play(float volume, float pitch)
{ {
std::vector<char> data(sBufferSize); std::vector<char> data(mBufferSize);
alSourceStop(mSource); alSourceStop(mSource);
alSourcei(mSource, AL_BUFFER, 0); alSourcei(mSource, AL_BUFFER, 0);
@ -251,7 +255,7 @@ bool OpenAL_SoundStream::process()
if(processed > 0) if(processed > 0)
{ {
std::vector<char> data(sBufferSize); std::vector<char> data(mBufferSize);
do { do {
ALuint bufid; ALuint bufid;
size_t got; size_t got;

@ -17,6 +17,9 @@ namespace MWSound
}; };
const char *getChannelConfigName(ChannelConfig config); 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 class Sound_Decoder
{ {
public: public:

@ -485,4 +485,24 @@ namespace MWSound
} }
return "(unknown channel config)"; 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);
}
} }