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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
27 #include "alAuxEffectSlot.h"
32 typedef struct ALdedicatedState
{
33 // Must be first in all effects!
36 ALfloat gains
[MAXCHANNELS
];
40 static ALvoid
DedicatedDestroy(ALeffectState
*effect
)
42 ALdedicatedState
*state
= (ALdedicatedState
*)effect
;
46 static ALboolean
DedicatedDeviceUpdate(ALeffectState
*effect
, ALCdevice
*Device
)
53 static ALvoid
DedicatedUpdate(ALeffectState
*effect
, ALCdevice
*device
, const ALeffectslot
*Slot
)
55 ALdedicatedState
*state
= (ALdedicatedState
*)effect
;
56 const ALfloat
*ChannelGain
;
61 Gain
= Slot
->Gain
* Slot
->effect
.Dedicated
.Gain
;
62 for(s
= 0;s
< MAXCHANNELS
;s
++)
63 state
->gains
[s
] = 0.0f
;
65 if(Slot
->effect
.type
== AL_EFFECT_DEDICATED_DIALOGUE
)
67 pos
= aluCart2LUTpos(1.0f
, 0.0f
);
68 ChannelGain
= device
->PanningLUT
[pos
];
70 for(s
= 0;s
< MAXCHANNELS
;s
++)
71 state
->gains
[s
] = ChannelGain
[s
] * Gain
;
73 else if(Slot
->effect
.type
== AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT
)
74 state
->gains
[LFE
] = Gain
;
77 static ALvoid
DedicatedProcess(ALeffectState
*effect
, ALuint SamplesToDo
, const ALfloat
*SamplesIn
, ALfloat (*SamplesOut
)[MAXCHANNELS
])
79 ALdedicatedState
*state
= (ALdedicatedState
*)effect
;
80 const ALfloat
*gains
= state
->gains
;
83 for(i
= 0;i
< SamplesToDo
;i
++)
87 sample
= SamplesIn
[i
];
88 for(s
= 0;s
< MAXCHANNELS
;s
++)
89 SamplesOut
[i
][s
] = sample
* gains
[s
];
93 ALeffectState
*DedicatedCreate(void)
95 ALdedicatedState
*state
;
98 state
= malloc(sizeof(*state
));
102 state
->state
.Destroy
= DedicatedDestroy
;
103 state
->state
.DeviceUpdate
= DedicatedDeviceUpdate
;
104 state
->state
.Update
= DedicatedUpdate
;
105 state
->state
.Process
= DedicatedProcess
;
107 for(s
= 0;s
< MAXCHANNELS
;s
++)
108 state
->gains
[s
] = 0.0f
;
110 return &state
->state
;