2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
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
21 #define _CRT_SECURE_NO_DEPRECATE // get rid of sprintf security warnings on VS2005
32 #include "alListener.h"
35 #if defined(HAVE_STDINT_H)
37 typedef int64_t ALint64
;
38 #elif defined(HAVE___INT64)
39 typedef __int64 ALint64
;
40 #elif (SIZEOF_LONG == 8)
42 #elif (SIZEOF_LONG_LONG == 8)
43 typedef long long ALint64
;
47 #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
49 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
53 #define aluAcos(x) ((ALfloat)acosf((float)(x)))
55 #define aluAcos(x) ((ALfloat)acos((double)(x)))
59 #if defined(max) && !defined(__max)
62 #if defined(min) && !defined(__min)
66 #define BUFFERSIZE 48000
67 #define FRACTIONBITS 14
68 #define FRACTIONMASK ((1L<<FRACTIONBITS)-1)
84 /* NOTE: The AL_FORMAT_REAR* enums aren't handled here be cause they're
85 * converted to AL_FORMAT_QUAD* when loaded */
86 __inline ALuint
aluBytesFromFormat(ALenum format
)
91 case AL_FORMAT_STEREO8
:
92 case AL_FORMAT_QUAD8_LOKI
:
94 case AL_FORMAT_51CHN8
:
95 case AL_FORMAT_61CHN8
:
96 case AL_FORMAT_71CHN8
:
99 case AL_FORMAT_MONO16
:
100 case AL_FORMAT_STEREO16
:
101 case AL_FORMAT_QUAD16_LOKI
:
102 case AL_FORMAT_QUAD16
:
103 case AL_FORMAT_51CHN16
:
104 case AL_FORMAT_61CHN16
:
105 case AL_FORMAT_71CHN16
:
108 case AL_FORMAT_MONO_FLOAT32
:
109 case AL_FORMAT_STEREO_FLOAT32
:
110 case AL_FORMAT_QUAD32
:
111 case AL_FORMAT_51CHN32
:
112 case AL_FORMAT_61CHN32
:
113 case AL_FORMAT_71CHN32
:
121 __inline ALuint
aluChannelsFromFormat(ALenum format
)
125 case AL_FORMAT_MONO8
:
126 case AL_FORMAT_MONO16
:
127 case AL_FORMAT_MONO_FLOAT32
:
130 case AL_FORMAT_STEREO8
:
131 case AL_FORMAT_STEREO16
:
132 case AL_FORMAT_STEREO_FLOAT32
:
135 case AL_FORMAT_QUAD8_LOKI
:
136 case AL_FORMAT_QUAD16_LOKI
:
137 case AL_FORMAT_QUAD8
:
138 case AL_FORMAT_QUAD16
:
139 case AL_FORMAT_QUAD32
:
142 case AL_FORMAT_51CHN8
:
143 case AL_FORMAT_51CHN16
:
144 case AL_FORMAT_51CHN32
:
147 case AL_FORMAT_61CHN8
:
148 case AL_FORMAT_61CHN16
:
149 case AL_FORMAT_61CHN32
:
152 case AL_FORMAT_71CHN8
:
153 case AL_FORMAT_71CHN16
:
154 case AL_FORMAT_71CHN32
:
162 static __inline ALint
aluF2L(ALfloat Value
)
165 if(sizeof(ALint
) == 4 && sizeof(double) == 8)
168 temp
= Value
+ (((65536.0*65536.0*16.0)+(65536.0*65536.0*8.0))*65536.0);
169 return *((ALint
*)&temp
);
175 static __inline ALshort
aluF2S(ALfloat Value
)
180 i
= __min( 32767, i
);
181 i
= __max(-32768, i
);
185 static __inline ALvoid
aluCrossproduct(ALfloat
*inVector1
,ALfloat
*inVector2
,ALfloat
*outVector
)
187 outVector
[0] = inVector1
[1]*inVector2
[2] - inVector1
[2]*inVector2
[1];
188 outVector
[1] = inVector1
[2]*inVector2
[0] - inVector1
[0]*inVector2
[2];
189 outVector
[2] = inVector1
[0]*inVector2
[1] - inVector1
[1]*inVector2
[0];
192 static __inline ALfloat
aluDotproduct(ALfloat
*inVector1
,ALfloat
*inVector2
)
194 return inVector1
[0]*inVector2
[0] + inVector1
[1]*inVector2
[1] +
195 inVector1
[2]*inVector2
[2];
198 static __inline ALvoid
aluNormalize(ALfloat
*inVector
)
200 ALfloat length
, inverse_length
;
202 length
= (ALfloat
)aluSqrt(aluDotproduct(inVector
, inVector
));
205 inverse_length
= 1.0f
/length
;
206 inVector
[0] *= inverse_length
;
207 inVector
[1] *= inverse_length
;
208 inVector
[2] *= inverse_length
;
212 static __inline ALvoid
aluMatrixVector(ALfloat
*vector
,ALfloat matrix
[3][3])
216 result
[0] = vector
[0]*matrix
[0][0] + vector
[1]*matrix
[1][0] + vector
[2]*matrix
[2][0];
217 result
[1] = vector
[0]*matrix
[0][1] + vector
[1]*matrix
[1][1] + vector
[2]*matrix
[2][1];
218 result
[2] = vector
[0]*matrix
[0][2] + vector
[1]*matrix
[1][2] + vector
[2]*matrix
[2][2];
219 memcpy(vector
, result
, sizeof(result
));
222 static __inline ALfloat
aluComputeDrySample(ALsource
*source
, ALfloat DryGainHF
, ALfloat sample
)
229 sample
+= source
->LastDrySample
* (1.0f
-DryGainHF
);
235 source
->LastDrySample
= sample
;
239 static __inline ALfloat
aluComputeWetSample(ALsource
*source
, ALfloat WetGainHF
, ALfloat sample
)
246 sample
+= source
->LastWetSample
* (1.0f
-WetGainHF
);
252 source
->LastWetSample
= sample
;
256 static ALvoid
CalcSourceParams(ALCcontext
*ALContext
, ALsource
*ALSource
,
257 ALenum isMono
, ALenum OutputFormat
,
258 ALfloat
*drysend
, ALfloat
*wetsend
,
259 ALfloat
*pitch
, ALfloat
*drygainhf
,
262 ALfloat InnerAngle
,OuterAngle
,Angle
,Distance
,DryMix
,WetMix
=0.0f
;
263 ALfloat Direction
[3],Position
[3],SourceToListener
[3];
264 ALfloat MinVolume
,MaxVolume
,MinDist
,MaxDist
,Rolloff
,OuterGainHF
;
265 ALfloat ConeVolume
,SourceVolume
,PanningFB
,PanningLR
,ListenerGain
;
266 ALfloat U
[3],V
[3],N
[3];
267 ALfloat DopplerFactor
, DopplerVelocity
, flSpeedOfSound
, flMaxVelocity
;
268 ALfloat Matrix
[3][3];
269 ALfloat flAttenuation
;
270 ALfloat RoomAttenuation
;
271 ALfloat MetersPerUnit
;
273 ALfloat DryGainHF
= 1.0f
;
274 ALfloat WetGainHF
= 1.0f
;
276 //Get context properties
277 DopplerFactor
= ALContext
->DopplerFactor
;
278 DopplerVelocity
= ALContext
->DopplerVelocity
;
279 flSpeedOfSound
= ALContext
->flSpeedOfSound
;
281 //Get listener properties
282 ListenerGain
= ALContext
->Listener
.Gain
;
283 MetersPerUnit
= ALContext
->Listener
.MetersPerUnit
;
285 //Get source properties
286 SourceVolume
= ALSource
->flGain
;
287 memcpy(Position
, ALSource
->vPosition
, sizeof(ALSource
->vPosition
));
288 memcpy(Direction
, ALSource
->vOrientation
, sizeof(ALSource
->vOrientation
));
289 MinVolume
= ALSource
->flMinGain
;
290 MaxVolume
= ALSource
->flMaxGain
;
291 MinDist
= ALSource
->flRefDistance
;
292 MaxDist
= ALSource
->flMaxDistance
;
293 Rolloff
= ALSource
->flRollOffFactor
;
294 InnerAngle
= ALSource
->flInnerAngle
;
295 OuterAngle
= ALSource
->flOuterAngle
;
296 OuterGainHF
= ALSource
->OuterGainHF
;
297 RoomRolloff
= ALSource
->RoomRolloffFactor
;
299 //Only apply 3D calculations for mono buffers
300 if(isMono
!= AL_FALSE
)
302 //1. Translate Listener to origin (convert to head relative)
303 if(ALSource
->bHeadRelative
==AL_FALSE
)
305 Position
[0] -= ALContext
->Listener
.Position
[0];
306 Position
[1] -= ALContext
->Listener
.Position
[1];
307 Position
[2] -= ALContext
->Listener
.Position
[2];
310 //2. Calculate distance attenuation
311 Distance
= aluSqrt(aluDotproduct(Position
, Position
));
313 flAttenuation
= 1.0f
;
314 RoomAttenuation
= 1.0f
;
315 switch (ALContext
->DistanceModel
)
317 case AL_INVERSE_DISTANCE_CLAMPED
:
318 Distance
=__max(Distance
,MinDist
);
319 Distance
=__min(Distance
,MaxDist
);
320 if (MaxDist
< MinDist
)
323 case AL_INVERSE_DISTANCE
:
326 if ((MinDist
+ (Rolloff
* (Distance
- MinDist
))) > 0.0f
)
327 flAttenuation
= MinDist
/ (MinDist
+ (Rolloff
* (Distance
- MinDist
)));
328 if ((MinDist
+ (RoomRolloff
* (Distance
- MinDist
))) > 0.0f
)
329 RoomAttenuation
= MinDist
/ (MinDist
+ (RoomRolloff
* (Distance
- MinDist
)));
333 case AL_LINEAR_DISTANCE_CLAMPED
:
334 Distance
=__max(Distance
,MinDist
);
335 Distance
=__min(Distance
,MaxDist
);
336 if (MaxDist
< MinDist
)
339 case AL_LINEAR_DISTANCE
:
340 Distance
=__min(Distance
,MaxDist
);
341 if (MaxDist
!= MinDist
)
343 flAttenuation
= 1.0f
- (Rolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
344 RoomAttenuation
= 1.0f
- (RoomRolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
348 case AL_EXPONENT_DISTANCE_CLAMPED
:
349 Distance
=__max(Distance
,MinDist
);
350 Distance
=__min(Distance
,MaxDist
);
351 if (MaxDist
< MinDist
)
354 case AL_EXPONENT_DISTANCE
:
355 if ((Distance
> 0.0f
) && (MinDist
> 0.0f
))
357 flAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -Rolloff
);
358 RoomAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -RoomRolloff
);
364 flAttenuation
= 1.0f
;
365 RoomAttenuation
= 1.0f
;
369 // Source Gain + Attenuation
370 DryMix
= SourceVolume
* flAttenuation
;
371 if(ALSource
->Send
[0].Slot
)
372 WetMix
= SourceVolume
* ((ALSource
->WetGainAuto
&&
373 ALSource
->Send
[0].Slot
->AuxSendAuto
) ?
374 RoomAttenuation
: 1.0f
);
376 // Clamp to Min/Max Gain
377 DryMix
= __min(DryMix
,MaxVolume
);
378 DryMix
= __max(DryMix
,MinVolume
);
379 WetMix
= __min(WetMix
,MaxVolume
);
380 WetMix
= __max(WetMix
,MinVolume
);
381 //3. Apply directional soundcones
382 SourceToListener
[0] = -Position
[0];
383 SourceToListener
[1] = -Position
[1];
384 SourceToListener
[2] = -Position
[2];
385 aluNormalize(Direction
);
386 aluNormalize(SourceToListener
);
387 Angle
= aluAcos(aluDotproduct(Direction
,SourceToListener
)) * 180.0f
/
389 if(Angle
>= InnerAngle
&& Angle
<= OuterAngle
)
391 ALfloat scale
= (Angle
-InnerAngle
) / (OuterAngle
-InnerAngle
);
392 ConeVolume
= (1.0f
+(ALSource
->flOuterGain
-1.0f
)*scale
);
393 if(ALSource
->WetGainAuto
)
394 WetMix
*= ConeVolume
;
395 if(ALSource
->DryGainHFAuto
)
396 DryGainHF
*= (1.0f
+(OuterGainHF
-1.0f
)*scale
);
397 if(ALSource
->WetGainHFAuto
)
398 WetGainHF
*= (1.0f
+(OuterGainHF
-1.0f
)*scale
);
400 else if(Angle
> OuterAngle
)
402 ConeVolume
= (1.0f
+(ALSource
->flOuterGain
-1.0f
));
403 if(ALSource
->WetGainAuto
)
404 WetMix
*= ConeVolume
;
405 if(ALSource
->DryGainHFAuto
)
406 DryGainHF
*= (1.0f
+(OuterGainHF
-1.0f
));
407 if(ALSource
->WetGainHFAuto
)
408 WetGainHF
*= (1.0f
+(OuterGainHF
-1.0f
));
413 //4. Calculate Velocity
414 if(DopplerFactor
!= 0.0f
)
416 ALfloat flVSS
, flVLS
;
418 flVLS
= aluDotproduct(ALContext
->Listener
.Velocity
,
420 flVSS
= aluDotproduct(ALSource
->vVelocity
, SourceToListener
);
422 flMaxVelocity
= (DopplerVelocity
* flSpeedOfSound
) / DopplerFactor
;
424 if (flVSS
>= flMaxVelocity
)
425 flVSS
= (flMaxVelocity
- 1.0f
);
426 else if (flVSS
<= -flMaxVelocity
)
427 flVSS
= -flMaxVelocity
+ 1.0f
;
429 if (flVLS
>= flMaxVelocity
)
430 flVLS
= (flMaxVelocity
- 1.0f
);
431 else if (flVLS
<= -flMaxVelocity
)
432 flVLS
= -flMaxVelocity
+ 1.0f
;
434 pitch
[0] = ALSource
->flPitch
*
435 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVLS
)) /
436 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVSS
));
439 pitch
[0] = ALSource
->flPitch
;
441 //5. Align coordinate system axes
442 aluCrossproduct(ALContext
->Listener
.Forward
, ALContext
->Listener
.Up
, U
); // Right-vector
443 aluNormalize(U
); // Normalized Right-vector
444 memcpy(V
, ALContext
->Listener
.Up
, sizeof(V
)); // Up-vector
445 aluNormalize(V
); // Normalized Up-vector
446 memcpy(N
, ALContext
->Listener
.Forward
, sizeof(N
)); // At-vector
447 aluNormalize(N
); // Normalized At-vector
448 Matrix
[0][0] = U
[0]; Matrix
[0][1] = V
[0]; Matrix
[0][2] = -N
[0];
449 Matrix
[1][0] = U
[1]; Matrix
[1][1] = V
[1]; Matrix
[1][2] = -N
[1];
450 Matrix
[2][0] = U
[2]; Matrix
[2][1] = V
[2]; Matrix
[2][2] = -N
[2];
451 aluMatrixVector(Position
, Matrix
);
453 //6. Apply filter gains and filters
454 switch(ALSource
->DirectFilter
.filter
)
456 case AL_FILTER_LOWPASS
:
457 DryMix
*= ALSource
->DirectFilter
.Gain
;
458 DryGainHF
*= ALSource
->DirectFilter
.GainHF
;
462 switch(ALSource
->Send
[0].WetFilter
.filter
)
464 case AL_FILTER_LOWPASS
:
465 WetMix
*= ALSource
->Send
[0].WetFilter
.Gain
;
466 WetGainHF
*= ALSource
->Send
[0].WetFilter
.GainHF
;
470 if(ALSource
->AirAbsorptionFactor
> 0.0f
)
471 DryGainHF
*= pow(ALSource
->AirAbsorptionFactor
* AIRABSORBGAINHF
,
472 Distance
* MetersPerUnit
);
474 if(ALSource
->Send
[0].Slot
)
475 WetMix
*= ALSource
->Send
[0].Slot
->Gain
;
477 //7. Convert normalized position into pannings, then into channel volumes
478 aluNormalize(Position
);
479 switch(aluChannelsFromFormat(OutputFormat
))
482 drysend
[FRONT_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
483 drysend
[FRONT_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
484 if(ALSource
->Send
[0].Slot
)
486 wetsend
[FRONT_LEFT
] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
487 wetsend
[FRONT_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
491 wetsend
[FRONT_LEFT
] = 0.0f
;
492 wetsend
[FRONT_RIGHT
] = 0.0f
;
497 PanningLR
= 0.5f
+ 0.5f
*Position
[0];
498 drysend
[FRONT_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
-PanningLR
); //L Direct
499 drysend
[FRONT_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt( PanningLR
); //R Direct
500 if(ALSource
->Send
[0].Slot
)
502 wetsend
[FRONT_LEFT
] = ListenerGain
* WetMix
* aluSqrt(1.0f
-PanningLR
); //L Room
503 wetsend
[FRONT_RIGHT
] = ListenerGain
* WetMix
* aluSqrt( PanningLR
); //R Room
507 wetsend
[FRONT_LEFT
] = 0.0f
;
508 wetsend
[FRONT_RIGHT
] = 0.0f
;
513 /* TODO: Add center/lfe channel in spatial calculations? */
515 // Apply a scalar so each individual speaker has more weight
516 PanningLR
= 0.5f
+ (0.5f
*Position
[0]*1.41421356f
);
517 PanningLR
= __min(1.0f
, PanningLR
);
518 PanningLR
= __max(0.0f
, PanningLR
);
519 PanningFB
= 0.5f
+ (0.5f
*Position
[2]*1.41421356f
);
520 PanningFB
= __min(1.0f
, PanningFB
);
521 PanningFB
= __max(0.0f
, PanningFB
);
522 drysend
[FRONT_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
523 drysend
[FRONT_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
524 drysend
[BACK_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
525 drysend
[BACK_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
526 if(ALSource
->Send
[0].Slot
)
528 wetsend
[FRONT_LEFT
] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
529 wetsend
[FRONT_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
530 wetsend
[BACK_LEFT
] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
531 wetsend
[BACK_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*( PanningFB
));
535 wetsend
[FRONT_LEFT
] = 0.0f
;
536 wetsend
[FRONT_RIGHT
] = 0.0f
;
537 wetsend
[BACK_LEFT
] = 0.0f
;
538 wetsend
[BACK_RIGHT
] = 0.0f
;
544 PanningFB
= 1.0f
- fabs(Position
[2]*1.15470054f
);
545 PanningFB
= __min(1.0f
, PanningFB
);
546 PanningFB
= __max(0.0f
, PanningFB
);
547 PanningLR
= 0.5f
+ (0.5*Position
[0]*((1.0f
-PanningFB
)*2.0f
));
548 PanningLR
= __min(1.0f
, PanningLR
);
549 PanningLR
= __max(0.0f
, PanningLR
);
550 if(Position
[2] > 0.0f
)
552 drysend
[BACK_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
553 drysend
[BACK_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
554 drysend
[SIDE_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
555 drysend
[SIDE_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
556 drysend
[FRONT_LEFT
] = 0.0f
;
557 drysend
[FRONT_RIGHT
] = 0.0f
;
558 if(ALSource
->Send
[0].Slot
)
560 wetsend
[BACK_LEFT
] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
561 wetsend
[BACK_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
562 wetsend
[SIDE_LEFT
] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
563 wetsend
[SIDE_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*( PanningFB
));
564 wetsend
[FRONT_LEFT
] = 0.0f
;
565 wetsend
[FRONT_RIGHT
] = 0.0f
;
569 wetsend
[FRONT_LEFT
] = 0.0f
;
570 wetsend
[FRONT_RIGHT
] = 0.0f
;
571 wetsend
[SIDE_LEFT
] = 0.0f
;
572 wetsend
[SIDE_RIGHT
] = 0.0f
;
573 wetsend
[BACK_LEFT
] = 0.0f
;
574 wetsend
[BACK_RIGHT
] = 0.0f
;
580 drysend
[FRONT_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
581 drysend
[FRONT_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
582 drysend
[SIDE_LEFT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
583 drysend
[SIDE_RIGHT
] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
584 drysend
[BACK_LEFT
] = 0.0f
;
585 drysend
[BACK_RIGHT
] = 0.0f
;
586 if(ALSource
->Send
[0].Slot
)
588 wetsend
[FRONT_LEFT
] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
589 wetsend
[FRONT_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
590 wetsend
[SIDE_LEFT
] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
591 wetsend
[SIDE_RIGHT
] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*( PanningFB
));
592 wetsend
[BACK_LEFT
] = 0.0f
;
593 wetsend
[BACK_RIGHT
] = 0.0f
;
597 wetsend
[FRONT_LEFT
] = 0.0f
;
598 wetsend
[FRONT_RIGHT
] = 0.0f
;
599 wetsend
[SIDE_LEFT
] = 0.0f
;
600 wetsend
[SIDE_RIGHT
] = 0.0f
;
601 wetsend
[BACK_LEFT
] = 0.0f
;
602 wetsend
[BACK_RIGHT
] = 0.0f
;
610 *drygainhf
= DryGainHF
;
611 *wetgainhf
= WetGainHF
;
615 *drygainhf
= DryGainHF
;
616 *wetgainhf
= WetGainHF
;
618 //1. Multi-channel buffers always play "normal"
619 drysend
[FRONT_LEFT
] = SourceVolume
* 1.0f
* ListenerGain
;
620 drysend
[FRONT_RIGHT
] = SourceVolume
* 1.0f
* ListenerGain
;
621 drysend
[SIDE_LEFT
] = SourceVolume
* 1.0f
* ListenerGain
;
622 drysend
[SIDE_RIGHT
] = SourceVolume
* 1.0f
* ListenerGain
;
623 drysend
[BACK_LEFT
] = SourceVolume
* 1.0f
* ListenerGain
;
624 drysend
[BACK_RIGHT
] = SourceVolume
* 1.0f
* ListenerGain
;
625 drysend
[CENTER
] = SourceVolume
* 1.0f
* ListenerGain
;
626 drysend
[LFE
] = SourceVolume
* 1.0f
* ListenerGain
;
627 if(ALSource
->Send
[0].Slot
)
629 wetsend
[FRONT_LEFT
] = SourceVolume
* 0.0f
* ListenerGain
;
630 wetsend
[FRONT_RIGHT
] = SourceVolume
* 0.0f
* ListenerGain
;
631 wetsend
[SIDE_LEFT
] = SourceVolume
* 0.0f
* ListenerGain
;
632 wetsend
[SIDE_RIGHT
] = SourceVolume
* 0.0f
* ListenerGain
;
633 wetsend
[BACK_LEFT
] = SourceVolume
* 0.0f
* ListenerGain
;
634 wetsend
[BACK_RIGHT
] = SourceVolume
* 0.0f
* ListenerGain
;
635 wetsend
[CENTER
] = SourceVolume
* 0.0f
* ListenerGain
;
636 wetsend
[LFE
] = SourceVolume
* 0.0f
* ListenerGain
;
640 wetsend
[FRONT_LEFT
] = 0.0f
;
641 wetsend
[FRONT_RIGHT
] = 0.0f
;
642 wetsend
[SIDE_LEFT
] = 0.0f
;
643 wetsend
[SIDE_RIGHT
] = 0.0f
;
644 wetsend
[BACK_LEFT
] = 0.0f
;
645 wetsend
[BACK_RIGHT
] = 0.0f
;
646 wetsend
[CENTER
] = 0.0f
;
651 pitch
[0] = ALSource
->flPitch
;
655 ALvoid
aluMixData(ALCcontext
*ALContext
,ALvoid
*buffer
,ALsizei size
,ALenum format
)
657 static float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
658 static float WetBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
659 ALfloat DrySend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
660 ALfloat WetSend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
661 ALfloat DryGainHF
= 0.0f
;
662 ALfloat WetGainHF
= 0.0f
;
663 ALuint BlockAlign
,BufferSize
;
664 ALuint DataSize
=0,DataPosInt
=0,DataPosFrac
=0;
665 ALuint Channels
,Frequency
,ulExtraSamples
;
667 ALint Looping
,increment
,State
;
668 ALuint Buffer
,fraction
;
675 ALbufferlistitem
*BufferListItem
;
677 ALint64 DataSize64
,DataPos64
;
679 SuspendContext(ALContext
);
683 //Figure output format variables
684 BlockAlign
= aluChannelsFromFormat(format
);
685 BlockAlign
*= aluBytesFromFormat(format
);
691 ALSource
= (ALContext
? ALContext
->Source
: NULL
);
692 SamplesToDo
= min(size
, BUFFERSIZE
);
694 //Clear mixing buffer
695 memset(DryBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
696 memset(WetBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
702 State
= ALSource
->state
;
703 while(State
== AL_PLAYING
&& j
< SamplesToDo
)
710 if((Buffer
= ALSource
->ulBufferID
))
712 ALBuffer
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(Buffer
);
714 Data
= ALBuffer
->data
;
715 Channels
= aluChannelsFromFormat(ALBuffer
->format
);
716 DataSize
= ALBuffer
->size
;
717 Frequency
= ALBuffer
->frequency
;
719 CalcSourceParams(ALContext
, ALSource
,
720 (Channels
==1) ? AL_TRUE
: AL_FALSE
,
721 format
, DrySend
, WetSend
, &Pitch
,
722 &DryGainHF
, &WetGainHF
);
725 Pitch
= (Pitch
*Frequency
) / ALContext
->Frequency
;
726 DataSize
/= Channels
* aluBytesFromFormat(ALBuffer
->format
);
729 DataPosInt
= ALSource
->position
;
730 DataPosFrac
= ALSource
->position_fraction
;
732 //Compute 18.14 fixed point step
733 increment
= aluF2L(Pitch
*(1L<<FRACTIONBITS
));
734 if(increment
> (MAX_PITCH
<<FRACTIONBITS
))
735 increment
= (MAX_PITCH
<<FRACTIONBITS
);
737 //Figure out how many samples we can mix.
738 //Pitch must be <= 4 (the number below !)
739 DataSize64
= DataSize
+MAX_PITCH
;
740 DataSize64
<<= FRACTIONBITS
;
741 DataPos64
= DataPosInt
;
742 DataPos64
<<= FRACTIONBITS
;
743 DataPos64
+= DataPosFrac
;
744 BufferSize
= (ALuint
)((DataSize64
-DataPos64
) / increment
);
745 BufferListItem
= ALSource
->queue
;
746 for(loop
= 0; loop
< ALSource
->BuffersPlayed
; loop
++)
749 BufferListItem
= BufferListItem
->next
;
753 if (BufferListItem
->next
)
755 if(BufferListItem
->next
->buffer
&&
756 ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
)
758 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->size
, (ALint
)(16*Channels
));
759 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
, ulExtraSamples
);
762 else if (ALSource
->bLooping
)
764 if (ALSource
->queue
->buffer
)
766 if(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
)
768 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->size
, (ALint
)(16*Channels
));
769 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
, ulExtraSamples
);
774 BufferSize
= min(BufferSize
, (SamplesToDo
-j
));
776 //Actual sample mixing loop
777 Data
+= DataPosInt
*Channels
;
780 k
= DataPosFrac
>>FRACTIONBITS
;
781 fraction
= DataPosFrac
&FRACTIONMASK
;
784 //First order interpolator
785 ALfloat sample
= (ALfloat
)((ALshort
)(((Data
[k
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
+1]*(fraction
)))>>FRACTIONBITS
));
787 //Direct path final mix buffer and panning
788 value
= aluComputeDrySample(ALSource
, DryGainHF
, sample
);
789 DryBuffer
[j
][FRONT_LEFT
] += value
*DrySend
[FRONT_LEFT
];
790 DryBuffer
[j
][FRONT_RIGHT
] += value
*DrySend
[FRONT_RIGHT
];
791 DryBuffer
[j
][SIDE_LEFT
] += value
*DrySend
[SIDE_LEFT
];
792 DryBuffer
[j
][SIDE_RIGHT
] += value
*DrySend
[SIDE_RIGHT
];
793 DryBuffer
[j
][BACK_LEFT
] += value
*DrySend
[BACK_LEFT
];
794 DryBuffer
[j
][BACK_RIGHT
] += value
*DrySend
[BACK_RIGHT
];
795 //Room path final mix buffer and panning
796 value
= aluComputeWetSample(ALSource
, WetGainHF
, sample
);
797 WetBuffer
[j
][FRONT_LEFT
] += value
*WetSend
[FRONT_LEFT
];
798 WetBuffer
[j
][FRONT_RIGHT
] += value
*WetSend
[FRONT_RIGHT
];
799 WetBuffer
[j
][SIDE_LEFT
] += value
*WetSend
[SIDE_LEFT
];
800 WetBuffer
[j
][SIDE_RIGHT
] += value
*WetSend
[SIDE_RIGHT
];
801 WetBuffer
[j
][BACK_LEFT
] += value
*WetSend
[BACK_LEFT
];
802 WetBuffer
[j
][BACK_RIGHT
] += value
*WetSend
[BACK_RIGHT
];
806 //First order interpolator (front left)
807 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
]*(fraction
)))>>FRACTIONBITS
));
808 DryBuffer
[j
][FRONT_LEFT
] += value
*DrySend
[FRONT_LEFT
];
809 WetBuffer
[j
][FRONT_LEFT
] += value
*WetSend
[FRONT_LEFT
];
810 //First order interpolator (front right)
811 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+1]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+1]*(fraction
)))>>FRACTIONBITS
));
812 DryBuffer
[j
][FRONT_RIGHT
] += value
*DrySend
[FRONT_RIGHT
];
813 WetBuffer
[j
][FRONT_RIGHT
] += value
*WetSend
[FRONT_RIGHT
];
821 //First order interpolator (center)
822 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+i
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+i
]*(fraction
)))>>FRACTIONBITS
));
823 DryBuffer
[j
][CENTER
] += value
*DrySend
[CENTER
];
824 WetBuffer
[j
][CENTER
] += value
*WetSend
[CENTER
];
827 //First order interpolator (lfe)
828 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+i
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+i
]*(fraction
)))>>FRACTIONBITS
));
829 DryBuffer
[j
][LFE
] += value
*DrySend
[LFE
];
830 WetBuffer
[j
][LFE
] += value
*WetSend
[LFE
];
833 //First order interpolator (back left)
834 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+i
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+i
]*(fraction
)))>>FRACTIONBITS
));
835 DryBuffer
[j
][BACK_LEFT
] += value
*DrySend
[BACK_LEFT
];
836 WetBuffer
[j
][BACK_LEFT
] += value
*WetSend
[BACK_LEFT
];
838 //First order interpolator (back right)
839 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+i
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+i
]*(fraction
)))>>FRACTIONBITS
));
840 DryBuffer
[j
][BACK_RIGHT
] += value
*DrySend
[BACK_RIGHT
];
841 WetBuffer
[j
][BACK_RIGHT
] += value
*WetSend
[BACK_RIGHT
];
845 //First order interpolator (side left)
846 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+i
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+i
]*(fraction
)))>>FRACTIONBITS
));
847 DryBuffer
[j
][SIDE_LEFT
] += value
*DrySend
[SIDE_LEFT
];
848 WetBuffer
[j
][SIDE_LEFT
] += value
*WetSend
[SIDE_LEFT
];
850 //First order interpolator (side right)
851 value
= (ALfloat
)((ALshort
)(((Data
[k
*Channels
+i
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[(k
+1)*Channels
+i
]*(fraction
)))>>FRACTIONBITS
));
852 DryBuffer
[j
][SIDE_RIGHT
] += value
*DrySend
[SIDE_RIGHT
];
853 WetBuffer
[j
][SIDE_RIGHT
] += value
*WetSend
[SIDE_RIGHT
];
858 DataPosFrac
+= increment
;
861 DataPosInt
+= (DataPosFrac
>>FRACTIONBITS
);
862 DataPosFrac
= (DataPosFrac
&FRACTIONMASK
);
865 ALSource
->position
= DataPosInt
;
866 ALSource
->position_fraction
= DataPosFrac
;
869 //Handle looping sources
870 if(!Buffer
|| DataPosInt
>= DataSize
)
875 Looping
= ALSource
->bLooping
;
876 if(ALSource
->BuffersPlayed
< (ALSource
->BuffersInQueue
-1))
878 BufferListItem
= ALSource
->queue
;
879 for(loop
= 0; loop
<= ALSource
->BuffersPlayed
; loop
++)
884 BufferListItem
->bufferstate
= PROCESSED
;
885 BufferListItem
= BufferListItem
->next
;
889 ALSource
->BuffersProcessed
++;
891 ALSource
->ulBufferID
= BufferListItem
->buffer
;
892 ALSource
->position
= DataPosInt
-DataSize
;
893 ALSource
->position_fraction
= DataPosFrac
;
894 ALSource
->BuffersPlayed
++;
901 ALSource
->state
= AL_STOPPED
;
902 ALSource
->inuse
= AL_FALSE
;
903 ALSource
->BuffersPlayed
= ALSource
->BuffersProcessed
= ALSource
->BuffersInQueue
;
904 BufferListItem
= ALSource
->queue
;
905 while(BufferListItem
!= NULL
)
907 BufferListItem
->bufferstate
= PROCESSED
;
908 BufferListItem
= BufferListItem
->next
;
915 ALSource
->state
= AL_PLAYING
;
916 ALSource
->inuse
= AL_TRUE
;
917 ALSource
->play
= AL_TRUE
;
918 ALSource
->BuffersPlayed
= 0;
919 ALSource
->BufferPosition
= 0;
920 ALSource
->lBytesPlayed
= 0;
921 ALSource
->BuffersProcessed
= 0;
922 BufferListItem
= ALSource
->queue
;
923 while(BufferListItem
!= NULL
)
925 BufferListItem
->bufferstate
= PENDING
;
926 BufferListItem
= BufferListItem
->next
;
928 ALSource
->ulBufferID
= ALSource
->queue
->buffer
;
930 ALSource
->position
= DataPosInt
-DataSize
;
931 ALSource
->position_fraction
= DataPosFrac
;
938 State
= ALSource
->state
;
941 ALSource
= ALSource
->next
;
944 //Post processing loop
947 case AL_FORMAT_MONO8
:
948 for(i
= 0;i
< SamplesToDo
;i
++)
950 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
]+DryBuffer
[i
][FRONT_RIGHT
]+
951 WetBuffer
[i
][FRONT_LEFT
]+WetBuffer
[i
][FRONT_RIGHT
])>>8)+128);
952 buffer
= ((ALubyte
*)buffer
) + 1;
955 case AL_FORMAT_STEREO8
:
958 for(i
= 0;i
< SamplesToDo
;i
++)
961 samples
[0] = DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
];
962 samples
[1] = DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
];
963 bs2b_cross_feed(ALContext
->bs2b
, samples
);
964 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(samples
[0])>>8)+128);
965 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(samples
[1])>>8)+128);
966 buffer
= ((ALubyte
*)buffer
) + 2;
971 for(i
= 0;i
< SamplesToDo
;i
++)
973 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
])>>8)+128);
974 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
])>>8)+128);
975 buffer
= ((ALubyte
*)buffer
) + 2;
979 case AL_FORMAT_QUAD8
:
980 for(i
= 0;i
< SamplesToDo
;i
++)
982 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
])>>8)+128);
983 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
])>>8)+128);
984 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
])>>8)+128);
985 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
])>>8)+128);
986 buffer
= ((ALubyte
*)buffer
) + 4;
989 case AL_FORMAT_51CHN8
:
990 for(i
= 0;i
< SamplesToDo
;i
++)
992 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
])>>8)+128);
993 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
])>>8)+128);
994 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
])>>8)+128);
995 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
])>>8)+128);
996 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
] +WetBuffer
[i
][CENTER
])>>8)+128);
997 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
] +WetBuffer
[i
][LFE
])>>8)+128);
998 buffer
= ((ALubyte
*)buffer
) + 6;
1001 case AL_FORMAT_61CHN8
:
1002 for(i
= 0;i
< SamplesToDo
;i
++)
1004 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
])>>8)+128);
1005 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1006 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_LEFT
] +WetBuffer
[i
][SIDE_LEFT
])>>8)+128);
1007 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_RIGHT
] +WetBuffer
[i
][SIDE_RIGHT
])>>8)+128);
1008 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
])>>8)+128);
1009 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
])>>8)+128);
1010 ((ALubyte
*)buffer
)[6] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
] +WetBuffer
[i
][LFE
])>>8)+128);
1011 buffer
= ((ALubyte
*)buffer
) + 7;
1014 case AL_FORMAT_71CHN8
:
1015 for(i
= 0;i
< SamplesToDo
;i
++)
1017 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
])>>8)+128);
1018 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1019 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_LEFT
] +WetBuffer
[i
][SIDE_LEFT
])>>8)+128);
1020 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_RIGHT
] +WetBuffer
[i
][SIDE_RIGHT
])>>8)+128);
1021 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
])>>8)+128);
1022 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
])>>8)+128);
1023 ((ALubyte
*)buffer
)[6] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
] +WetBuffer
[i
][CENTER
])>>8)+128);
1024 ((ALubyte
*)buffer
)[7] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
] +WetBuffer
[i
][LFE
])>>8)+128);
1025 buffer
= ((ALubyte
*)buffer
) + 8;
1029 case AL_FORMAT_MONO16
:
1030 for(i
= 0;i
< SamplesToDo
;i
++)
1032 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]+DryBuffer
[i
][FRONT_RIGHT
]+
1033 WetBuffer
[i
][FRONT_LEFT
]+WetBuffer
[i
][FRONT_RIGHT
]);
1034 buffer
= ((ALshort
*)buffer
) + 1;
1037 case AL_FORMAT_STEREO16
:
1040 for(i
= 0;i
< SamplesToDo
;i
++)
1043 samples
[0] = DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
];
1044 samples
[1] = DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
];
1045 bs2b_cross_feed(ALContext
->bs2b
, samples
);
1046 ((ALshort
*)buffer
)[0] = aluF2S(samples
[0]);
1047 ((ALshort
*)buffer
)[1] = aluF2S(samples
[1]);
1048 buffer
= ((ALshort
*)buffer
) + 2;
1053 for(i
= 0;i
< SamplesToDo
;i
++)
1055 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
]);
1056 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
]);
1057 buffer
= ((ALshort
*)buffer
) + 2;
1061 case AL_FORMAT_QUAD16
:
1062 for(i
= 0;i
< SamplesToDo
;i
++)
1064 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
]);
1065 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
]);
1066 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
]);
1067 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
]);
1068 buffer
= ((ALshort
*)buffer
) + 4;
1071 case AL_FORMAT_51CHN16
:
1072 for(i
= 0;i
< SamplesToDo
;i
++)
1074 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
]);
1075 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
]);
1076 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
]);
1077 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
]);
1078 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][CENTER
] +WetBuffer
[i
][CENTER
]);
1079 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][LFE
] +WetBuffer
[i
][LFE
]);
1080 buffer
= ((ALshort
*)buffer
) + 6;
1083 case AL_FORMAT_61CHN16
:
1084 for(i
= 0;i
< SamplesToDo
;i
++)
1086 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
]);
1087 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
]);
1088 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][SIDE_LEFT
] +WetBuffer
[i
][SIDE_LEFT
]);
1089 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][SIDE_RIGHT
] +WetBuffer
[i
][SIDE_RIGHT
]);
1090 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
]);
1091 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
]);
1092 ((ALshort
*)buffer
)[6] = aluF2S(DryBuffer
[i
][LFE
] +WetBuffer
[i
][LFE
]);
1093 buffer
= ((ALshort
*)buffer
) + 7;
1096 case AL_FORMAT_71CHN16
:
1097 for(i
= 0;i
< SamplesToDo
;i
++)
1099 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
] +WetBuffer
[i
][FRONT_LEFT
]);
1100 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]+WetBuffer
[i
][FRONT_RIGHT
]);
1101 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][SIDE_LEFT
] +WetBuffer
[i
][SIDE_LEFT
]);
1102 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][SIDE_RIGHT
] +WetBuffer
[i
][SIDE_RIGHT
]);
1103 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_LEFT
] +WetBuffer
[i
][BACK_LEFT
]);
1104 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][BACK_RIGHT
] +WetBuffer
[i
][BACK_RIGHT
]);
1105 ((ALshort
*)buffer
)[6] = aluF2S(DryBuffer
[i
][CENTER
] +WetBuffer
[i
][CENTER
]);
1106 ((ALshort
*)buffer
)[7] = aluF2S(DryBuffer
[i
][LFE
] +WetBuffer
[i
][LFE
]);
1107 buffer
= ((ALshort
*)buffer
) + 8;
1115 size
-= SamplesToDo
;
1119 ProcessContext(ALContext
);