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
26 #include "alAuxEffectSlot.h"
29 #include "filters/defs.h"
32 typedef struct ALdedicatedState
{
33 DERIVE_FROM_TYPE(ALeffectState
);
35 ALfloat CurrentGains
[MAX_OUTPUT_CHANNELS
];
36 ALfloat TargetGains
[MAX_OUTPUT_CHANNELS
];
39 static ALvoid
ALdedicatedState_Destruct(ALdedicatedState
*state
);
40 static ALboolean
ALdedicatedState_deviceUpdate(ALdedicatedState
*state
, ALCdevice
*device
);
41 static ALvoid
ALdedicatedState_update(ALdedicatedState
*state
, const ALCcontext
*context
, const ALeffectslot
*slot
, const ALeffectProps
*props
);
42 static ALvoid
ALdedicatedState_process(ALdedicatedState
*state
, ALsizei SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALsizei NumChannels
);
43 DECLARE_DEFAULT_ALLOCATORS(ALdedicatedState
)
45 DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState
);
48 static void ALdedicatedState_Construct(ALdedicatedState
*state
)
50 ALeffectState_Construct(STATIC_CAST(ALeffectState
, state
));
51 SET_VTABLE2(ALdedicatedState
, ALeffectState
, state
);
54 static ALvoid
ALdedicatedState_Destruct(ALdedicatedState
*state
)
56 ALeffectState_Destruct(STATIC_CAST(ALeffectState
,state
));
59 static ALboolean
ALdedicatedState_deviceUpdate(ALdedicatedState
*state
, ALCdevice
*UNUSED(device
))
62 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
63 state
->CurrentGains
[i
] = 0.0f
;
67 static ALvoid
ALdedicatedState_update(ALdedicatedState
*state
, const ALCcontext
*context
, const ALeffectslot
*slot
, const ALeffectProps
*props
)
69 const ALCdevice
*device
= context
->Device
;
73 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
74 state
->TargetGains
[i
] = 0.0f
;
76 Gain
= slot
->Params
.Gain
* props
->Dedicated
.Gain
;
77 if(slot
->Params
.EffectType
== AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT
)
80 if((idx
=GetChannelIdxByName(&device
->RealOut
, LFE
)) != -1)
82 STATIC_CAST(ALeffectState
,state
)->OutBuffer
= device
->RealOut
.Buffer
;
83 STATIC_CAST(ALeffectState
,state
)->OutChannels
= device
->RealOut
.NumChannels
;
84 state
->TargetGains
[idx
] = Gain
;
87 else if(slot
->Params
.EffectType
== AL_EFFECT_DEDICATED_DIALOGUE
)
90 /* Dialog goes to the front-center speaker if it exists, otherwise it
91 * plays from the front-center location. */
92 if((idx
=GetChannelIdxByName(&device
->RealOut
, FrontCenter
)) != -1)
94 STATIC_CAST(ALeffectState
,state
)->OutBuffer
= device
->RealOut
.Buffer
;
95 STATIC_CAST(ALeffectState
,state
)->OutChannels
= device
->RealOut
.NumChannels
;
96 state
->TargetGains
[idx
] = Gain
;
100 ALfloat coeffs
[MAX_AMBI_COEFFS
];
101 CalcAngleCoeffs(0.0f
, 0.0f
, 0.0f
, coeffs
);
103 STATIC_CAST(ALeffectState
,state
)->OutBuffer
= device
->Dry
.Buffer
;
104 STATIC_CAST(ALeffectState
,state
)->OutChannels
= device
->Dry
.NumChannels
;
105 ComputePanGains(&device
->Dry
, coeffs
, Gain
, state
->TargetGains
);
110 static ALvoid
ALdedicatedState_process(ALdedicatedState
*state
, ALsizei SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALsizei NumChannels
)
112 MixSamples(SamplesIn
[0], NumChannels
, SamplesOut
, state
->CurrentGains
,
113 state
->TargetGains
, SamplesToDo
, 0, SamplesToDo
);
117 typedef struct DedicatedStateFactory
{
118 DERIVE_FROM_TYPE(EffectStateFactory
);
119 } DedicatedStateFactory
;
121 ALeffectState
*DedicatedStateFactory_create(DedicatedStateFactory
*UNUSED(factory
))
123 ALdedicatedState
*state
;
125 NEW_OBJ0(state
, ALdedicatedState
)();
126 if(!state
) return NULL
;
128 return STATIC_CAST(ALeffectState
, state
);
131 DEFINE_EFFECTSTATEFACTORY_VTABLE(DedicatedStateFactory
);
134 EffectStateFactory
*DedicatedStateFactory_getFactory(void)
136 static DedicatedStateFactory DedicatedFactory
= { { GET_VTABLE2(DedicatedStateFactory
, EffectStateFactory
) } };
138 return STATIC_CAST(EffectStateFactory
, &DedicatedFactory
);
142 void ALdedicated_setParami(ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum param
, ALint
UNUSED(val
))
143 { alSetError(context
, AL_INVALID_ENUM
, "Invalid dedicated integer property 0x%04x", param
); }
144 void ALdedicated_setParamiv(ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum param
, const ALint
*UNUSED(vals
))
145 { alSetError(context
, AL_INVALID_ENUM
, "Invalid dedicated integer-vector property 0x%04x", param
); }
146 void ALdedicated_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
148 ALeffectProps
*props
= &effect
->Props
;
151 case AL_DEDICATED_GAIN
:
152 if(!(val
>= 0.0f
&& isfinite(val
)))
153 SETERR_RETURN(context
, AL_INVALID_VALUE
,, "Dedicated gain out of range");
154 props
->Dedicated
.Gain
= val
;
158 alSetError(context
, AL_INVALID_ENUM
, "Invalid dedicated float property 0x%04x", param
);
161 void ALdedicated_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
162 { ALdedicated_setParamf(effect
, context
, param
, vals
[0]); }
164 void ALdedicated_getParami(const ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum param
, ALint
*UNUSED(val
))
165 { alSetError(context
, AL_INVALID_ENUM
, "Invalid dedicated integer property 0x%04x", param
); }
166 void ALdedicated_getParamiv(const ALeffect
*UNUSED(effect
), ALCcontext
*context
, ALenum param
, ALint
*UNUSED(vals
))
167 { alSetError(context
, AL_INVALID_ENUM
, "Invalid dedicated integer-vector property 0x%04x", param
); }
168 void ALdedicated_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
170 const ALeffectProps
*props
= &effect
->Props
;
173 case AL_DEDICATED_GAIN
:
174 *val
= props
->Dedicated
.Gain
;
178 alSetError(context
, AL_INVALID_ENUM
, "Invalid dedicated float property 0x%04x", param
);
181 void ALdedicated_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
182 { ALdedicated_getParamf(effect
, context
, param
, vals
); }
184 DEFINE_ALEFFECT_VTABLE(ALdedicated
);