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"
33 #include "alAuxEffectSlot.h"
38 #if defined (HAVE_FLOAT_H)
42 #if defined(HAVE_STDINT_H)
44 typedef int64_t ALint64
;
45 #elif defined(HAVE___INT64)
46 typedef __int64 ALint64
;
47 #elif (SIZEOF_LONG == 8)
49 #elif (SIZEOF_LONG_LONG == 8)
50 typedef long long ALint64
;
54 #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
56 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
60 #define aluAcos(x) ((ALfloat)acosf((float)(x)))
62 #define aluAcos(x) ((ALfloat)acos((double)(x)))
66 #if defined(max) && !defined(__max)
69 #if defined(min) && !defined(__min)
73 #define BUFFERSIZE 24000
74 #define FRACTIONBITS 14
75 #define FRACTIONMASK ((1L<<FRACTIONBITS)-1)
76 #define MAX_PITCH 65536
78 /* Minimum ramp length in milliseconds. The value below was chosen to
79 * adequately reduce clicks and pops from harsh gain changes. */
80 #define MIN_RAMP_LENGTH 16
82 ALboolean DuplicateStereo
= AL_FALSE
;
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
:
163 static __inline ALfloat
lpFilter(FILTER
*iir
, ALfloat input
)
165 ALfloat
*history
= iir
->history
;
166 ALfloat a
= iir
->coeff
;
167 ALfloat output
= input
;
169 output
= output
+ (history
[0]-output
)*a
;
171 output
= output
+ (history
[1]-output
)*a
;
173 output
= output
+ (history
[2]-output
)*a
;
175 output
= output
+ (history
[3]-output
)*a
;
182 static __inline ALshort
aluF2S(ALfloat Value
)
187 i
= __min( 32767, i
);
188 i
= __max(-32768, i
);
192 static __inline ALvoid
aluCrossproduct(ALfloat
*inVector1
,ALfloat
*inVector2
,ALfloat
*outVector
)
194 outVector
[0] = inVector1
[1]*inVector2
[2] - inVector1
[2]*inVector2
[1];
195 outVector
[1] = inVector1
[2]*inVector2
[0] - inVector1
[0]*inVector2
[2];
196 outVector
[2] = inVector1
[0]*inVector2
[1] - inVector1
[1]*inVector2
[0];
199 static __inline ALfloat
aluDotproduct(ALfloat
*inVector1
,ALfloat
*inVector2
)
201 return inVector1
[0]*inVector2
[0] + inVector1
[1]*inVector2
[1] +
202 inVector1
[2]*inVector2
[2];
205 static __inline ALvoid
aluNormalize(ALfloat
*inVector
)
207 ALfloat length
, inverse_length
;
209 length
= aluSqrt(aluDotproduct(inVector
, inVector
));
212 inverse_length
= 1.0f
/length
;
213 inVector
[0] *= inverse_length
;
214 inVector
[1] *= inverse_length
;
215 inVector
[2] *= inverse_length
;
219 static __inline ALvoid
aluMatrixVector(ALfloat
*vector
,ALfloat matrix
[3][3])
223 result
[0] = vector
[0]*matrix
[0][0] + vector
[1]*matrix
[1][0] + vector
[2]*matrix
[2][0];
224 result
[1] = vector
[0]*matrix
[0][1] + vector
[1]*matrix
[1][1] + vector
[2]*matrix
[2][1];
225 result
[2] = vector
[0]*matrix
[0][2] + vector
[1]*matrix
[1][2] + vector
[2]*matrix
[2][2];
226 memcpy(vector
, result
, sizeof(result
));
230 static ALvoid
CalcSourceParams(ALCcontext
*ALContext
, ALsource
*ALSource
,
231 ALenum isMono
, ALenum OutputFormat
,
232 ALfloat
*drysend
, ALfloat
*wetsend
,
233 ALfloat
*pitch
, ALfloat
*drygainhf
,
236 ALfloat InnerAngle
,OuterAngle
,Angle
,Distance
,DryMix
,WetMix
=0.0f
;
237 ALfloat Direction
[3],Position
[3],SourceToListener
[3];
238 ALfloat MinVolume
,MaxVolume
,MinDist
,MaxDist
,Rolloff
,OuterGainHF
;
239 ALfloat ConeVolume
,SourceVolume
,PanningFB
,PanningLR
,ListenerGain
;
240 ALfloat U
[3],V
[3],N
[3];
241 ALfloat DopplerFactor
, DopplerVelocity
, flSpeedOfSound
, flMaxVelocity
;
242 ALfloat Matrix
[3][3];
243 ALfloat flAttenuation
;
244 ALfloat RoomAttenuation
;
245 ALfloat MetersPerUnit
;
247 ALfloat DryGainHF
= 1.0f
;
248 ALfloat WetGainHF
= 1.0f
;
251 //Get context properties
252 DopplerFactor
= ALContext
->DopplerFactor
* ALSource
->DopplerFactor
;
253 DopplerVelocity
= ALContext
->DopplerVelocity
;
254 flSpeedOfSound
= ALContext
->flSpeedOfSound
;
256 //Get listener properties
257 ListenerGain
= ALContext
->Listener
.Gain
;
258 MetersPerUnit
= ALContext
->Listener
.MetersPerUnit
;
260 //Get source properties
261 SourceVolume
= ALSource
->flGain
;
262 memcpy(Position
, ALSource
->vPosition
, sizeof(ALSource
->vPosition
));
263 memcpy(Direction
, ALSource
->vOrientation
, sizeof(ALSource
->vOrientation
));
264 MinVolume
= ALSource
->flMinGain
;
265 MaxVolume
= ALSource
->flMaxGain
;
266 MinDist
= ALSource
->flRefDistance
;
267 MaxDist
= ALSource
->flMaxDistance
;
268 Rolloff
= ALSource
->flRollOffFactor
;
269 InnerAngle
= ALSource
->flInnerAngle
;
270 OuterAngle
= ALSource
->flOuterAngle
;
271 OuterGainHF
= ALSource
->OuterGainHF
;
272 RoomRolloff
= ALSource
->RoomRolloffFactor
;
274 //Only apply 3D calculations for mono buffers
275 if(isMono
!= AL_FALSE
)
277 //1. Translate Listener to origin (convert to head relative)
278 // Note that Direction and SourceToListener are *not* transformed.
279 // SourceToListener is used with the source and listener velocities,
280 // which are untransformed, and Direction is used with SourceToListener
281 // for the sound cone
282 if(ALSource
->bHeadRelative
==AL_FALSE
)
284 // Build transform matrix
285 aluCrossproduct(ALContext
->Listener
.Forward
, ALContext
->Listener
.Up
, U
); // Right-vector
286 aluNormalize(U
); // Normalized Right-vector
287 memcpy(V
, ALContext
->Listener
.Up
, sizeof(V
)); // Up-vector
288 aluNormalize(V
); // Normalized Up-vector
289 memcpy(N
, ALContext
->Listener
.Forward
, sizeof(N
)); // At-vector
290 aluNormalize(N
); // Normalized At-vector
291 Matrix
[0][0] = U
[0]; Matrix
[0][1] = V
[0]; Matrix
[0][2] = -N
[0];
292 Matrix
[1][0] = U
[1]; Matrix
[1][1] = V
[1]; Matrix
[1][2] = -N
[1];
293 Matrix
[2][0] = U
[2]; Matrix
[2][1] = V
[2]; Matrix
[2][2] = -N
[2];
295 // Translate source position into listener space
296 Position
[0] -= ALContext
->Listener
.Position
[0];
297 Position
[1] -= ALContext
->Listener
.Position
[1];
298 Position
[2] -= ALContext
->Listener
.Position
[2];
300 SourceToListener
[0] = -Position
[0];
301 SourceToListener
[1] = -Position
[1];
302 SourceToListener
[2] = -Position
[2];
304 // Transform source position and direction into listener space
305 aluMatrixVector(Position
, Matrix
);
309 SourceToListener
[0] = -Position
[0];
310 SourceToListener
[1] = -Position
[1];
311 SourceToListener
[2] = -Position
[2];
313 aluNormalize(SourceToListener
);
314 aluNormalize(Direction
);
316 //2. Calculate distance attenuation
317 Distance
= aluSqrt(aluDotproduct(Position
, Position
));
319 if(ALSource
->Send
[0].Slot
)
321 if(ALSource
->Send
[0].Slot
->effect
.type
== AL_EFFECT_REVERB
)
322 RoomRolloff
+= ALSource
->Send
[0].Slot
->effect
.Reverb
.RoomRolloffFactor
;
325 flAttenuation
= 1.0f
;
326 RoomAttenuation
= 1.0f
;
327 switch (ALContext
->DistanceModel
)
329 case AL_INVERSE_DISTANCE_CLAMPED
:
330 Distance
=__max(Distance
,MinDist
);
331 Distance
=__min(Distance
,MaxDist
);
332 if (MaxDist
< MinDist
)
335 case AL_INVERSE_DISTANCE
:
338 if ((MinDist
+ (Rolloff
* (Distance
- MinDist
))) > 0.0f
)
339 flAttenuation
= MinDist
/ (MinDist
+ (Rolloff
* (Distance
- MinDist
)));
340 if ((MinDist
+ (RoomRolloff
* (Distance
- MinDist
))) > 0.0f
)
341 RoomAttenuation
= MinDist
/ (MinDist
+ (RoomRolloff
* (Distance
- MinDist
)));
345 case AL_LINEAR_DISTANCE_CLAMPED
:
346 Distance
=__max(Distance
,MinDist
);
347 Distance
=__min(Distance
,MaxDist
);
348 if (MaxDist
< MinDist
)
351 case AL_LINEAR_DISTANCE
:
352 Distance
=__min(Distance
,MaxDist
);
353 if (MaxDist
!= MinDist
)
355 flAttenuation
= 1.0f
- (Rolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
356 RoomAttenuation
= 1.0f
- (RoomRolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
360 case AL_EXPONENT_DISTANCE_CLAMPED
:
361 Distance
=__max(Distance
,MinDist
);
362 Distance
=__min(Distance
,MaxDist
);
363 if (MaxDist
< MinDist
)
366 case AL_EXPONENT_DISTANCE
:
367 if ((Distance
> 0.0f
) && (MinDist
> 0.0f
))
369 flAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -Rolloff
);
370 RoomAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -RoomRolloff
);
375 flAttenuation
= 1.0f
;
376 RoomAttenuation
= 1.0f
;
380 // Distance-based air absorption
381 if(ALSource
->AirAbsorptionFactor
> 0.0f
&& ALContext
->DistanceModel
!= AL_NONE
)
383 ALfloat dist
= Distance
-MinDist
;
386 if(dist
< 0.0f
) dist
= 0.0f
;
387 // Absorption calculation is done in dB
388 absorb
= (ALSource
->AirAbsorptionFactor
*AIRABSORBGAINDBHF
) *
389 (Distance
*MetersPerUnit
);
390 // Convert dB to linear gain before applying
391 absorb
= pow(0.5, absorb
/-6.0);
396 // Source Gain + Attenuation and clamp to Min/Max Gain
397 DryMix
= SourceVolume
* flAttenuation
;
398 DryMix
= __min(DryMix
,MaxVolume
);
399 DryMix
= __max(DryMix
,MinVolume
);
401 WetMix
= SourceVolume
* RoomAttenuation
;
402 WetMix
= __min(WetMix
,MaxVolume
);
403 WetMix
= __max(WetMix
,MinVolume
);
405 //3. Apply directional soundcones
406 Angle
= aluAcos(aluDotproduct(Direction
,SourceToListener
)) * 180.0f
/
408 if(Angle
>= InnerAngle
&& Angle
<= OuterAngle
)
410 ALfloat scale
= (Angle
-InnerAngle
) / (OuterAngle
-InnerAngle
);
411 ConeVolume
= (1.0f
+(ALSource
->flOuterGain
-1.0f
)*scale
);
412 DryMix
*= ConeVolume
;
413 if(ALSource
->WetGainAuto
)
414 WetMix
*= ConeVolume
;
415 if(ALSource
->DryGainHFAuto
)
416 DryGainHF
*= (1.0f
+(OuterGainHF
-1.0f
)*scale
);
417 if(ALSource
->WetGainHFAuto
)
418 WetGainHF
*= (1.0f
+(OuterGainHF
-1.0f
)*scale
);
420 else if(Angle
> OuterAngle
)
422 ConeVolume
= (1.0f
+(ALSource
->flOuterGain
-1.0f
));
423 DryMix
*= ConeVolume
;
424 if(ALSource
->WetGainAuto
)
425 WetMix
*= ConeVolume
;
426 if(ALSource
->DryGainHFAuto
)
427 DryGainHF
*= (1.0f
+(OuterGainHF
-1.0f
));
428 if(ALSource
->WetGainHFAuto
)
429 WetGainHF
*= (1.0f
+(OuterGainHF
-1.0f
));
432 //4. Calculate Velocity
433 if(DopplerFactor
!= 0.0f
)
435 ALfloat flVSS
, flVLS
= 0.0f
;
437 if(ALSource
->bHeadRelative
==AL_FALSE
)
438 flVLS
= aluDotproduct(ALContext
->Listener
.Velocity
, SourceToListener
);
439 flVSS
= aluDotproduct(ALSource
->vVelocity
, SourceToListener
);
441 flMaxVelocity
= (DopplerVelocity
* flSpeedOfSound
) / DopplerFactor
;
443 if (flVSS
>= flMaxVelocity
)
444 flVSS
= (flMaxVelocity
- 1.0f
);
445 else if (flVSS
<= -flMaxVelocity
)
446 flVSS
= -flMaxVelocity
+ 1.0f
;
448 if (flVLS
>= flMaxVelocity
)
449 flVLS
= (flMaxVelocity
- 1.0f
);
450 else if (flVLS
<= -flMaxVelocity
)
451 flVLS
= -flMaxVelocity
+ 1.0f
;
453 pitch
[0] = ALSource
->flPitch
*
454 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVLS
)) /
455 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVSS
));
458 pitch
[0] = ALSource
->flPitch
;
460 if(ALSource
->Send
[0].Slot
&&
461 ALSource
->Send
[0].Slot
->effect
.type
!= AL_EFFECT_NULL
)
463 if(ALSource
->Send
[0].Slot
->AuxSendAuto
)
465 // Apply minimal attenuation in place of missing statistical
467 WetMix
*= pow(DryMix
, 1.0f
/ 2.0f
);
471 // If the slot's auxilliary send auto is off, the data sent to the
472 // effect slot is the same as the dry path, sans filter effects
474 WetGainHF
= DryGainHF
;
477 // Note that this is really applied by the effect slot. However,
478 // it's easier (more optimal) to handle it here.
479 if(ALSource
->Send
[0].Slot
->effect
.type
== AL_EFFECT_REVERB
)
480 WetGainHF
*= ALSource
->Send
[0].Slot
->effect
.Reverb
.GainHF
;
488 //5. Apply filter gains and filters
489 switch(ALSource
->DirectFilter
.type
)
491 case AL_FILTER_LOWPASS
:
492 DryMix
*= ALSource
->DirectFilter
.Gain
;
493 DryGainHF
*= ALSource
->DirectFilter
.GainHF
;
497 switch(ALSource
->Send
[0].WetFilter
.type
)
499 case AL_FILTER_LOWPASS
:
500 WetMix
*= ALSource
->Send
[0].WetFilter
.Gain
;
501 WetGainHF
*= ALSource
->Send
[0].WetFilter
.GainHF
;
505 DryMix
*= ListenerGain
;
506 WetMix
*= ListenerGain
;
508 //6. Convert normalized position into pannings, then into channel volumes
509 aluNormalize(Position
);
510 switch(aluChannelsFromFormat(OutputFormat
))
514 PanningLR
= 0.5f
+ 0.5f
*Position
[0];
515 drysend
[FRONT_LEFT
] = DryMix
* aluSqrt(1.0f
-PanningLR
); //L Direct
516 drysend
[FRONT_RIGHT
] = DryMix
* aluSqrt( PanningLR
); //R Direct
517 drysend
[BACK_LEFT
] = 0.0f
;
518 drysend
[BACK_RIGHT
] = 0.0f
;
519 drysend
[SIDE_LEFT
] = 0.0f
;
520 drysend
[SIDE_RIGHT
] = 0.0f
;
523 /* TODO: Add center/lfe channel in spatial calculations? */
525 // Apply a scalar so each individual speaker has more weight
526 PanningLR
= 0.5f
+ (0.5f
*Position
[0]*1.41421356f
);
527 PanningLR
= __min(1.0f
, PanningLR
);
528 PanningLR
= __max(0.0f
, PanningLR
);
529 PanningFB
= 0.5f
+ (0.5f
*Position
[2]*1.41421356f
);
530 PanningFB
= __min(1.0f
, PanningFB
);
531 PanningFB
= __max(0.0f
, PanningFB
);
532 drysend
[FRONT_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
533 drysend
[FRONT_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
534 drysend
[BACK_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
535 drysend
[BACK_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
536 drysend
[SIDE_LEFT
] = 0.0f
;
537 drysend
[SIDE_RIGHT
] = 0.0f
;
541 PanningFB
= 1.0f
- fabs(Position
[2]*1.15470054f
);
542 PanningFB
= __min(1.0f
, PanningFB
);
543 PanningFB
= __max(0.0f
, PanningFB
);
544 PanningLR
= 0.5f
+ (0.5*Position
[0]*((1.0f
-PanningFB
)*2.0f
));
545 PanningLR
= __min(1.0f
, PanningLR
);
546 PanningLR
= __max(0.0f
, PanningLR
);
547 if(Position
[2] > 0.0f
)
549 drysend
[BACK_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
550 drysend
[BACK_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
551 drysend
[SIDE_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
552 drysend
[SIDE_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
553 drysend
[FRONT_LEFT
] = 0.0f
;
554 drysend
[FRONT_RIGHT
] = 0.0f
;
558 drysend
[FRONT_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
559 drysend
[FRONT_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
560 drysend
[SIDE_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
561 drysend
[SIDE_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
562 drysend
[BACK_LEFT
] = 0.0f
;
563 drysend
[BACK_RIGHT
] = 0.0f
;
570 // Update filter coefficients. Calculations based on the I3DL2 spec.
571 cw
= cos(2.0f
*3.141592654f
* LOWPASSFREQCUTOFF
/ ALContext
->Frequency
);
572 // We use four chained one-pole filters, so we need to take the fourth
573 // root of the squared gain, which is the same as the square root of
575 // Be careful with gains < 0.0001, as that causes the coefficient to
576 // head towards 1, which will flatten the signal
577 g
= aluSqrt(__max(DryGainHF
, 0.0001f
));
579 if(g
< 0.9999f
) // 1-epsilon
580 a
= (1 - g
*cw
- aluSqrt(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) / (1 - g
);
581 ALSource
->iirFilter
.coeff
= a
;
583 g
= aluSqrt(__max(WetGainHF
, 0.0001f
));
585 if(g
< 0.9999f
) // 1-epsilon
586 a
= (1 - g
*cw
- aluSqrt(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) / (1 - g
);
587 ALSource
->Send
[0].iirFilter
.coeff
= a
;
589 *drygainhf
= DryGainHF
;
590 *wetgainhf
= WetGainHF
;
594 //1. Multi-channel buffers always play "normal"
595 pitch
[0] = ALSource
->flPitch
;
597 drysend
[FRONT_LEFT
] = SourceVolume
* ListenerGain
;
598 drysend
[FRONT_RIGHT
] = SourceVolume
* ListenerGain
;
599 drysend
[SIDE_LEFT
] = SourceVolume
* ListenerGain
;
600 drysend
[SIDE_RIGHT
] = SourceVolume
* ListenerGain
;
601 drysend
[BACK_LEFT
] = SourceVolume
* ListenerGain
;
602 drysend
[BACK_RIGHT
] = SourceVolume
* ListenerGain
;
603 drysend
[CENTER
] = SourceVolume
* ListenerGain
;
604 drysend
[LFE
] = SourceVolume
* ListenerGain
;
608 *drygainhf
= DryGainHF
;
609 *wetgainhf
= WetGainHF
;
613 static __inline ALshort
lerp(ALshort val1
, ALshort val2
, ALint frac
)
615 return val1
+ (((val2
-val1
)*frac
)>>FRACTIONBITS
);
618 ALvoid
aluMixData(ALCcontext
*ALContext
,ALvoid
*buffer
,ALsizei size
,ALenum format
)
620 static float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
621 static float WetBuffer
[BUFFERSIZE
];
622 ALfloat newDrySend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
623 ALfloat newWetSend
= 0.0f
;
624 ALfloat DryGainHF
= 0.0f
;
625 ALfloat WetGainHF
= 0.0f
;
629 ALfloat dryGainStep
[OUTPUTCHANNELS
];
631 ALuint BlockAlign
,BufferSize
;
632 ALuint DataSize
=0,DataPosInt
=0,DataPosFrac
=0;
633 ALuint Channels
,Frequency
,ulExtraSamples
;
641 ALeffectslot
*ALEffectSlot
;
645 ALbufferlistitem
*BufferListItem
;
647 ALint64 DataSize64
,DataPos64
;
648 FILTER
*DryFilter
, *WetFilter
;
651 SuspendContext(ALContext
);
653 #if defined(HAVE_FESETROUND)
654 fpuState
= fegetround();
655 fesetround(FE_TOWARDZERO
);
656 #elif defined(HAVE__CONTROLFP)
657 fpuState
= _controlfp(0, 0);
658 _controlfp(_RC_CHOP
, _MCW_RC
);
663 //Figure output format variables
664 BlockAlign
= aluChannelsFromFormat(format
);
665 BlockAlign
*= aluBytesFromFormat(format
);
671 SamplesToDo
= min(size
, BUFFERSIZE
);
674 ALEffectSlot
= ALContext
->AuxiliaryEffectSlot
;
675 ALSource
= ALContext
->Source
;
676 rampLength
= ALContext
->Frequency
* MIN_RAMP_LENGTH
/ 1000;
684 rampLength
= max(rampLength
, SamplesToDo
);
686 //Clear mixing buffer
687 memset(WetBuffer
, 0, SamplesToDo
*sizeof(ALfloat
));
688 memset(DryBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
694 State
= ALSource
->state
;
696 while(State
== AL_PLAYING
&& j
< SamplesToDo
)
703 if((Buffer
= ALSource
->ulBufferID
))
705 ALBuffer
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(Buffer
);
707 Data
= ALBuffer
->data
;
708 Channels
= aluChannelsFromFormat(ALBuffer
->format
);
709 DataSize
= ALBuffer
->size
;
710 DataSize
/= Channels
* aluBytesFromFormat(ALBuffer
->format
);
711 Frequency
= ALBuffer
->frequency
;
712 DataPosInt
= ALSource
->position
;
713 DataPosFrac
= ALSource
->position_fraction
;
715 if(DataPosInt
>= DataSize
)
718 CalcSourceParams(ALContext
, ALSource
,
719 (Channels
==1) ? AL_TRUE
: AL_FALSE
,
720 format
, newDrySend
, &newWetSend
, &Pitch
,
721 &DryGainHF
, &WetGainHF
);
723 Pitch
= (Pitch
*Frequency
) / ALContext
->Frequency
;
726 DryFilter
= &ALSource
->iirFilter
;
727 WetFilter
= &ALSource
->Send
[0].iirFilter
;
728 DrySend
= ALSource
->DryGains
;
729 WetSend
= &ALSource
->WetGain
;
731 //Compute the gain steps for each output channel
732 if(ALSource
->FirstStart
&& DataPosInt
== 0 && DataPosFrac
== 0)
734 for(i
= 0;i
< OUTPUTCHANNELS
;i
++)
736 DrySend
[i
] = newDrySend
[i
];
739 *WetSend
= newWetSend
;
744 for(i
= 0;i
< OUTPUTCHANNELS
;i
++)
745 dryGainStep
[i
] = (newDrySend
[i
]-DrySend
[i
]) / rampLength
;
746 wetGainStep
= (newWetSend
-(*WetSend
)) / rampLength
;
748 ALSource
->FirstStart
= AL_FALSE
;
750 //Compute 18.14 fixed point step
751 if(Pitch
> (float)MAX_PITCH
)
752 Pitch
= (float)MAX_PITCH
;
753 increment
= (ALint
)(Pitch
*(ALfloat
)(1L<<FRACTIONBITS
));
755 increment
= (1<<FRACTIONBITS
);
757 //Figure out how many samples we can mix.
758 DataSize64
= DataSize
;
759 DataSize64
<<= FRACTIONBITS
;
760 DataPos64
= DataPosInt
;
761 DataPos64
<<= FRACTIONBITS
;
762 DataPos64
+= DataPosFrac
;
763 BufferSize
= (ALuint
)((DataSize64
-DataPos64
+(increment
-1)) / increment
);
765 BufferListItem
= ALSource
->queue
;
766 for(loop
= 0; loop
< ALSource
->BuffersPlayed
; loop
++)
769 BufferListItem
= BufferListItem
->next
;
773 if (BufferListItem
->next
)
775 ALbuffer
*NextBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
);
776 if(NextBuf
&& NextBuf
->data
)
778 ulExtraSamples
= min(NextBuf
->size
, (ALint
)(ALBuffer
->padding
*Channels
*2));
779 memcpy(&Data
[DataSize
*Channels
], NextBuf
->data
, ulExtraSamples
);
782 else if (ALSource
->bLooping
)
784 ALbuffer
*NextBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
);
785 if (NextBuf
&& NextBuf
->data
)
787 ulExtraSamples
= min(NextBuf
->size
, (ALint
)(ALBuffer
->padding
*Channels
*2));
788 memcpy(&Data
[DataSize
*Channels
], NextBuf
->data
, ulExtraSamples
);
792 memset(&Data
[DataSize
*Channels
], 0, (ALBuffer
->padding
*Channels
*2));
794 BufferSize
= min(BufferSize
, (SamplesToDo
-j
));
796 //Actual sample mixing loop
798 Data
+= DataPosInt
*Channels
;
801 for(i
= 0;i
< OUTPUTCHANNELS
;i
++)
802 DrySend
[i
] += dryGainStep
[i
];
803 *WetSend
+= wetGainStep
;
807 ALfloat sample
, outsamp
;
808 //First order interpolator
809 sample
= lerp(Data
[k
], Data
[k
+1], DataPosFrac
);
811 //Direct path final mix buffer and panning
812 outsamp
= lpFilter(DryFilter
, sample
);
813 DryBuffer
[j
][FRONT_LEFT
] += outsamp
*DrySend
[FRONT_LEFT
];
814 DryBuffer
[j
][FRONT_RIGHT
] += outsamp
*DrySend
[FRONT_RIGHT
];
815 DryBuffer
[j
][SIDE_LEFT
] += outsamp
*DrySend
[SIDE_LEFT
];
816 DryBuffer
[j
][SIDE_RIGHT
] += outsamp
*DrySend
[SIDE_RIGHT
];
817 DryBuffer
[j
][BACK_LEFT
] += outsamp
*DrySend
[BACK_LEFT
];
818 DryBuffer
[j
][BACK_RIGHT
] += outsamp
*DrySend
[BACK_RIGHT
];
819 //Room path final mix buffer and panning
820 outsamp
= lpFilter(WetFilter
, sample
);
821 WetBuffer
[j
] += outsamp
*(*WetSend
);
825 ALfloat samp1
, samp2
;
826 //First order interpolator (front left)
827 samp1
= lerp(Data
[k
*Channels
], Data
[(k
+1)*Channels
], DataPosFrac
);
828 DryBuffer
[j
][FRONT_LEFT
] += samp1
*DrySend
[FRONT_LEFT
];
829 //First order interpolator (front right)
830 samp2
= lerp(Data
[k
*Channels
+1], Data
[(k
+1)*Channels
+1], DataPosFrac
);
831 DryBuffer
[j
][FRONT_RIGHT
] += samp2
*DrySend
[FRONT_RIGHT
];
839 //First order interpolator (center)
840 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
841 DryBuffer
[j
][CENTER
] += value
*DrySend
[CENTER
];
844 //First order interpolator (lfe)
845 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
846 DryBuffer
[j
][LFE
] += value
*DrySend
[LFE
];
849 //First order interpolator (back left)
850 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
851 DryBuffer
[j
][BACK_LEFT
] += value
*DrySend
[BACK_LEFT
];
853 //First order interpolator (back right)
854 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
855 DryBuffer
[j
][BACK_RIGHT
] += value
*DrySend
[BACK_RIGHT
];
859 //First order interpolator (side left)
860 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
861 DryBuffer
[j
][SIDE_LEFT
] += value
*DrySend
[SIDE_LEFT
];
863 //First order interpolator (side right)
864 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
865 DryBuffer
[j
][SIDE_RIGHT
] += value
*DrySend
[SIDE_RIGHT
];
869 else if(DuplicateStereo
)
871 //Duplicate stereo channels on the back speakers
872 DryBuffer
[j
][BACK_LEFT
] += samp1
*DrySend
[BACK_LEFT
];
873 DryBuffer
[j
][BACK_RIGHT
] += samp2
*DrySend
[BACK_RIGHT
];
876 DataPosFrac
+= increment
;
877 k
+= DataPosFrac
>>FRACTIONBITS
;
878 DataPosFrac
&= FRACTIONMASK
;
884 ALSource
->position
= DataPosInt
;
885 ALSource
->position_fraction
= DataPosFrac
;
890 //Handle looping sources
891 if(!Buffer
|| DataPosInt
>= DataSize
)
896 Looping
= ALSource
->bLooping
;
897 if(ALSource
->BuffersPlayed
< (ALSource
->BuffersInQueue
-1))
899 BufferListItem
= ALSource
->queue
;
900 for(loop
= 0; loop
<= ALSource
->BuffersPlayed
; loop
++)
905 BufferListItem
->bufferstate
= PROCESSED
;
906 BufferListItem
= BufferListItem
->next
;
910 ALSource
->ulBufferID
= BufferListItem
->buffer
;
911 ALSource
->position
= DataPosInt
-DataSize
;
912 ALSource
->position_fraction
= DataPosFrac
;
913 ALSource
->BuffersPlayed
++;
920 ALSource
->state
= AL_STOPPED
;
921 ALSource
->inuse
= AL_FALSE
;
922 ALSource
->BuffersPlayed
= ALSource
->BuffersInQueue
;
923 BufferListItem
= ALSource
->queue
;
924 while(BufferListItem
!= NULL
)
926 BufferListItem
->bufferstate
= PROCESSED
;
927 BufferListItem
= BufferListItem
->next
;
929 ALSource
->position
= DataSize
;
930 ALSource
->position_fraction
= 0;
936 ALSource
->state
= AL_PLAYING
;
937 ALSource
->inuse
= AL_TRUE
;
938 ALSource
->play
= AL_TRUE
;
939 ALSource
->BuffersPlayed
= 0;
940 BufferListItem
= ALSource
->queue
;
941 while(BufferListItem
!= NULL
)
943 BufferListItem
->bufferstate
= PENDING
;
944 BufferListItem
= BufferListItem
->next
;
946 ALSource
->ulBufferID
= ALSource
->queue
->buffer
;
948 if(ALSource
->BuffersInQueue
== 1)
949 ALSource
->position
= DataPosInt
%DataSize
;
951 ALSource
->position
= DataPosInt
-DataSize
;
952 ALSource
->position_fraction
= DataPosFrac
;
959 State
= ALSource
->state
;
962 ALSource
= ALSource
->next
;
965 // effect slot processing
968 if(ALEffectSlot
->effect
.type
== AL_EFFECT_REVERB
)
969 VerbProcess(ALEffectSlot
->ReverbState
, SamplesToDo
, WetBuffer
, DryBuffer
);
971 ALEffectSlot
= ALEffectSlot
->next
;
974 //Post processing loop
977 case AL_FORMAT_MONO8
:
978 for(i
= 0;i
< SamplesToDo
;i
++)
980 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
]+DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
981 buffer
= ((ALubyte
*)buffer
) + 1;
984 case AL_FORMAT_STEREO8
:
985 if(ALContext
&& ALContext
->bs2b
)
987 for(i
= 0;i
< SamplesToDo
;i
++)
990 samples
[0] = DryBuffer
[i
][FRONT_LEFT
];
991 samples
[1] = DryBuffer
[i
][FRONT_RIGHT
];
992 bs2b_cross_feed(ALContext
->bs2b
, samples
);
993 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(samples
[0])>>8)+128);
994 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(samples
[1])>>8)+128);
995 buffer
= ((ALubyte
*)buffer
) + 2;
1000 for(i
= 0;i
< SamplesToDo
;i
++)
1002 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1003 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1004 buffer
= ((ALubyte
*)buffer
) + 2;
1008 case AL_FORMAT_QUAD8
:
1009 for(i
= 0;i
< SamplesToDo
;i
++)
1011 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1012 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1013 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1014 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1015 buffer
= ((ALubyte
*)buffer
) + 4;
1018 case AL_FORMAT_51CHN8
:
1019 for(i
= 0;i
< SamplesToDo
;i
++)
1021 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1022 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1023 #ifdef _WIN32 /* Of course, Windows can't use the same ordering... */
1024 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1025 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1026 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1027 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1029 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1030 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1031 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1032 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1034 buffer
= ((ALubyte
*)buffer
) + 6;
1037 case AL_FORMAT_61CHN8
:
1038 for(i
= 0;i
< SamplesToDo
;i
++)
1040 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1041 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1043 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1044 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1045 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1047 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1048 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1049 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1051 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_LEFT
])>>8)+128);
1052 ((ALubyte
*)buffer
)[6] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_RIGHT
])>>8)+128);
1053 buffer
= ((ALubyte
*)buffer
) + 7;
1056 case AL_FORMAT_71CHN8
:
1057 for(i
= 0;i
< SamplesToDo
;i
++)
1059 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1060 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1062 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1063 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1064 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1065 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1067 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1068 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1069 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1070 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1072 ((ALubyte
*)buffer
)[6] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_LEFT
])>>8)+128);
1073 ((ALubyte
*)buffer
)[7] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_RIGHT
])>>8)+128);
1074 buffer
= ((ALubyte
*)buffer
) + 8;
1078 case AL_FORMAT_MONO16
:
1079 for(i
= 0;i
< SamplesToDo
;i
++)
1081 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]+DryBuffer
[i
][FRONT_RIGHT
]);
1082 buffer
= ((ALshort
*)buffer
) + 1;
1085 case AL_FORMAT_STEREO16
:
1086 if(ALContext
&& ALContext
->bs2b
)
1088 for(i
= 0;i
< SamplesToDo
;i
++)
1091 samples
[0] = DryBuffer
[i
][FRONT_LEFT
];
1092 samples
[1] = DryBuffer
[i
][FRONT_RIGHT
];
1093 bs2b_cross_feed(ALContext
->bs2b
, samples
);
1094 ((ALshort
*)buffer
)[0] = aluF2S(samples
[0]);
1095 ((ALshort
*)buffer
)[1] = aluF2S(samples
[1]);
1096 buffer
= ((ALshort
*)buffer
) + 2;
1101 for(i
= 0;i
< SamplesToDo
;i
++)
1103 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1104 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1105 buffer
= ((ALshort
*)buffer
) + 2;
1109 case AL_FORMAT_QUAD16
:
1110 for(i
= 0;i
< SamplesToDo
;i
++)
1112 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1113 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1114 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1115 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1116 buffer
= ((ALshort
*)buffer
) + 4;
1119 case AL_FORMAT_51CHN16
:
1120 for(i
= 0;i
< SamplesToDo
;i
++)
1122 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1123 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1125 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][CENTER
]);
1126 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][LFE
]);
1127 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1128 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1130 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1131 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1132 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][CENTER
]);
1133 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][LFE
]);
1135 buffer
= ((ALshort
*)buffer
) + 6;
1138 case AL_FORMAT_61CHN16
:
1139 for(i
= 0;i
< SamplesToDo
;i
++)
1141 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1142 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1144 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][LFE
]);
1145 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1146 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1148 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1149 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1150 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][LFE
]);
1152 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][SIDE_LEFT
]);
1153 ((ALshort
*)buffer
)[6] = aluF2S(DryBuffer
[i
][SIDE_RIGHT
]);
1154 buffer
= ((ALshort
*)buffer
) + 7;
1157 case AL_FORMAT_71CHN16
:
1158 for(i
= 0;i
< SamplesToDo
;i
++)
1160 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1161 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1163 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][CENTER
]);
1164 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][LFE
]);
1165 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1166 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1168 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1169 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1170 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][CENTER
]);
1171 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][LFE
]);
1173 ((ALshort
*)buffer
)[6] = aluF2S(DryBuffer
[i
][SIDE_LEFT
]);
1174 ((ALshort
*)buffer
)[7] = aluF2S(DryBuffer
[i
][SIDE_RIGHT
]);
1175 buffer
= ((ALshort
*)buffer
) + 8;
1183 size
-= SamplesToDo
;
1186 #if defined(HAVE_FESETROUND)
1187 fesetround(fpuState
);
1188 #elif defined(HAVE__CONTROLFP)
1189 _controlfp(fpuState
, 0xfffff);
1192 ProcessContext(ALContext
);