2 * OpenAL cross platform audio library
3 * Copyright (C) 2011 by Chris Robinson.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
28 #include "alc/effects/base.h"
31 #include "core/bufferline.h"
32 #include "core/devformat.h"
33 #include "core/device.h"
34 #include "core/effectslot.h"
35 #include "core/mixer.h"
36 #include "intrusive_ptr.h"
43 using uint = unsigned int;
45 struct DedicatedState final : public EffectState {
46 /* The "dedicated" effect can output to the real output, so should have
47 * gains for all possible output channels and not just the main ambisonic
50 float mCurrentGains[MAX_OUTPUT_CHANNELS];
51 float mTargetGains[MAX_OUTPUT_CHANNELS];
54 void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override;
55 void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props,
56 const EffectTarget target) override;
57 void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
58 const al::span<FloatBufferLine> samplesOut) override;
60 DEF_NEWDEL(DedicatedState)
63 void DedicatedState::deviceUpdate(const DeviceBase*, const BufferStorage*)
65 std::fill(std::begin(mCurrentGains), std::end(mCurrentGains), 0.0f);
68 void DedicatedState::update(const ContextBase*, const EffectSlot *slot,
69 const EffectProps *props, const EffectTarget target)
71 std::fill(std::begin(mTargetGains), std::end(mTargetGains), 0.0f);
73 const float Gain{slot->Gain * props->Dedicated.Gain};
75 if(slot->EffectType == EffectSlotType::DedicatedLFE)
77 const uint idx{target.RealOut ? target.RealOut->ChannelIndex[LFE] : InvalidChannelIndex};
78 if(idx != InvalidChannelIndex)
80 mOutTarget = target.RealOut->Buffer;
81 mTargetGains[idx] = Gain;
84 else if(slot->EffectType == EffectSlotType::DedicatedDialog)
86 /* Dialog goes to the front-center speaker if it exists, otherwise it
87 * plays from the front-center location. */
88 const uint idx{target.RealOut ? target.RealOut->ChannelIndex[FrontCenter]
89 : InvalidChannelIndex};
90 if(idx != InvalidChannelIndex)
92 mOutTarget = target.RealOut->Buffer;
93 mTargetGains[idx] = Gain;
97 static constexpr auto coeffs = CalcDirectionCoeffs({0.0f, 0.0f, -1.0f});
99 mOutTarget = target.Main->Buffer;
100 ComputePanGains(target.Main, coeffs.data(), Gain, mTargetGains);
105 void DedicatedState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
107 MixSamples({samplesIn[0].data(), samplesToDo}, samplesOut, mCurrentGains, mTargetGains,
112 struct DedicatedStateFactory final : public EffectStateFactory {
113 al::intrusive_ptr<EffectState> create() override
114 { return al::intrusive_ptr<EffectState>{new DedicatedState{}}; }
119 EffectStateFactory *DedicatedStateFactory_getFactory()
121 static DedicatedStateFactory DedicatedFactory{};
122 return &DedicatedFactory;