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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "alFilter.h"
|
|
|
|
#include "alAuxEffectSlot.h"
|
|
|
|
#include "alError.h"
|
|
|
|
#include "alu.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct ALdedicatedState {
|
2013-05-20 01:32:02 -07:00
|
|
|
DERIVE_FROM_TYPE(ALeffectState);
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2012-06-28 18:49:49 -07:00
|
|
|
ALfloat gains[MaxChannels];
|
2011-03-12 20:11:25 -08:00
|
|
|
} ALdedicatedState;
|
|
|
|
|
|
|
|
|
|
|
|
static ALvoid DedicatedDestroy(ALeffectState *effect)
|
|
|
|
{
|
2013-05-20 01:32:02 -07:00
|
|
|
ALdedicatedState *state = GET_PARENT_TYPE(ALdedicatedState, ALeffectState, effect);
|
2011-03-12 20:11:25 -08:00
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
|
|
|
|
{
|
|
|
|
(void)effect;
|
|
|
|
(void)Device;
|
|
|
|
return AL_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:49:58 -07:00
|
|
|
static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const ALeffectslot *Slot)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2013-05-20 01:32:02 -07:00
|
|
|
ALdedicatedState *state = GET_PARENT_TYPE(ALdedicatedState, ALeffectState, effect);
|
2011-07-16 03:35:51 -07:00
|
|
|
ALfloat Gain;
|
2011-03-12 20:11:25 -08:00
|
|
|
ALsizei s;
|
|
|
|
|
2011-09-11 07:42:23 -07:00
|
|
|
Gain = Slot->Gain * Slot->effect.Dedicated.Gain;
|
2012-06-28 18:49:49 -07:00
|
|
|
for(s = 0;s < MaxChannels;s++)
|
2011-09-01 18:01:14 -07:00
|
|
|
state->gains[s] = 0.0f;
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2011-09-01 18:01:14 -07:00
|
|
|
if(Slot->effect.type == AL_EFFECT_DEDICATED_DIALOGUE)
|
2012-06-29 02:12:36 -07:00
|
|
|
ComputeAngleGains(device, atan2f(0.0f, 1.0f), 0.0f, Gain, state->gains);
|
2011-09-01 18:01:14 -07:00
|
|
|
else if(Slot->effect.type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
|
|
|
|
state->gains[LFE] = Gain;
|
2011-03-12 20:11:25 -08:00
|
|
|
}
|
|
|
|
|
2012-10-14 10:16:46 -07:00
|
|
|
static ALvoid DedicatedProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE])
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2013-05-20 01:32:02 -07:00
|
|
|
ALdedicatedState *state = GET_PARENT_TYPE(ALdedicatedState, ALeffectState, effect);
|
2011-03-12 20:11:25 -08:00
|
|
|
const ALfloat *gains = state->gains;
|
2012-09-11 06:32:42 -07:00
|
|
|
ALuint i, c;
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2012-09-11 06:32:42 -07:00
|
|
|
for(c = 0;c < MaxChannels;c++)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
for(i = 0;i < SamplesToDo;i++)
|
|
|
|
SamplesOut[c][i] = SamplesIn[i] * gains[c];
|
2011-03-12 20:11:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-01 18:01:14 -07:00
|
|
|
ALeffectState *DedicatedCreate(void)
|
2011-03-12 20:11:25 -08:00
|
|
|
{
|
|
|
|
ALdedicatedState *state;
|
|
|
|
ALsizei s;
|
|
|
|
|
|
|
|
state = malloc(sizeof(*state));
|
|
|
|
if(!state)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-20 01:32:02 -07:00
|
|
|
GET_DERIVED_TYPE(ALeffectState, state)->Destroy = DedicatedDestroy;
|
|
|
|
GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = DedicatedDeviceUpdate;
|
|
|
|
GET_DERIVED_TYPE(ALeffectState, state)->Update = DedicatedUpdate;
|
|
|
|
GET_DERIVED_TYPE(ALeffectState, state)->Process = DedicatedProcess;
|
2011-03-12 20:11:25 -08:00
|
|
|
|
2012-06-28 18:49:49 -07:00
|
|
|
for(s = 0;s < MaxChannels;s++)
|
2011-03-12 20:11:25 -08:00
|
|
|
state->gains[s] = 0.0f;
|
|
|
|
|
2013-05-20 01:32:02 -07:00
|
|
|
return GET_DERIVED_TYPE(ALeffectState, state);
|
2011-03-12 20:11:25 -08:00
|
|
|
}
|
2013-03-13 21:53:42 -07:00
|
|
|
|
|
|
|
void ded_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
|
|
|
|
{ (void)effect;(void)param;(void)val; alSetError(context, AL_INVALID_ENUM); }
|
|
|
|
void ded_SetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
|
|
|
|
{
|
|
|
|
ded_SetParami(effect, context, param, vals[0]);
|
|
|
|
}
|
|
|
|
void ded_SetParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
|
|
|
|
{
|
|
|
|
switch(param)
|
|
|
|
{
|
|
|
|
case AL_DEDICATED_GAIN:
|
|
|
|
if(val >= 0.0f && isfinite(val))
|
|
|
|
effect->Dedicated.Gain = val;
|
|
|
|
else
|
|
|
|
alSetError(context, AL_INVALID_VALUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
alSetError(context, AL_INVALID_ENUM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ded_SetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
|
|
|
|
{
|
|
|
|
ded_SetParamf(effect, context, param, vals[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ded_GetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
|
|
|
|
{ (void)effect;(void)param;(void)val; alSetError(context, AL_INVALID_ENUM); }
|
|
|
|
void ded_GetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
|
|
|
|
{
|
|
|
|
ded_GetParami(effect, context, param, vals);
|
|
|
|
}
|
|
|
|
void ded_GetParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
|
|
|
|
{
|
|
|
|
switch(param)
|
|
|
|
{
|
|
|
|
case AL_DEDICATED_GAIN:
|
|
|
|
*val = effect->Dedicated.Gain;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
alSetError(context, AL_INVALID_ENUM);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ded_GetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
|
|
|
|
{
|
|
|
|
ded_GetParamf(effect, context, param, vals);
|
|
|
|
}
|