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
*state
)
41 ALeffectState_Destruct(STATIC_CAST(ALeffectState
,state
));
44 static ALboolean
ALdedicatedState_deviceUpdate(ALdedicatedState
*UNUSED(state
), ALCdevice
*UNUSED(device
))
49 static ALvoid
ALdedicatedState_update(ALdedicatedState
*state
, const ALCdevice
*device
, const ALeffectslot
*Slot
, const ALeffectProps
*props
)
54 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
55 state
->gains
[i
] = 0.0f
;
57 Gain
= Slot
->Params
.Gain
* props
->Dedicated
.Gain
;
58 if(Slot
->Params
.EffectType
== AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT
)
61 if((idx
=GetChannelIdxByName(device
->RealOut
, LFE
)) != -1)
63 STATIC_CAST(ALeffectState
,state
)->OutBuffer
= device
->RealOut
.Buffer
;
64 STATIC_CAST(ALeffectState
,state
)->OutChannels
= device
->RealOut
.NumChannels
;
65 state
->gains
[idx
] = Gain
;
68 else if(Slot
->Params
.EffectType
== AL_EFFECT_DEDICATED_DIALOGUE
)
71 /* Dialog goes to the front-center speaker if it exists, otherwise it
72 * plays from the front-center location. */
73 if((idx
=GetChannelIdxByName(device
->RealOut
, FrontCenter
)) != -1)
75 STATIC_CAST(ALeffectState
,state
)->OutBuffer
= device
->RealOut
.Buffer
;
76 STATIC_CAST(ALeffectState
,state
)->OutChannels
= device
->RealOut
.NumChannels
;
77 state
->gains
[idx
] = Gain
;
81 ALfloat coeffs
[MAX_AMBI_COEFFS
];
82 CalcXYZCoeffs(0.0f
, 0.0f
, -1.0f
, 0.0f
, coeffs
);
84 STATIC_CAST(ALeffectState
,state
)->OutBuffer
= device
->Dry
.Buffer
;
85 STATIC_CAST(ALeffectState
,state
)->OutChannels
= device
->Dry
.NumChannels
;
86 ComputePanningGains(device
->Dry
, coeffs
, Gain
, state
->gains
);
91 static ALvoid
ALdedicatedState_process(ALdedicatedState
*state
, ALuint SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
93 const ALfloat
*gains
= state
->gains
;
96 for(c
= 0;c
< NumChannels
;c
++)
98 if(!(fabsf(gains
[c
]) > GAIN_SILENCE_THRESHOLD
))
101 for(i
= 0;i
< SamplesToDo
;i
++)
102 SamplesOut
[c
][i
] += SamplesIn
[0][i
] * gains
[c
];
106 DECLARE_DEFAULT_ALLOCATORS(ALdedicatedState
)
108 DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState
);
111 typedef struct ALdedicatedStateFactory
{
112 DERIVE_FROM_TYPE(ALeffectStateFactory
);
113 } ALdedicatedStateFactory
;
115 ALeffectState
*ALdedicatedStateFactory_create(ALdedicatedStateFactory
*UNUSED(factory
))
117 ALdedicatedState
*state
;
120 state
= ALdedicatedState_New(sizeof(*state
));
121 if(!state
) return NULL
;
122 SET_VTABLE2(ALdedicatedState
, ALeffectState
, state
);
124 for(s
= 0;s
< MAX_OUTPUT_CHANNELS
;s
++)
125 state
->gains
[s
] = 0.0f
;
127 return STATIC_CAST(ALeffectState
, state
);
130 DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdedicatedStateFactory
);
133 ALeffectStateFactory
*ALdedicatedStateFactory_getFactory(void)
135 static ALdedicatedStateFactory DedicatedFactory
= { { GET_VTABLE2(ALdedicatedStateFactory
, ALeffectStateFactory
) } };
137 return STATIC_CAST(ALeffectStateFactory
, &DedicatedFactory
);
141 void ALdedicated_setParami(ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum
UNUSED(param
), ALint
UNUSED(val
))
142 { SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
); }
143 void ALdedicated_setParamiv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
145 ALdedicated_setParami(effect
, context
, param
, vals
[0]);
147 void ALdedicated_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
149 ALeffectProps
*props
= &effect
->Props
;
152 case AL_DEDICATED_GAIN
:
153 if(!(val
>= 0.0f
&& isfinite(val
)))
154 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
155 props
->Dedicated
.Gain
= val
;
159 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
162 void ALdedicated_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
164 ALdedicated_setParamf(effect
, context
, param
, vals
[0]);
167 void ALdedicated_getParami(const ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum
UNUSED(param
), ALint
*UNUSED(val
))
168 { SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
); }
169 void ALdedicated_getParamiv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
171 ALdedicated_getParami(effect
, context
, param
, vals
);
173 void ALdedicated_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
175 const ALeffectProps
*props
= &effect
->Props
;
178 case AL_DEDICATED_GAIN
:
179 *val
= props
->Dedicated
.Gain
;
183 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
186 void ALdedicated_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
188 ALdedicated_getParamf(effect
, context
, param
, vals
);
191 DEFINE_ALEFFECT_VTABLE(ALdedicated
);