diff options
-rw-r--r-- | al/source.cpp | 43 | ||||
-rw-r--r-- | alc/alc.cpp | 49 | ||||
-rw-r--r-- | alc/voice.cpp | 49 | ||||
-rw-r--r-- | alc/voice.h | 2 |
4 files changed, 53 insertions, 90 deletions
diff --git a/al/source.cpp b/al/source.cpp index 5b95e9ed..b2bb0d75 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -452,11 +452,6 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL else if(source->SourceType == AL_STATIC) voice->mFlags |= VoiceIsStatic; voice->mNumCallbackSamples = 0; - /* Clear the stepping value explicitly so the mixer knows not to mix this - * until the update gets applied. - */ - voice->mStep = 0; - if(voice->mChans.capacity() > 2 && num_channels < voice->mChans.capacity()) { decltype(voice->mChans){}.swap(voice->mChans); @@ -466,44 +461,8 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL voice->mChans.resize(num_channels); voice->mVoiceSamples.reserve(maxu(2, num_channels)); voice->mVoiceSamples.resize(num_channels); - std::fill_n(voice->mVoiceSamples.begin(), num_channels, Voice::BufferLine{}); - - /* Don't need to set the VOICE_IS_AMBISONIC flag if the device is not - * higher order than the voice. No HF scaling is necessary to mix it. - */ - if(voice->mAmbiOrder && device->mAmbiOrder > voice->mAmbiOrder) - { - const uint8_t *OrderFromChan{(voice->mFmtChannels == FmtBFormat2D) ? - AmbiIndex::OrderFrom2DChannel().data() : AmbiIndex::OrderFromChannel().data()}; - const auto scales = BFormatDec::GetHFOrderScales(voice->mAmbiOrder, device->mAmbiOrder); - const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)}; - for(auto &chandata : voice->mChans) - { - chandata.mAmbiScale = scales[*(OrderFromChan++)]; - chandata.mAmbiSplitter = splitter; - chandata.mDryParams = DirectParams{}; - std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{}); - } - - voice->mFlags |= VoiceIsAmbisonic; - } - else - { - for(auto &chandata : voice->mChans) - { - chandata.mDryParams = DirectParams{}; - std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{}); - } - } - - if(device->AvgSpeakerDist > 0.0f) - { - const float w1{SpeedOfSoundMetersPerSec / - (device->AvgSpeakerDist * static_cast<float>(device->Frequency))}; - for(auto &chandata : voice->mChans) - chandata.mDryParams.NFCtrlFilter.init(w1); - } + voice->prepare(device); source->PropsClean.test_and_set(std::memory_order_acq_rel); UpdateSourceProps(source, voice, context); diff --git a/alc/alc.cpp b/alc/alc.cpp index 2de0b47e..d5963d24 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2218,54 +2218,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) if(voice->mSourceID.load(std::memory_order_relaxed) == 0u) continue; - voice->mStep = 0; - voice->mFlags |= VoiceIsFading; - - /* Clear previous samples. */ - std::fill(voice->mVoiceSamples.begin(), voice->mVoiceSamples.end(), - Voice::BufferLine{}); - - if(voice->mAmbiOrder && device->mAmbiOrder > voice->mAmbiOrder) - { - const uint8_t *OrderFromChan{(voice->mFmtChannels == FmtBFormat2D) ? - AmbiIndex::OrderFrom2DChannel().data() : - AmbiIndex::OrderFromChannel().data()}; - - const BandSplitter splitter{device->mXOverFreq / - static_cast<float>(device->Frequency)}; - - const auto scales = BFormatDec::GetHFOrderScales(voice->mAmbiOrder, - device->mAmbiOrder); - for(auto &chandata : voice->mChans) - { - chandata.mAmbiScale = scales[*(OrderFromChan++)]; - chandata.mAmbiSplitter = splitter; - chandata.mDryParams = DirectParams{}; - std::fill_n(chandata.mWetParams.begin(), num_sends, SendParams{}); - } - - voice->mFlags |= VoiceIsAmbisonic; - } - else - { - /* Clear previous params. */ - for(auto &chandata : voice->mChans) - { - chandata.mDryParams = DirectParams{}; - std::fill_n(chandata.mWetParams.begin(), num_sends, SendParams{}); - } - - voice->mFlags &= ~VoiceIsAmbisonic; - } - - if(device->AvgSpeakerDist > 0.0f) - { - /* Reinitialize the NFC filters for new parameters. */ - const float w1{SpeedOfSoundMetersPerSec / - (device->AvgSpeakerDist * static_cast<float>(device->Frequency))}; - for(auto &chandata : voice->mChans) - chandata.mDryParams.NFCtrlFilter.init(w1); - } + voice->prepare(device); } srclock.unlock(); diff --git a/alc/voice.cpp b/alc/voice.cpp index 8b61316f..f9eca51c 100644 --- a/alc/voice.cpp +++ b/alc/voice.cpp @@ -44,6 +44,7 @@ #include "alstring.h" #include "alu.h" #include "async_event.h" +#include "bformatdec.h" #include "buffer_storage.h" #include "core/cpu_caps.h" #include "core/devformat.h" @@ -798,3 +799,51 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo) SendSourceStoppedEvent(Context, SourceID); } } + +void Voice::prepare(ALCdevice *device) +{ + /* Clear the stepping value explicitly so the mixer knows not to mix this + * until the update gets applied. + */ + mStep = 0; + + /* Make sure the sample history is cleared. */ + std::fill(mVoiceSamples.begin(), mVoiceSamples.end(), BufferLine{}); + + /* Don't need to set the VoiceIsAmbisonic flag if the device is not higher + * order than the voice. No HF scaling is necessary to mix it. + */ + if(mAmbiOrder && device->mAmbiOrder > mAmbiOrder) + { + const uint8_t *OrderFromChan{(mFmtChannels == FmtBFormat2D) ? + AmbiIndex::OrderFrom2DChannel().data() : AmbiIndex::OrderFromChannel().data()}; + const auto scales = BFormatDec::GetHFOrderScales(mAmbiOrder, device->mAmbiOrder); + + const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)}; + for(auto &chandata : mChans) + { + chandata.mAmbiScale = scales[*(OrderFromChan++)]; + chandata.mAmbiSplitter = splitter; + chandata.mDryParams = DirectParams{}; + std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{}); + } + mFlags |= VoiceIsAmbisonic; + } + else + { + for(auto &chandata : mChans) + { + chandata.mDryParams = DirectParams{}; + std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{}); + } + mFlags &= ~VoiceIsAmbisonic; + } + + if(device->AvgSpeakerDist > 0.0f) + { + const float w1{SpeedOfSoundMetersPerSec / + (device->AvgSpeakerDist * static_cast<float>(device->Frequency))}; + for(auto &chandata : mChans) + chandata.mDryParams.NFCtrlFilter.init(w1); + } +} diff --git a/alc/voice.h b/alc/voice.h index 5921635c..96975efa 100644 --- a/alc/voice.h +++ b/alc/voice.h @@ -238,6 +238,8 @@ struct Voice { void mix(const State vstate, ALCcontext *Context, const uint SamplesToDo); + void prepare(ALCdevice *device); + DEF_NEWDEL(Voice) }; |