Combine some duplicate code
This commit is contained in:
parent
7b2f194490
commit
051d6fb243
@ -452,11 +452,6 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL
|
|||||||
else if(source->SourceType == AL_STATIC) voice->mFlags |= VoiceIsStatic;
|
else if(source->SourceType == AL_STATIC) voice->mFlags |= VoiceIsStatic;
|
||||||
voice->mNumCallbackSamples = 0;
|
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())
|
if(voice->mChans.capacity() > 2 && num_channels < voice->mChans.capacity())
|
||||||
{
|
{
|
||||||
decltype(voice->mChans){}.swap(voice->mChans);
|
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->mChans.resize(num_channels);
|
||||||
voice->mVoiceSamples.reserve(maxu(2, num_channels));
|
voice->mVoiceSamples.reserve(maxu(2, num_channels));
|
||||||
voice->mVoiceSamples.resize(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
|
voice->prepare(device);
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
source->PropsClean.test_and_set(std::memory_order_acq_rel);
|
source->PropsClean.test_and_set(std::memory_order_acq_rel);
|
||||||
UpdateSourceProps(source, voice, context);
|
UpdateSourceProps(source, voice, context);
|
||||||
|
49
alc/alc.cpp
49
alc/alc.cpp
@ -2218,54 +2218,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
|
|||||||
if(voice->mSourceID.load(std::memory_order_relaxed) == 0u)
|
if(voice->mSourceID.load(std::memory_order_relaxed) == 0u)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
voice->mStep = 0;
|
voice->prepare(device);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
srclock.unlock();
|
srclock.unlock();
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "alstring.h"
|
#include "alstring.h"
|
||||||
#include "alu.h"
|
#include "alu.h"
|
||||||
#include "async_event.h"
|
#include "async_event.h"
|
||||||
|
#include "bformatdec.h"
|
||||||
#include "buffer_storage.h"
|
#include "buffer_storage.h"
|
||||||
#include "core/cpu_caps.h"
|
#include "core/cpu_caps.h"
|
||||||
#include "core/devformat.h"
|
#include "core/devformat.h"
|
||||||
@ -798,3 +799,51 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
|||||||
SendSourceStoppedEvent(Context, SourceID);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -238,6 +238,8 @@ struct Voice {
|
|||||||
|
|
||||||
void mix(const State vstate, ALCcontext *Context, const uint SamplesToDo);
|
void mix(const State vstate, ALCcontext *Context, const uint SamplesToDo);
|
||||||
|
|
||||||
|
void prepare(ALCdevice *device);
|
||||||
|
|
||||||
DEF_NEWDEL(Voice)
|
DEF_NEWDEL(Voice)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user