mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-31 21:45:33 +00:00
Use 6 125ms buffers for OpenAL streams
This commit is contained in:
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
|
||||
{
|
||||
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<ALuint>(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<char> data(sBufferSize);
|
||||
std::vector<char> data(mBufferSize);
|
||||
|
||||
alSourceStop(mSource);
|
||||
alSourcei(mSource, AL_BUFFER, 0);
|
||||
|
@ -251,7 +255,7 @@ bool OpenAL_SoundStream::process()
|
|||
|
||||
if(processed > 0)
|
||||
{
|
||||
std::vector<char> data(sBufferSize);
|
||||
std::vector<char> data(mBufferSize);
|
||||
do {
|
||||
ALuint bufid;
|
||||
size_t got;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue