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
|
|
|
|
|
|
|
#include "alMain.h"
|
2018-11-17 23:02:27 -08:00
|
|
|
#include "alcontext.h"
|
2011-03-12 20:11:25 -08:00
|
|
|
#include "alAuxEffectSlot.h"
|
|
|
|
#include "alError.h"
|
|
|
|
#include "alu.h"
|
|
|
|
|
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
struct ALdedicatedState 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;
|
2018-12-24 13:29:36 -08:00
|
|
|
void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props, const EffectTarget target) override;
|
2019-02-21 02:57:39 -08:00
|
|
|
void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) override;
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
DEF_NEWDEL(ALdedicatedState)
|
|
|
|
};
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2018-12-22 18:43:34 -08:00
|
|
|
ALboolean ALdedicatedState::deviceUpdate(const ALCdevice *UNUSED(device))
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-24 13:29:36 -08:00
|
|
|
void ALdedicatedState::update(const ALCcontext* UNUSED(context), const ALeffectslot *slot, const ALeffectProps *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
|
|
|
{
|
2018-12-24 13:29:36 -08:00
|
|
|
mOutBuffer = target.RealOut->Buffer;
|
|
|
|
mOutChannels = target.RealOut->NumChannels;
|
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
|
|
|
{
|
2018-12-24 13:29:36 -08:00
|
|
|
mOutBuffer = target.RealOut->Buffer;
|
|
|
|
mOutChannels = target.RealOut->NumChannels;
|
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];
|
2017-02-23 16:44:59 -08:00
|
|
|
CalcAngleCoeffs(0.0f, 0.0f, 0.0f, coeffs);
|
2016-04-16 14:11:10 -07:00
|
|
|
|
2018-12-24 13:29:36 -08:00
|
|
|
mOutBuffer = target.Main->Buffer;
|
|
|
|
mOutChannels = target.Main->NumChannels;
|
|
|
|
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-02-21 02:57:39 -08:00
|
|
|
void ALdedicatedState::process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei /*numInput*/, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2019-02-21 02:57:39 -08:00
|
|
|
MixSamples(samplesIn[0], numOutput, samplesOut, mCurrentGains, mTargetGains, samplesToDo, 0,
|
|
|
|
samplesToDo);
|
2011-03-12 20:11:25 -08:00
|
|
|
}
|
|
|
|
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2018-11-17 06:53:20 -08:00
|
|
|
struct DedicatedStateFactory final : public EffectStateFactory {
|
2018-11-19 22:34:26 -08:00
|
|
|
EffectState *create() override;
|
2018-11-17 06:53:20 -08:00
|
|
|
};
|
2013-10-07 14:49:36 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
EffectState *DedicatedStateFactory::create()
|
|
|
|
{ return new ALdedicatedState{}; }
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2019-01-09 19:43:54 +01:00
|
|
|
EffectStateFactory *DedicatedStateFactory_getFactory()
|
2013-05-21 12:47:18 -07:00
|
|
|
{
|
2018-11-17 06:53:20 -08:00
|
|
|
static DedicatedStateFactory DedicatedFactory{};
|
2018-11-19 06:43:37 -08:00
|
|
|
return &DedicatedFactory;
|
2013-05-21 12:47:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-25 15:59:59 -08:00
|
|
|
void ALdedicated_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
|
|
|
|
{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); }
|
|
|
|
void ALdedicated_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
|
|
|
|
{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); }
|
2013-05-29 11:17:45 -07:00
|
|
|
void ALdedicated_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
|
2013-03-13 21:53:42 -07:00
|
|
|
{
|
2013-05-25 22:07:31 -07:00
|
|
|
ALeffectProps *props = &effect->Props;
|
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:
|
2018-01-25 15:59:59 -08:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param);
|
2013-03-13 21:53:42 -07:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 11:17:45 -07:00
|
|
|
void ALdedicated_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
|
2018-01-24 17:07:01 -08:00
|
|
|
{ ALdedicated_setParamf(effect, context, param, vals[0]); }
|
2013-03-13 21:53:42 -07:00
|
|
|
|
2018-01-25 15:59:59 -08:00
|
|
|
void ALdedicated_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(val))
|
|
|
|
{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); }
|
|
|
|
void ALdedicated_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
|
|
|
|
{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); }
|
2013-10-07 12:56:41 -07:00
|
|
|
void ALdedicated_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
|
2013-03-13 21:53:42 -07:00
|
|
|
{
|
2013-05-25 22:07:31 -07:00
|
|
|
const ALeffectProps *props = &effect->Props;
|
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:
|
2018-01-25 15:59:59 -08:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param);
|
2013-03-13 21:53:42 -07:00
|
|
|
}
|
|
|
|
}
|
2013-10-07 12:56:41 -07:00
|
|
|
void ALdedicated_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
|
2018-01-24 17:07:01 -08:00
|
|
|
{ ALdedicated_getParamf(effect, context, param, vals); }
|
2013-05-24 23:26:59 -07:00
|
|
|
|
|
|
|
DEFINE_ALEFFECT_VTABLE(ALdedicated);
|