2011-03-12 20:11:25 -08:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 2011 by Chris Robinson.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2014-08-18 14:11:03 +02:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-03-12 20:11:25 -08:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-01-09 19:42:40 +01:00
|
|
|
#include <cstdlib>
|
2018-11-19 09:51:29 -08:00
|
|
|
#include <cmath>
|
2018-11-19 19:57:30 -08:00
|
|
|
#include <algorithm>
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2019-07-29 17:54:07 -07:00
|
|
|
#include "al/auxeffectslot.h"
|
2019-07-28 18:33:29 -07:00
|
|
|
#include "alcmain.h"
|
2018-11-17 23:02:27 -08:00
|
|
|
#include "alcontext.h"
|
2011-03-12 20:11:25 -08:00
|
|
|
#include "alu.h"
|
|
|
|
|
|
|
|
|
2019-03-22 12:58:24 -07:00
|
|
|
namespace {
|
|
|
|
|
2019-03-22 13:33:58 -07:00
|
|
|
struct DedicatedState final : public EffectState {
|
2018-11-19 19:57:30 -08:00
|
|
|
ALfloat mCurrentGains[MAX_OUTPUT_CHANNELS];
|
|
|
|
ALfloat mTargetGains[MAX_OUTPUT_CHANNELS];
|
2016-08-25 03:42:43 -07:00
|
|
|
|
|
|
|
|
2018-12-22 18:43:34 -08:00
|
|
|
ALboolean deviceUpdate(const ALCdevice *device) override;
|
2019-03-22 22:48:12 -07:00
|
|
|
void update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) override;
|
2019-05-29 22:31:36 -07:00
|
|
|
void process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei numInput, const al::span<FloatBufferLine> samplesOut) override;
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2019-03-22 13:33:58 -07:00
|
|
|
DEF_NEWDEL(DedicatedState)
|
2018-11-19 22:34:26 -08:00
|
|
|
};
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2019-07-28 17:15:34 -07:00
|
|
|
ALboolean DedicatedState::deviceUpdate(const ALCdevice*)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2018-11-19 22:34:26 -08:00
|
|
|
std::fill(std::begin(mCurrentGains), std::end(mCurrentGains), 0.0f);
|
2011-03-12 20:11:25 -08:00
|
|
|
return AL_TRUE;
|
|
|
|
}
|
|
|
|
|
2019-07-28 17:15:34 -07:00
|
|
|
void DedicatedState::update(const ALCcontext*, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2018-11-19 22:34:26 -08:00
|
|
|
std::fill(std::begin(mTargetGains), std::end(mTargetGains), 0.0f);
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2018-12-23 08:51:28 -08:00
|
|
|
const ALfloat Gain{slot->Params.Gain * props->Dedicated.Gain};
|
|
|
|
|
2017-09-21 05:42:35 -07:00
|
|
|
if(slot->Params.EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
|
2014-10-02 21:19:34 -07:00
|
|
|
{
|
2018-12-24 13:29:36 -08:00
|
|
|
const int idx{!target.RealOut ? -1 : GetChannelIdxByName(*target.RealOut, LFE)};
|
|
|
|
if(idx != -1)
|
2016-03-25 14:47:30 -07:00
|
|
|
{
|
2019-07-03 23:26:33 -07:00
|
|
|
mOutTarget = target.RealOut->Buffer;
|
2018-11-19 22:34:26 -08:00
|
|
|
mTargetGains[idx] = Gain;
|
2016-03-25 14:47:30 -07:00
|
|
|
}
|
2014-10-02 21:19:34 -07:00
|
|
|
}
|
2017-09-21 05:42:35 -07:00
|
|
|
else if(slot->Params.EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
|
2014-10-02 18:05:42 -07:00
|
|
|
{
|
|
|
|
/* Dialog goes to the front-center speaker if it exists, otherwise it
|
|
|
|
* plays from the front-center location. */
|
2018-12-24 13:29:36 -08:00
|
|
|
const int idx{!target.RealOut ? -1 : GetChannelIdxByName(*target.RealOut, FrontCenter)};
|
2018-11-19 19:57:30 -08:00
|
|
|
if(idx != -1)
|
2016-03-25 14:47:30 -07:00
|
|
|
{
|
2019-07-03 23:26:33 -07:00
|
|
|
mOutTarget = target.RealOut->Buffer;
|
2018-11-19 22:34:26 -08:00
|
|
|
mTargetGains[idx] = Gain;
|
2016-03-25 14:47:30 -07:00
|
|
|
}
|
2014-10-02 21:19:34 -07:00
|
|
|
else
|
2014-10-02 18:05:42 -07:00
|
|
|
{
|
2019-02-19 15:39:33 -08:00
|
|
|
ALfloat coeffs[MAX_AMBI_CHANNELS];
|
2019-05-20 21:16:13 -07:00
|
|
|
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
|
2016-04-16 14:11:10 -07:00
|
|
|
|
2019-07-04 15:02:12 -07:00
|
|
|
mOutTarget = target.Main->Buffer;
|
2018-12-24 13:29:36 -08:00
|
|
|
ComputePanGains(target.Main, coeffs, Gain, mTargetGains);
|
2014-10-02 18:05:42 -07:00
|
|
|
}
|
2013-10-03 05:02:16 -07:00
|
|
|
}
|
2011-03-12 20:11:25 -08:00
|
|
|
}
|
|
|
|
|
2019-05-29 22:31:36 -07:00
|
|
|
void DedicatedState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei /*numInput*/, const al::span<FloatBufferLine> samplesOut)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2019-05-29 22:31:36 -07:00
|
|
|
MixSamples(samplesIn[0].data(), samplesOut, mCurrentGains, mTargetGains, samplesToDo, 0,
|
|
|
|
samplesToDo);
|
2011-03-12 20:11:25 -08:00
|
|
|
}
|
|
|
|
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_setParami(EffectProps*, ALCcontext *context, ALenum param, ALint)
|
2019-07-30 21:32:05 -07:00
|
|
|
{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); }
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*)
|
2019-07-30 21:32:05 -07:00
|
|
|
{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); }
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALfloat val)
|
2013-03-13 21:53:42 -07:00
|
|
|
{
|
|
|
|
switch(param)
|
|
|
|
{
|
|
|
|
case AL_DEDICATED_GAIN:
|
2018-11-19 09:51:29 -08:00
|
|
|
if(!(val >= 0.0f && std::isfinite(val)))
|
2018-01-25 15:59:59 -08:00
|
|
|
SETERR_RETURN(context, AL_INVALID_VALUE,, "Dedicated gain out of range");
|
2013-05-26 00:01:07 -07:00
|
|
|
props->Dedicated.Gain = val;
|
2013-03-13 21:53:42 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param);
|
2013-03-13 21:53:42 -07:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals)
|
2019-03-22 16:04:13 -07:00
|
|
|
{ Dedicated_setParamf(props, context, param, vals[0]); }
|
2013-03-13 21:53:42 -07:00
|
|
|
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_getParami(const EffectProps*, ALCcontext *context, ALenum param, ALint*)
|
2019-07-30 21:32:05 -07:00
|
|
|
{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); }
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*)
|
2019-07-30 21:32:05 -07:00
|
|
|
{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); }
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val)
|
2013-03-13 21:53:42 -07:00
|
|
|
{
|
|
|
|
switch(param)
|
|
|
|
{
|
|
|
|
case AL_DEDICATED_GAIN:
|
2013-05-25 22:07:31 -07:00
|
|
|
*val = props->Dedicated.Gain;
|
2013-03-13 21:53:42 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param);
|
2013-03-13 21:53:42 -07:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 22:48:12 -07:00
|
|
|
void Dedicated_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals)
|
2019-03-22 16:04:13 -07:00
|
|
|
{ Dedicated_getParamf(props, context, param, vals); }
|
2013-05-24 23:26:59 -07:00
|
|
|
|
2019-03-22 13:33:58 -07:00
|
|
|
DEFINE_ALEFFECT_VTABLE(Dedicated);
|
|
|
|
|
|
|
|
|
|
|
|
struct DedicatedStateFactory final : public EffectStateFactory {
|
|
|
|
EffectState *create() override { return new DedicatedState{}; }
|
2019-03-22 22:48:12 -07:00
|
|
|
EffectProps getDefaultProps() const noexcept override;
|
2019-03-22 13:33:58 -07:00
|
|
|
const EffectVtable *getEffectVtable() const noexcept override { return &Dedicated_vtable; }
|
|
|
|
};
|
|
|
|
|
2019-03-22 22:48:12 -07:00
|
|
|
EffectProps DedicatedStateFactory::getDefaultProps() const noexcept
|
2019-03-22 13:33:58 -07:00
|
|
|
{
|
2019-03-22 22:48:12 -07:00
|
|
|
EffectProps props{};
|
2019-03-22 13:33:58 -07:00
|
|
|
props.Dedicated.Gain = 1.0f;
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
EffectStateFactory *DedicatedStateFactory_getFactory()
|
|
|
|
{
|
|
|
|
static DedicatedStateFactory DedicatedFactory{};
|
|
|
|
return &DedicatedFactory;
|
|
|
|
}
|