Use an std::array for the OpenAL stream buffers

experimental
Chris Robinson 7 years ago
parent 780e82480d
commit d68e1581ee

@ -273,13 +273,12 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
// //
class OpenAL_SoundStream class OpenAL_SoundStream
{ {
static const ALuint sNumBuffers = 6;
static const ALfloat sBufferLength; static const ALfloat sBufferLength;
private: private:
ALuint mSource; ALuint mSource;
ALuint mBuffers[sNumBuffers]; std::array<ALuint,6> mBuffers;
ALint mCurrentBufIdx; ALint mCurrentBufIdx;
ALenum mFormat; ALenum mFormat;
@ -392,16 +391,17 @@ private:
OpenAL_SoundStream::OpenAL_SoundStream(ALuint src, DecoderPtr decoder) OpenAL_SoundStream::OpenAL_SoundStream(ALuint src, DecoderPtr decoder)
: mSource(src), mBuffers{0}, mCurrentBufIdx(0), mFormat(AL_NONE), mSampleRate(0) : mSource(src), mCurrentBufIdx(0), mFormat(AL_NONE), mSampleRate(0)
, mBufferSize(0), mFrameSize(0), mSilence(0), mDecoder(std::move(decoder)) , mBufferSize(0), mFrameSize(0), mSilence(0), mDecoder(std::move(decoder))
, mLoudnessAnalyzer(nullptr) , mLoudnessAnalyzer(nullptr)
{ {
mBuffers.fill(0);
} }
OpenAL_SoundStream::~OpenAL_SoundStream() OpenAL_SoundStream::~OpenAL_SoundStream()
{ {
if(mBuffers[0] && alIsBuffer(mBuffers[0])) if(mBuffers[0] && alIsBuffer(mBuffers[0]))
alDeleteBuffers(sNumBuffers, mBuffers); alDeleteBuffers(mBuffers.size(), mBuffers.data());
alGetError(); alGetError();
mDecoder->close(); mDecoder->close();
@ -409,7 +409,7 @@ OpenAL_SoundStream::~OpenAL_SoundStream()
bool OpenAL_SoundStream::init(bool getLoudnessData) bool OpenAL_SoundStream::init(bool getLoudnessData)
{ {
alGenBuffers(sNumBuffers, mBuffers); alGenBuffers(mBuffers.size(), mBuffers.data());
ALenum err = getALError(); ALenum err = getALError();
if(err != AL_NO_ERROR) if(err != AL_NO_ERROR)
return false; return false;
@ -542,10 +542,10 @@ ALint OpenAL_SoundStream::refillQueue()
ALint queued; ALint queued;
alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued); alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
if(!mIsFinished && (ALuint)queued < sNumBuffers) if(!mIsFinished && (ALuint)queued < mBuffers.size())
{ {
std::vector<char> data(mBufferSize); std::vector<char> data(mBufferSize);
for(;!mIsFinished && (ALuint)queued < sNumBuffers;++queued) for(;!mIsFinished && (ALuint)queued < mBuffers.size();++queued)
{ {
size_t got = mDecoder->read(&data[0], data.size()); size_t got = mDecoder->read(&data[0], data.size());
if(got < data.size()) if(got < data.size())
@ -561,7 +561,7 @@ ALint OpenAL_SoundStream::refillQueue()
ALuint bufid = mBuffers[mCurrentBufIdx]; ALuint bufid = mBuffers[mCurrentBufIdx];
alBufferData(bufid, mFormat, &data[0], data.size(), mSampleRate); alBufferData(bufid, mFormat, &data[0], data.size(), mSampleRate);
alSourceQueueBuffers(mSource, 1, &bufid); alSourceQueueBuffers(mSource, 1, &bufid);
mCurrentBufIdx = (mCurrentBufIdx+1) % sNumBuffers; mCurrentBufIdx = (mCurrentBufIdx+1) % mBuffers.size();
} }
} }
} }

Loading…
Cancel
Save