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
27 #include "alAuxEffectSlot.h"
32 typedef struct ALdedicatedState
{
33 DERIVE_FROM_TYPE(ALeffectState
);
35 ALfloat gains
[MAX_OUTPUT_CHANNELS
];
39 static ALvoid
ALdedicatedState_Destruct(ALdedicatedState
*UNUSED(state
))
43 static ALboolean
ALdedicatedState_deviceUpdate(ALdedicatedState
*UNUSED(state
), ALCdevice
*UNUSED(device
))
48 static ALvoid
ALdedicatedState_update(ALdedicatedState
*state
, ALCdevice
*device
, const ALeffectslot
*Slot
)
53 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
54 state
->gains
[i
] = 0.0f
;
56 Gain
= Slot
->Gain
* Slot
->EffectProps
.Dedicated
.Gain
;
57 if(Slot
->EffectType
== AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT
)
60 if((idx
=GetChannelIdxByName(device
, LFE
)) != -1)
61 state
->gains
[idx
] = Gain
;
63 else if(Slot
->EffectType
== AL_EFFECT_DEDICATED_DIALOGUE
)
66 /* Dialog goes to the front-center speaker if it exists, otherwise it
67 * plays from the front-center location. */
68 if((idx
=GetChannelIdxByName(device
, FrontCenter
)) != -1)
69 state
->gains
[idx
] = Gain
;
72 static const ALfloat front_dir
[3] = { 0.0f
, 0.0f
, -1.0f
};
73 ComputeDirectionalGains(device
, front_dir
, Gain
, state
->gains
);
78 static ALvoid
ALdedicatedState_process(ALdedicatedState
*state
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
80 const ALfloat
*gains
= state
->gains
;
83 for(c
= 0;c
< NumChannels
;c
++)
85 if(!(fabsf(gains
[c
]) > GAIN_SILENCE_THRESHOLD
))
88 for(i
= 0;i
< SamplesToDo
;i
++)
89 SamplesOut
[c
][i
] = SamplesIn
[i
] * gains
[c
];
93 DECLARE_DEFAULT_ALLOCATORS(ALdedicatedState
)
95 DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState
);
98 typedef struct ALdedicatedStateFactory
{
99 DERIVE_FROM_TYPE(ALeffectStateFactory
);
100 } ALdedicatedStateFactory
;
102 ALeffectState
*ALdedicatedStateFactory_create(ALdedicatedStateFactory
*UNUSED(factory
))
104 ALdedicatedState
*state
;
107 state
= ALdedicatedState_New(sizeof(*state
));
108 if(!state
) return NULL
;
109 SET_VTABLE2(ALdedicatedState
, ALeffectState
, state
);
111 for(s
= 0;s
< MAX_OUTPUT_CHANNELS
;s
++)
112 state
->gains
[s
] = 0.0f
;
114 return STATIC_CAST(ALeffectState
, state
);
117 DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdedicatedStateFactory
);
120 ALeffectStateFactory
*ALdedicatedStateFactory_getFactory(void)
122 static ALdedicatedStateFactory DedicatedFactory
= { { GET_VTABLE2(ALdedicatedStateFactory
, ALeffectStateFactory
) } };
124 return STATIC_CAST(ALeffectStateFactory
, &DedicatedFactory
);
128 void ALdedicated_setParami(ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum
UNUSED(param
), ALint
UNUSED(val
))
129 { SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
); }
130 void ALdedicated_setParamiv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
132 ALdedicated_setParami(effect
, context
, param
, vals
[0]);
134 void ALdedicated_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
136 ALeffectProps
*props
= &effect
->Props
;
139 case AL_DEDICATED_GAIN
:
140 if(!(val
>= 0.0f
&& isfinite(val
)))
141 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
142 props
->Dedicated
.Gain
= val
;
146 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
149 void ALdedicated_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
151 ALdedicated_setParamf(effect
, context
, param
, vals
[0]);
154 void ALdedicated_getParami(const ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum
UNUSED(param
), ALint
*UNUSED(val
))
155 { SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
); }
156 void ALdedicated_getParamiv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
158 ALdedicated_getParami(effect
, context
, param
, vals
);
160 void ALdedicated_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
162 const ALeffectProps
*props
= &effect
->Props
;
165 case AL_DEDICATED_GAIN
:
166 *val
= props
->Dedicated
.Gain
;
170 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
173 void ALdedicated_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
175 ALdedicated_getParamf(effect
, context
, param
, vals
);
178 DEFINE_ALEFFECT_VTABLE(ALdedicated
);