From f0cca53f6585191ec7de0f4b7d756a2e5c906a05 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 20 Oct 2017 17:27:04 -0700 Subject: [PATCH] Store the applied group properties in the source --- src/source.cpp | 47 +++++++++++++++++++---------------------------- src/source.h | 4 ++-- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/source.cpp b/src/source.cpp index 52da2dc..abceee1 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -181,6 +181,8 @@ void SourceImpl::resetProperties() if(mGroup) mGroup->removeSource(Source(this)); mGroup = nullptr; + mGroupPitch = 1.0f; + mGroupGain = 1.0f; mPaused.store(false, std::memory_order_release); mOffset = 0; @@ -233,16 +235,8 @@ void SourceImpl::applyProperties(bool looping, ALuint offset) const { alSourcei(mId, AL_LOOPING, looping ? AL_TRUE : AL_FALSE); alSourcei(mId, AL_SAMPLE_OFFSET, offset); - if(mGroup) - { - alSourcef(mId, AL_PITCH, mPitch * mGroup->getAppliedPitch()); - alSourcef(mId, AL_GAIN, mGain * mGroup->getAppliedGain()); - } - else - { - alSourcef(mId, AL_PITCH, mPitch); - alSourcef(mId, AL_GAIN, mGain); - } + alSourcef(mId, AL_PITCH, mPitch * mGroupPitch); + alSourcef(mId, AL_GAIN, mGain * mGroupGain); alSourcef(mId, AL_MIN_GAIN, mMinGain); alSourcef(mId, AL_MAX_GAIN, mMaxGain); alSourcef(mId, AL_REFERENCE_DISTANCE, mRefDist); @@ -289,29 +283,24 @@ void SourceImpl::setGroup(SourceGroupImpl *group) if(mGroup) mGroup->removeSource(Source(this)); mGroup = group; - groupUpdate(); + mGroupPitch = mGroup->getAppliedPitch(); + mGroupGain = mGroup->getAppliedGain(); + if(mId) + { + alSourcef(mId, AL_PITCH, mPitch * mGroupPitch); + alSourcef(mId, AL_GAIN, mGain * mGroupGain); + } } void SourceImpl::unsetGroup() { mGroup = nullptr; - groupUpdate(); -} - -void SourceImpl::groupUpdate() -{ + mGroupPitch = 1.0f; + mGroupGain = 1.0f; if(mId) { - if(mGroup) - { - alSourcef(mId, AL_PITCH, mPitch * mGroup->getAppliedPitch()); - alSourcef(mId, AL_GAIN, mGain * mGroup->getAppliedGain()); - } - else - { - alSourcef(mId, AL_PITCH, mPitch); - alSourcef(mId, AL_GAIN, mGain); - } + alSourcef(mId, AL_PITCH, mPitch * mGroupPitch); + alSourcef(mId, AL_GAIN, mGain * mGroupGain); } } @@ -322,6 +311,8 @@ void SourceImpl::groupPropUpdate(ALfloat gain, ALfloat pitch) alSourcef(mId, AL_PITCH, mPitch * pitch); alSourcef(mId, AL_GAIN, mGain * gain); } + mGroupPitch = pitch; + mGroupGain = gain; } @@ -784,7 +775,7 @@ void SourceImpl::setPitch(ALfloat pitch) throw std::runtime_error("Pitch out of range"); CheckContext(mContext); if(mId != 0) - alSourcef(mId, AL_PITCH, pitch * (mGroup ? mGroup->getAppliedPitch() : 1.0f)); + alSourcef(mId, AL_PITCH, pitch * mGroupPitch); mPitch = pitch; } @@ -795,7 +786,7 @@ void SourceImpl::setGain(ALfloat gain) throw std::runtime_error("Gain out of range"); CheckContext(mContext); if(mId != 0) - alSourcef(mId, AL_GAIN, gain * (mGroup ? mGroup->getAppliedGain() : 1.0f)); + alSourcef(mId, AL_GAIN, gain * mGroupGain); mGain = gain; } diff --git a/src/source.h b/src/source.h index ac4fd09..8a2a72f 100644 --- a/src/source.h +++ b/src/source.h @@ -35,6 +35,8 @@ class SourceImpl { UniquePtr mStream; SourceGroupImpl *mGroup; + ALfloat mGroupPitch; + ALfloat mGroupGain; mutable std::mutex mMutex; std::atomic mIsAsync; @@ -88,8 +90,6 @@ public: void setGroup(SourceGroupImpl *group); void unsetGroup(); - - void groupUpdate(); void groupPropUpdate(ALfloat gain, ALfloat pitch); void checkPaused(); -- 2.11.4.GIT