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"
37 #if defined(HAVE_STDINT_H)
39 typedef int64_t ALint64
;
40 #elif defined(HAVE___INT64)
41 typedef __int64 ALint64
;
42 #elif (SIZEOF_LONG == 8)
44 #elif (SIZEOF_LONG_LONG == 8)
45 typedef long long ALint64
;
49 #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
51 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
55 #define aluAcos(x) ((ALfloat)acosf((float)(x)))
57 #define aluAcos(x) ((ALfloat)acos((double)(x)))
61 #if defined(max) && !defined(__max)
64 #if defined(min) && !defined(__min)
68 #define BUFFERSIZE 24000
69 #define FRACTIONBITS 14
70 #define FRACTIONMASK ((1L<<FRACTIONBITS)-1)
71 #define MAX_PITCH 65536
73 /* Minimum ramp length in milliseconds. The value below was chosen to
74 * adequately reduce clicks and pops from harsh gain changes. */
75 #define MIN_RAMP_LENGTH 16
77 ALboolean DuplicateStereo
= AL_FALSE
;
79 /* NOTE: The AL_FORMAT_REAR* enums aren't handled here be cause they're
80 * converted to AL_FORMAT_QUAD* when loaded */
81 __inline ALuint
aluBytesFromFormat(ALenum format
)
86 case AL_FORMAT_STEREO8
:
87 case AL_FORMAT_QUAD8_LOKI
:
89 case AL_FORMAT_51CHN8
:
90 case AL_FORMAT_61CHN8
:
91 case AL_FORMAT_71CHN8
:
94 case AL_FORMAT_MONO16
:
95 case AL_FORMAT_STEREO16
:
96 case AL_FORMAT_QUAD16_LOKI
:
97 case AL_FORMAT_QUAD16
:
98 case AL_FORMAT_51CHN16
:
99 case AL_FORMAT_61CHN16
:
100 case AL_FORMAT_71CHN16
:
103 case AL_FORMAT_MONO_FLOAT32
:
104 case AL_FORMAT_STEREO_FLOAT32
:
105 case AL_FORMAT_QUAD32
:
106 case AL_FORMAT_51CHN32
:
107 case AL_FORMAT_61CHN32
:
108 case AL_FORMAT_71CHN32
:
116 __inline ALuint
aluChannelsFromFormat(ALenum format
)
120 case AL_FORMAT_MONO8
:
121 case AL_FORMAT_MONO16
:
122 case AL_FORMAT_MONO_FLOAT32
:
125 case AL_FORMAT_STEREO8
:
126 case AL_FORMAT_STEREO16
:
127 case AL_FORMAT_STEREO_FLOAT32
:
130 case AL_FORMAT_QUAD8_LOKI
:
131 case AL_FORMAT_QUAD16_LOKI
:
132 case AL_FORMAT_QUAD8
:
133 case AL_FORMAT_QUAD16
:
134 case AL_FORMAT_QUAD32
:
137 case AL_FORMAT_51CHN8
:
138 case AL_FORMAT_51CHN16
:
139 case AL_FORMAT_51CHN32
:
142 case AL_FORMAT_61CHN8
:
143 case AL_FORMAT_61CHN16
:
144 case AL_FORMAT_61CHN32
:
147 case AL_FORMAT_71CHN8
:
148 case AL_FORMAT_71CHN16
:
149 case AL_FORMAT_71CHN32
:
158 static __inline ALfloat
lpFilter(FILTER
*iir
, ALfloat input
)
160 ALfloat
*history
= iir
->history
;
161 ALfloat a
= iir
->coeff
;
162 ALfloat output
= input
;
164 output
= output
+ (history
[0]-output
)*a
;
166 output
= output
+ (history
[1]-output
)*a
;
168 output
= output
+ (history
[2]-output
)*a
;
170 output
= output
+ (history
[3]-output
)*a
;
177 static __inline ALshort
aluF2S(ALfloat Value
)
182 i
= __min( 32767, i
);
183 i
= __max(-32768, i
);
187 static __inline ALvoid
aluCrossproduct(ALfloat
*inVector1
,ALfloat
*inVector2
,ALfloat
*outVector
)
189 outVector
[0] = inVector1
[1]*inVector2
[2] - inVector1
[2]*inVector2
[1];
190 outVector
[1] = inVector1
[2]*inVector2
[0] - inVector1
[0]*inVector2
[2];
191 outVector
[2] = inVector1
[0]*inVector2
[1] - inVector1
[1]*inVector2
[0];
194 static __inline ALfloat
aluDotproduct(ALfloat
*inVector1
,ALfloat
*inVector2
)
196 return inVector1
[0]*inVector2
[0] + inVector1
[1]*inVector2
[1] +
197 inVector1
[2]*inVector2
[2];
200 static __inline ALvoid
aluNormalize(ALfloat
*inVector
)
202 ALfloat length
, inverse_length
;
204 length
= aluSqrt(aluDotproduct(inVector
, inVector
));
207 inverse_length
= 1.0f
/length
;
208 inVector
[0] *= inverse_length
;
209 inVector
[1] *= inverse_length
;
210 inVector
[2] *= inverse_length
;
214 static __inline ALvoid
aluMatrixVector(ALfloat
*vector
,ALfloat matrix
[3][3])
218 result
[0] = vector
[0]*matrix
[0][0] + vector
[1]*matrix
[1][0] + vector
[2]*matrix
[2][0];
219 result
[1] = vector
[0]*matrix
[0][1] + vector
[1]*matrix
[1][1] + vector
[2]*matrix
[2][1];
220 result
[2] = vector
[0]*matrix
[0][2] + vector
[1]*matrix
[1][2] + vector
[2]*matrix
[2][2];
221 memcpy(vector
, result
, sizeof(result
));
225 static ALvoid
CalcSourceParams(ALCcontext
*ALContext
, ALsource
*ALSource
,
226 ALenum isMono
, ALenum OutputFormat
,
227 ALfloat
*drysend
, ALfloat
*wetsend
,
228 ALfloat
*pitch
, ALfloat
*drygainhf
,
231 ALfloat InnerAngle
,OuterAngle
,Angle
,Distance
,DryMix
,WetMix
=0.0f
;
232 ALfloat Direction
[3],Position
[3],SourceToListener
[3];
233 ALfloat MinVolume
,MaxVolume
,MinDist
,MaxDist
,Rolloff
,OuterGainHF
;
234 ALfloat ConeVolume
,SourceVolume
,PanningFB
,PanningLR
,ListenerGain
;
235 ALfloat U
[3],V
[3],N
[3];
236 ALfloat DopplerFactor
, DopplerVelocity
, flSpeedOfSound
, flMaxVelocity
;
237 ALfloat Matrix
[3][3];
238 ALfloat flAttenuation
;
239 ALfloat RoomAttenuation
;
240 ALfloat MetersPerUnit
;
242 ALfloat DryGainHF
= 1.0f
;
243 ALfloat WetGainHF
= 1.0f
;
246 //Get context properties
247 DopplerFactor
= ALContext
->DopplerFactor
* ALSource
->DopplerFactor
;
248 DopplerVelocity
= ALContext
->DopplerVelocity
;
249 flSpeedOfSound
= ALContext
->flSpeedOfSound
;
251 //Get listener properties
252 ListenerGain
= ALContext
->Listener
.Gain
;
253 MetersPerUnit
= ALContext
->Listener
.MetersPerUnit
;
255 //Get source properties
256 SourceVolume
= ALSource
->flGain
;
257 memcpy(Position
, ALSource
->vPosition
, sizeof(ALSource
->vPosition
));
258 memcpy(Direction
, ALSource
->vOrientation
, sizeof(ALSource
->vOrientation
));
259 MinVolume
= ALSource
->flMinGain
;
260 MaxVolume
= ALSource
->flMaxGain
;
261 MinDist
= ALSource
->flRefDistance
;
262 MaxDist
= ALSource
->flMaxDistance
;
263 Rolloff
= ALSource
->flRollOffFactor
;
264 InnerAngle
= ALSource
->flInnerAngle
;
265 OuterAngle
= ALSource
->flOuterAngle
;
266 OuterGainHF
= ALSource
->OuterGainHF
;
267 RoomRolloff
= ALSource
->RoomRolloffFactor
;
269 //Only apply 3D calculations for mono buffers
270 if(isMono
!= AL_FALSE
)
272 //1. Translate Listener to origin (convert to head relative)
273 // Note that Direction and SourceToListener are *not* transformed.
274 // SourceToListener is used with the source and listener velocities,
275 // which are untransformed, and Direction is used with SourceToListener
276 // for the sound cone
277 if(ALSource
->bHeadRelative
==AL_FALSE
)
279 // Build transform matrix
280 aluCrossproduct(ALContext
->Listener
.Forward
, ALContext
->Listener
.Up
, U
); // Right-vector
281 aluNormalize(U
); // Normalized Right-vector
282 memcpy(V
, ALContext
->Listener
.Up
, sizeof(V
)); // Up-vector
283 aluNormalize(V
); // Normalized Up-vector
284 memcpy(N
, ALContext
->Listener
.Forward
, sizeof(N
)); // At-vector
285 aluNormalize(N
); // Normalized At-vector
286 Matrix
[0][0] = U
[0]; Matrix
[0][1] = V
[0]; Matrix
[0][2] = -N
[0];
287 Matrix
[1][0] = U
[1]; Matrix
[1][1] = V
[1]; Matrix
[1][2] = -N
[1];
288 Matrix
[2][0] = U
[2]; Matrix
[2][1] = V
[2]; Matrix
[2][2] = -N
[2];
290 // Translate source position into listener space
291 Position
[0] -= ALContext
->Listener
.Position
[0];
292 Position
[1] -= ALContext
->Listener
.Position
[1];
293 Position
[2] -= ALContext
->Listener
.Position
[2];
295 SourceToListener
[0] = -Position
[0];
296 SourceToListener
[1] = -Position
[1];
297 SourceToListener
[2] = -Position
[2];
299 // Transform source position and direction into listener space
300 aluMatrixVector(Position
, Matrix
);
304 SourceToListener
[0] = -Position
[0];
305 SourceToListener
[1] = -Position
[1];
306 SourceToListener
[2] = -Position
[2];
308 aluNormalize(SourceToListener
);
309 aluNormalize(Direction
);
311 //2. Calculate distance attenuation
312 Distance
= aluSqrt(aluDotproduct(Position
, Position
));
314 if(ALSource
->Send
[0].Slot
)
316 if(ALSource
->Send
[0].Slot
->effect
.type
== AL_EFFECT_REVERB
)
317 RoomRolloff
+= ALSource
->Send
[0].Slot
->effect
.Reverb
.RoomRolloffFactor
;
320 flAttenuation
= 1.0f
;
321 RoomAttenuation
= 1.0f
;
322 switch (ALContext
->DistanceModel
)
324 case AL_INVERSE_DISTANCE_CLAMPED
:
325 Distance
=__max(Distance
,MinDist
);
326 Distance
=__min(Distance
,MaxDist
);
327 if (MaxDist
< MinDist
)
330 case AL_INVERSE_DISTANCE
:
333 if ((MinDist
+ (Rolloff
* (Distance
- MinDist
))) > 0.0f
)
334 flAttenuation
= MinDist
/ (MinDist
+ (Rolloff
* (Distance
- MinDist
)));
335 if ((MinDist
+ (RoomRolloff
* (Distance
- MinDist
))) > 0.0f
)
336 RoomAttenuation
= MinDist
/ (MinDist
+ (RoomRolloff
* (Distance
- MinDist
)));
340 case AL_LINEAR_DISTANCE_CLAMPED
:
341 Distance
=__max(Distance
,MinDist
);
342 Distance
=__min(Distance
,MaxDist
);
343 if (MaxDist
< MinDist
)
346 case AL_LINEAR_DISTANCE
:
347 Distance
=__min(Distance
,MaxDist
);
348 if (MaxDist
!= MinDist
)
350 flAttenuation
= 1.0f
- (Rolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
351 RoomAttenuation
= 1.0f
- (RoomRolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
355 case AL_EXPONENT_DISTANCE_CLAMPED
:
356 Distance
=__max(Distance
,MinDist
);
357 Distance
=__min(Distance
,MaxDist
);
358 if (MaxDist
< MinDist
)
361 case AL_EXPONENT_DISTANCE
:
362 if ((Distance
> 0.0f
) && (MinDist
> 0.0f
))
364 flAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -Rolloff
);
365 RoomAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -RoomRolloff
);
370 flAttenuation
= 1.0f
;
371 RoomAttenuation
= 1.0f
;
375 // Distance-based air absorption
376 if(ALSource
->AirAbsorptionFactor
> 0.0f
&& ALContext
->DistanceModel
!= AL_NONE
)
378 ALfloat dist
= Distance
-MinDist
;
381 if(dist
< 0.0f
) dist
= 0.0f
;
382 // Absorption calculation is done in dB
383 absorb
= (ALSource
->AirAbsorptionFactor
*AIRABSORBGAINDBHF
) *
384 (Distance
*MetersPerUnit
);
385 // Convert dB to linear gain before applying
386 absorb
= pow(0.5, absorb
/-6.0);
391 // Source Gain + Attenuation and clamp to Min/Max Gain
392 DryMix
= SourceVolume
* flAttenuation
;
393 DryMix
= __min(DryMix
,MaxVolume
);
394 DryMix
= __max(DryMix
,MinVolume
);
396 WetMix
= SourceVolume
* RoomAttenuation
;
397 WetMix
= __min(WetMix
,MaxVolume
);
398 WetMix
= __max(WetMix
,MinVolume
);
400 //3. Apply directional soundcones
401 Angle
= aluAcos(aluDotproduct(Direction
,SourceToListener
)) * 180.0f
/
403 if(Angle
>= InnerAngle
&& Angle
<= OuterAngle
)
405 ALfloat scale
= (Angle
-InnerAngle
) / (OuterAngle
-InnerAngle
);
406 ConeVolume
= (1.0f
+(ALSource
->flOuterGain
-1.0f
)*scale
);
407 DryMix
*= ConeVolume
;
408 if(ALSource
->WetGainAuto
)
409 WetMix
*= ConeVolume
;
410 if(ALSource
->DryGainHFAuto
)
411 DryGainHF
*= (1.0f
+(OuterGainHF
-1.0f
)*scale
);
412 if(ALSource
->WetGainHFAuto
)
413 WetGainHF
*= (1.0f
+(OuterGainHF
-1.0f
)*scale
);
415 else if(Angle
> OuterAngle
)
417 ConeVolume
= (1.0f
+(ALSource
->flOuterGain
-1.0f
));
418 DryMix
*= ConeVolume
;
419 if(ALSource
->WetGainAuto
)
420 WetMix
*= ConeVolume
;
421 if(ALSource
->DryGainHFAuto
)
422 DryGainHF
*= (1.0f
+(OuterGainHF
-1.0f
));
423 if(ALSource
->WetGainHFAuto
)
424 WetGainHF
*= (1.0f
+(OuterGainHF
-1.0f
));
427 //4. Calculate Velocity
428 if(DopplerFactor
!= 0.0f
)
430 ALfloat flVSS
, flVLS
= 0.0f
;
432 if(ALSource
->bHeadRelative
==AL_FALSE
)
433 flVLS
= aluDotproduct(ALContext
->Listener
.Velocity
, SourceToListener
);
434 flVSS
= aluDotproduct(ALSource
->vVelocity
, SourceToListener
);
436 flMaxVelocity
= (DopplerVelocity
* flSpeedOfSound
) / DopplerFactor
;
438 if (flVSS
>= flMaxVelocity
)
439 flVSS
= (flMaxVelocity
- 1.0f
);
440 else if (flVSS
<= -flMaxVelocity
)
441 flVSS
= -flMaxVelocity
+ 1.0f
;
443 if (flVLS
>= flMaxVelocity
)
444 flVLS
= (flMaxVelocity
- 1.0f
);
445 else if (flVLS
<= -flMaxVelocity
)
446 flVLS
= -flMaxVelocity
+ 1.0f
;
448 pitch
[0] = ALSource
->flPitch
*
449 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVLS
)) /
450 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVSS
));
453 pitch
[0] = ALSource
->flPitch
;
455 if(ALSource
->Send
[0].Slot
&&
456 ALSource
->Send
[0].Slot
->effect
.type
!= AL_EFFECT_NULL
)
458 // If the slot's auxilliary send auto is off, the data sent to the
459 // effect slot is the same as the dry path, sans filter effects
460 if(!ALSource
->Send
[0].Slot
->AuxSendAuto
)
463 WetGainHF
= DryGainHF
;
466 // Note that these are really applied by the effect slot. However,
467 // it's easier to handle them here (particularly the lowpass
468 // filter). Applying the gain to the individual sources going to
469 // the effect slot should have the same effect as applying the gain
470 // to the accumulated sources in the effect slot.
471 // vol1*g + vol2*g + ... voln*g = (vol1+vol2+...voln)*g
472 WetMix
*= ALSource
->Send
[0].Slot
->Gain
;
473 if(ALSource
->Send
[0].Slot
->effect
.type
== AL_EFFECT_REVERB
)
475 WetMix
*= ALSource
->Send
[0].Slot
->effect
.Reverb
.Gain
;
476 WetGainHF
*= ALSource
->Send
[0].Slot
->effect
.Reverb
.GainHF
;
477 WetGainHF
*= pow(ALSource
->Send
[0].Slot
->effect
.Reverb
.AirAbsorptionGainHF
,
478 Distance
* MetersPerUnit
);
487 //5. Apply filter gains and filters
488 switch(ALSource
->DirectFilter
.type
)
490 case AL_FILTER_LOWPASS
:
491 DryMix
*= ALSource
->DirectFilter
.Gain
;
492 DryGainHF
*= ALSource
->DirectFilter
.GainHF
;
496 switch(ALSource
->Send
[0].WetFilter
.type
)
498 case AL_FILTER_LOWPASS
:
499 WetMix
*= ALSource
->Send
[0].WetFilter
.Gain
;
500 WetGainHF
*= ALSource
->Send
[0].WetFilter
.GainHF
;
504 DryMix
*= ListenerGain
;
505 WetMix
*= ListenerGain
;
507 //6. Convert normalized position into pannings, then into channel volumes
508 aluNormalize(Position
);
509 switch(aluChannelsFromFormat(OutputFormat
))
513 PanningLR
= 0.5f
+ 0.5f
*Position
[0];
514 drysend
[FRONT_LEFT
] = DryMix
* aluSqrt(1.0f
-PanningLR
); //L Direct
515 drysend
[FRONT_RIGHT
] = DryMix
* aluSqrt( PanningLR
); //R Direct
516 drysend
[BACK_LEFT
] = 0.0f
;
517 drysend
[BACK_RIGHT
] = 0.0f
;
518 drysend
[SIDE_LEFT
] = 0.0f
;
519 drysend
[SIDE_RIGHT
] = 0.0f
;
522 /* TODO: Add center/lfe channel in spatial calculations? */
524 // Apply a scalar so each individual speaker has more weight
525 PanningLR
= 0.5f
+ (0.5f
*Position
[0]*1.41421356f
);
526 PanningLR
= __min(1.0f
, PanningLR
);
527 PanningLR
= __max(0.0f
, PanningLR
);
528 PanningFB
= 0.5f
+ (0.5f
*Position
[2]*1.41421356f
);
529 PanningFB
= __min(1.0f
, PanningFB
);
530 PanningFB
= __max(0.0f
, PanningFB
);
531 drysend
[FRONT_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
532 drysend
[FRONT_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
533 drysend
[BACK_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
534 drysend
[BACK_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
535 drysend
[SIDE_LEFT
] = 0.0f
;
536 drysend
[SIDE_RIGHT
] = 0.0f
;
540 PanningFB
= 1.0f
- fabs(Position
[2]*1.15470054f
);
541 PanningFB
= __min(1.0f
, PanningFB
);
542 PanningFB
= __max(0.0f
, PanningFB
);
543 PanningLR
= 0.5f
+ (0.5*Position
[0]*((1.0f
-PanningFB
)*2.0f
));
544 PanningLR
= __min(1.0f
, PanningLR
);
545 PanningLR
= __max(0.0f
, PanningLR
);
546 if(Position
[2] > 0.0f
)
548 drysend
[BACK_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
549 drysend
[BACK_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
550 drysend
[SIDE_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
551 drysend
[SIDE_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
552 drysend
[FRONT_LEFT
] = 0.0f
;
553 drysend
[FRONT_RIGHT
] = 0.0f
;
557 drysend
[FRONT_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
));
558 drysend
[FRONT_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
));
559 drysend
[SIDE_LEFT
] = DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
));
560 drysend
[SIDE_RIGHT
] = DryMix
* aluSqrt(( PanningLR
)*( PanningFB
));
561 drysend
[BACK_LEFT
] = 0.0f
;
562 drysend
[BACK_RIGHT
] = 0.0f
;
569 // Update filter coefficients. Calculations based on the I3DL2 spec.
570 cw
= cos(2.0f
*3.141592654f
* LOWPASSFREQCUTOFF
/ ALContext
->Frequency
);
571 // We use four chained one-pole filters, so we need to take the fourth
572 // root of the squared gain, which is the same as the square root of
574 // Be careful with gains < 0.0001, as that causes the coefficient to
575 // head towards 1, which will flatten the signal
576 g
= aluSqrt(__max(DryGainHF
, 0.0001f
));
578 if(g
< 0.9999f
) // 1-epsilon
579 a
= (1 - g
*cw
- aluSqrt(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) / (1 - g
);
580 ALSource
->iirFilter
.coeff
= a
;
582 g
= aluSqrt(__max(WetGainHF
, 0.0001f
));
584 if(g
< 0.9999f
) // 1-epsilon
585 a
= (1 - g
*cw
- aluSqrt(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) / (1 - g
);
586 ALSource
->Send
[0].iirFilter
.coeff
= a
;
588 *drygainhf
= DryGainHF
;
589 *wetgainhf
= WetGainHF
;
593 //1. Multi-channel buffers always play "normal"
594 pitch
[0] = ALSource
->flPitch
;
596 drysend
[FRONT_LEFT
] = SourceVolume
* ListenerGain
;
597 drysend
[FRONT_RIGHT
] = SourceVolume
* ListenerGain
;
598 drysend
[SIDE_LEFT
] = SourceVolume
* ListenerGain
;
599 drysend
[SIDE_RIGHT
] = SourceVolume
* ListenerGain
;
600 drysend
[BACK_LEFT
] = SourceVolume
* ListenerGain
;
601 drysend
[BACK_RIGHT
] = SourceVolume
* ListenerGain
;
602 drysend
[CENTER
] = SourceVolume
* ListenerGain
;
603 drysend
[LFE
] = SourceVolume
* ListenerGain
;
607 *drygainhf
= DryGainHF
;
608 *wetgainhf
= WetGainHF
;
612 static __inline ALshort
lerp(ALshort val1
, ALshort val2
, ALint frac
)
614 return val1
+ (((val2
-val1
)*frac
)>>FRACTIONBITS
);
617 ALvoid
aluMixData(ALCcontext
*ALContext
,ALvoid
*buffer
,ALsizei size
,ALenum format
)
619 static float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
620 static float WetBuffer
[BUFFERSIZE
];
621 ALfloat newDrySend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
622 ALfloat newWetSend
= 0.0f
;
623 ALfloat DryGainHF
= 0.0f
;
624 ALfloat WetGainHF
= 0.0f
;
628 ALfloat dryGainStep
[OUTPUTCHANNELS
];
630 ALuint BlockAlign
,BufferSize
;
631 ALuint DataSize
=0,DataPosInt
=0,DataPosFrac
=0;
632 ALuint Channels
,Frequency
,ulExtraSamples
;
640 ALeffectslot
*ALEffectSlot
;
644 ALbufferlistitem
*BufferListItem
;
646 ALint64 DataSize64
,DataPos64
;
647 FILTER
*DryFilter
, *WetFilter
;
650 SuspendContext(ALContext
);
652 #if defined(HAVE_FESETROUND)
653 fpuState
= fegetround();
654 fesetround(FE_TOWARDZERO
);
655 #elif defined(HAVE__CONTROLFP)
656 fpuState
= _controlfp(0, 0);
657 _controlfp(_RC_CHOP
, _MCW_RC
);
662 //Figure output format variables
663 BlockAlign
= aluChannelsFromFormat(format
);
664 BlockAlign
*= aluBytesFromFormat(format
);
670 SamplesToDo
= min(size
, BUFFERSIZE
);
673 ALEffectSlot
= ALContext
->AuxiliaryEffectSlot
;
674 ALSource
= ALContext
->Source
;
675 rampLength
= ALContext
->Frequency
* MIN_RAMP_LENGTH
/ 1000;
683 rampLength
= max(rampLength
, SamplesToDo
);
685 //Clear mixing buffer
686 memset(WetBuffer
, 0, SamplesToDo
*sizeof(ALfloat
));
687 memset(DryBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
693 State
= ALSource
->state
;
695 while(State
== AL_PLAYING
&& j
< SamplesToDo
)
702 if((Buffer
= ALSource
->ulBufferID
))
704 ALBuffer
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(Buffer
);
706 Data
= ALBuffer
->data
;
707 Channels
= aluChannelsFromFormat(ALBuffer
->format
);
708 DataSize
= ALBuffer
->size
;
709 DataSize
/= Channels
* aluBytesFromFormat(ALBuffer
->format
);
710 Frequency
= ALBuffer
->frequency
;
711 DataPosInt
= ALSource
->position
;
712 DataPosFrac
= ALSource
->position_fraction
;
714 if(DataPosInt
>= DataSize
)
717 CalcSourceParams(ALContext
, ALSource
,
718 (Channels
==1) ? AL_TRUE
: AL_FALSE
,
719 format
, newDrySend
, &newWetSend
, &Pitch
,
720 &DryGainHF
, &WetGainHF
);
722 Pitch
= (Pitch
*Frequency
) / ALContext
->Frequency
;
725 DryFilter
= &ALSource
->iirFilter
;
726 WetFilter
= &ALSource
->Send
[0].iirFilter
;
727 DrySend
= ALSource
->DryGains
;
728 WetSend
= &ALSource
->WetGain
;
730 //Compute the gain steps for each output channel
731 for(i
= 0;i
< OUTPUTCHANNELS
;i
++)
732 dryGainStep
[i
] = (newDrySend
[i
]-DrySend
[i
]) / rampLength
;
733 wetGainStep
= (newWetSend
-(*WetSend
)) / rampLength
;
735 //Compute 18.14 fixed point step
736 if(Pitch
> (float)MAX_PITCH
)
737 Pitch
= (float)MAX_PITCH
;
738 increment
= (ALint
)(Pitch
*(ALfloat
)(1L<<FRACTIONBITS
));
740 increment
= (1<<FRACTIONBITS
);
742 //Figure out how many samples we can mix.
743 DataSize64
= DataSize
;
744 DataSize64
<<= FRACTIONBITS
;
745 DataPos64
= DataPosInt
;
746 DataPos64
<<= FRACTIONBITS
;
747 DataPos64
+= DataPosFrac
;
748 BufferSize
= (ALuint
)((DataSize64
-DataPos64
+(increment
-1)) / increment
);
750 BufferListItem
= ALSource
->queue
;
751 for(loop
= 0; loop
< ALSource
->BuffersPlayed
; loop
++)
754 BufferListItem
= BufferListItem
->next
;
758 if (BufferListItem
->next
)
760 ALbuffer
*NextBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
);
761 if(NextBuf
&& NextBuf
->data
)
763 ulExtraSamples
= min(NextBuf
->size
, (ALint
)(ALBuffer
->padding
*Channels
*2));
764 memcpy(&Data
[DataSize
*Channels
], NextBuf
->data
, ulExtraSamples
);
767 else if (ALSource
->bLooping
)
769 ALbuffer
*NextBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
);
770 if (NextBuf
&& NextBuf
->data
)
772 ulExtraSamples
= min(NextBuf
->size
, (ALint
)(ALBuffer
->padding
*Channels
*2));
773 memcpy(&Data
[DataSize
*Channels
], NextBuf
->data
, ulExtraSamples
);
777 memset(&Data
[DataSize
*Channels
], 0, (ALBuffer
->padding
*Channels
*2));
779 BufferSize
= min(BufferSize
, (SamplesToDo
-j
));
781 //Actual sample mixing loop
783 Data
+= DataPosInt
*Channels
;
786 for(i
= 0;i
< OUTPUTCHANNELS
;i
++)
787 DrySend
[i
] += dryGainStep
[i
];
788 *WetSend
+= wetGainStep
;
792 ALfloat sample
, outsamp
;
793 //First order interpolator
794 sample
= lerp(Data
[k
], Data
[k
+1], DataPosFrac
);
796 //Direct path final mix buffer and panning
797 outsamp
= lpFilter(DryFilter
, sample
);
798 DryBuffer
[j
][FRONT_LEFT
] += outsamp
*DrySend
[FRONT_LEFT
];
799 DryBuffer
[j
][FRONT_RIGHT
] += outsamp
*DrySend
[FRONT_RIGHT
];
800 DryBuffer
[j
][SIDE_LEFT
] += outsamp
*DrySend
[SIDE_LEFT
];
801 DryBuffer
[j
][SIDE_RIGHT
] += outsamp
*DrySend
[SIDE_RIGHT
];
802 DryBuffer
[j
][BACK_LEFT
] += outsamp
*DrySend
[BACK_LEFT
];
803 DryBuffer
[j
][BACK_RIGHT
] += outsamp
*DrySend
[BACK_RIGHT
];
804 //Room path final mix buffer and panning
805 outsamp
= lpFilter(WetFilter
, sample
);
806 WetBuffer
[j
] += outsamp
*(*WetSend
);
810 ALfloat samp1
, samp2
;
811 //First order interpolator (front left)
812 samp1
= lerp(Data
[k
*Channels
], Data
[(k
+1)*Channels
], DataPosFrac
);
813 DryBuffer
[j
][FRONT_LEFT
] += samp1
*DrySend
[FRONT_LEFT
];
814 //First order interpolator (front right)
815 samp2
= lerp(Data
[k
*Channels
+1], Data
[(k
+1)*Channels
+1], DataPosFrac
);
816 DryBuffer
[j
][FRONT_RIGHT
] += samp2
*DrySend
[FRONT_RIGHT
];
824 //First order interpolator (center)
825 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
826 DryBuffer
[j
][CENTER
] += value
*DrySend
[CENTER
];
829 //First order interpolator (lfe)
830 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
831 DryBuffer
[j
][LFE
] += value
*DrySend
[LFE
];
834 //First order interpolator (back left)
835 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
836 DryBuffer
[j
][BACK_LEFT
] += value
*DrySend
[BACK_LEFT
];
838 //First order interpolator (back right)
839 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
840 DryBuffer
[j
][BACK_RIGHT
] += value
*DrySend
[BACK_RIGHT
];
844 //First order interpolator (side left)
845 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
846 DryBuffer
[j
][SIDE_LEFT
] += value
*DrySend
[SIDE_LEFT
];
848 //First order interpolator (side right)
849 value
= lerp(Data
[k
*Channels
+i
], Data
[(k
+1)*Channels
+i
], DataPosFrac
);
850 DryBuffer
[j
][SIDE_RIGHT
] += value
*DrySend
[SIDE_RIGHT
];
854 else if(DuplicateStereo
)
856 //Duplicate stereo channels on the back speakers
857 DryBuffer
[j
][BACK_LEFT
] += samp1
*DrySend
[BACK_LEFT
];
858 DryBuffer
[j
][BACK_RIGHT
] += samp2
*DrySend
[BACK_RIGHT
];
861 DataPosFrac
+= increment
;
862 k
+= DataPosFrac
>>FRACTIONBITS
;
863 DataPosFrac
&= FRACTIONMASK
;
869 ALSource
->position
= DataPosInt
;
870 ALSource
->position_fraction
= DataPosFrac
;
875 //Handle looping sources
876 if(!Buffer
|| DataPosInt
>= DataSize
)
881 Looping
= ALSource
->bLooping
;
882 if(ALSource
->BuffersPlayed
< (ALSource
->BuffersInQueue
-1))
884 BufferListItem
= ALSource
->queue
;
885 for(loop
= 0; loop
<= ALSource
->BuffersPlayed
; loop
++)
890 BufferListItem
->bufferstate
= PROCESSED
;
891 BufferListItem
= BufferListItem
->next
;
895 ALSource
->ulBufferID
= BufferListItem
->buffer
;
896 ALSource
->position
= DataPosInt
-DataSize
;
897 ALSource
->position_fraction
= DataPosFrac
;
898 ALSource
->BuffersPlayed
++;
905 ALSource
->state
= AL_STOPPED
;
906 ALSource
->inuse
= AL_FALSE
;
907 ALSource
->BuffersPlayed
= ALSource
->BuffersInQueue
;
908 BufferListItem
= ALSource
->queue
;
909 while(BufferListItem
!= NULL
)
911 BufferListItem
->bufferstate
= PROCESSED
;
912 BufferListItem
= BufferListItem
->next
;
914 ALSource
->position
= DataSize
;
915 ALSource
->position_fraction
= 0;
921 ALSource
->state
= AL_PLAYING
;
922 ALSource
->inuse
= AL_TRUE
;
923 ALSource
->play
= AL_TRUE
;
924 ALSource
->BuffersPlayed
= 0;
925 BufferListItem
= ALSource
->queue
;
926 while(BufferListItem
!= NULL
)
928 BufferListItem
->bufferstate
= PENDING
;
929 BufferListItem
= BufferListItem
->next
;
931 ALSource
->ulBufferID
= ALSource
->queue
->buffer
;
933 if(ALSource
->BuffersInQueue
== 1)
934 ALSource
->position
= DataPosInt
%DataSize
;
936 ALSource
->position
= DataPosInt
-DataSize
;
937 ALSource
->position_fraction
= DataPosFrac
;
944 State
= ALSource
->state
;
947 ALSource
= ALSource
->next
;
950 // effect slot processing
953 if(ALEffectSlot
->effect
.type
== AL_EFFECT_REVERB
)
955 ALfloat
*DelayBuffer
= ALEffectSlot
->ReverbBuffer
;
956 ALuint Pos
= ALEffectSlot
->ReverbPos
;
957 ALuint LatePos
= ALEffectSlot
->ReverbLatePos
;
958 ALuint ReflectPos
= ALEffectSlot
->ReverbReflectPos
;
959 ALuint Length
= ALEffectSlot
->ReverbLength
;
960 ALfloat DecayGain
= ALEffectSlot
->ReverbDecayGain
;
961 ALfloat DecayHFRatio
= ALEffectSlot
->effect
.Reverb
.DecayHFRatio
;
962 ALfloat ReflectGain
= ALEffectSlot
->effect
.Reverb
.ReflectionsGain
;
963 ALfloat LateReverbGain
= ALEffectSlot
->effect
.Reverb
.LateReverbGain
;
964 ALfloat sample
, lowsample
;
966 WetFilter
= &ALEffectSlot
->iirFilter
;
967 for(i
= 0;i
< SamplesToDo
;i
++)
969 DelayBuffer
[Pos
] = WetBuffer
[i
];
971 sample
= DelayBuffer
[ReflectPos
] * ReflectGain
;
973 DelayBuffer
[LatePos
] *= LateReverbGain
;
975 Pos
= (Pos
+1) % Length
;
976 lowsample
= lpFilter(WetFilter
, DelayBuffer
[Pos
]);
977 lowsample
+= (DelayBuffer
[Pos
]-lowsample
) * DecayHFRatio
;
979 DelayBuffer
[LatePos
] += lowsample
* DecayGain
;
981 sample
+= DelayBuffer
[LatePos
];
983 DryBuffer
[i
][FRONT_LEFT
] += sample
;
984 DryBuffer
[i
][FRONT_RIGHT
] += sample
;
985 DryBuffer
[i
][SIDE_LEFT
] += sample
;
986 DryBuffer
[i
][SIDE_RIGHT
] += sample
;
987 DryBuffer
[i
][BACK_LEFT
] += sample
;
988 DryBuffer
[i
][BACK_RIGHT
] += sample
;
990 LatePos
= (LatePos
+1) % Length
;
991 ReflectPos
= (ReflectPos
+1) % Length
;
994 ALEffectSlot
->ReverbPos
= Pos
;
995 ALEffectSlot
->ReverbLatePos
= LatePos
;
996 ALEffectSlot
->ReverbReflectPos
= ReflectPos
;
999 ALEffectSlot
= ALEffectSlot
->next
;
1002 //Post processing loop
1005 case AL_FORMAT_MONO8
:
1006 for(i
= 0;i
< SamplesToDo
;i
++)
1008 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
]+DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1009 buffer
= ((ALubyte
*)buffer
) + 1;
1012 case AL_FORMAT_STEREO8
:
1013 if(ALContext
&& ALContext
->bs2b
)
1015 for(i
= 0;i
< SamplesToDo
;i
++)
1018 samples
[0] = DryBuffer
[i
][FRONT_LEFT
];
1019 samples
[1] = DryBuffer
[i
][FRONT_RIGHT
];
1020 bs2b_cross_feed(ALContext
->bs2b
, samples
);
1021 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(samples
[0])>>8)+128);
1022 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(samples
[1])>>8)+128);
1023 buffer
= ((ALubyte
*)buffer
) + 2;
1028 for(i
= 0;i
< SamplesToDo
;i
++)
1030 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1031 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1032 buffer
= ((ALubyte
*)buffer
) + 2;
1036 case AL_FORMAT_QUAD8
:
1037 for(i
= 0;i
< SamplesToDo
;i
++)
1039 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1040 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1041 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1042 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1043 buffer
= ((ALubyte
*)buffer
) + 4;
1046 case AL_FORMAT_51CHN8
:
1047 for(i
= 0;i
< SamplesToDo
;i
++)
1049 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1050 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1051 #ifdef _WIN32 /* Of course, Windows can't use the same ordering... */
1052 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1053 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1054 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1055 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1057 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1058 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1059 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1060 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1062 buffer
= ((ALubyte
*)buffer
) + 6;
1065 case AL_FORMAT_61CHN8
:
1066 for(i
= 0;i
< SamplesToDo
;i
++)
1068 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1069 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1071 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1072 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1073 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1075 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1076 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1077 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1079 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_LEFT
])>>8)+128);
1080 ((ALubyte
*)buffer
)[6] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_RIGHT
])>>8)+128);
1081 buffer
= ((ALubyte
*)buffer
) + 7;
1084 case AL_FORMAT_71CHN8
:
1085 for(i
= 0;i
< SamplesToDo
;i
++)
1087 ((ALubyte
*)buffer
)[0] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_LEFT
])>>8)+128);
1088 ((ALubyte
*)buffer
)[1] = (ALubyte
)((aluF2S(DryBuffer
[i
][FRONT_RIGHT
])>>8)+128);
1090 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1091 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1092 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1093 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1095 ((ALubyte
*)buffer
)[2] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_LEFT
])>>8)+128);
1096 ((ALubyte
*)buffer
)[3] = (ALubyte
)((aluF2S(DryBuffer
[i
][BACK_RIGHT
])>>8)+128);
1097 ((ALubyte
*)buffer
)[4] = (ALubyte
)((aluF2S(DryBuffer
[i
][CENTER
])>>8)+128);
1098 ((ALubyte
*)buffer
)[5] = (ALubyte
)((aluF2S(DryBuffer
[i
][LFE
])>>8)+128);
1100 ((ALubyte
*)buffer
)[6] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_LEFT
])>>8)+128);
1101 ((ALubyte
*)buffer
)[7] = (ALubyte
)((aluF2S(DryBuffer
[i
][SIDE_RIGHT
])>>8)+128);
1102 buffer
= ((ALubyte
*)buffer
) + 8;
1106 case AL_FORMAT_MONO16
:
1107 for(i
= 0;i
< SamplesToDo
;i
++)
1109 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]+DryBuffer
[i
][FRONT_RIGHT
]);
1110 buffer
= ((ALshort
*)buffer
) + 1;
1113 case AL_FORMAT_STEREO16
:
1114 if(ALContext
&& ALContext
->bs2b
)
1116 for(i
= 0;i
< SamplesToDo
;i
++)
1119 samples
[0] = DryBuffer
[i
][FRONT_LEFT
];
1120 samples
[1] = DryBuffer
[i
][FRONT_RIGHT
];
1121 bs2b_cross_feed(ALContext
->bs2b
, samples
);
1122 ((ALshort
*)buffer
)[0] = aluF2S(samples
[0]);
1123 ((ALshort
*)buffer
)[1] = aluF2S(samples
[1]);
1124 buffer
= ((ALshort
*)buffer
) + 2;
1129 for(i
= 0;i
< SamplesToDo
;i
++)
1131 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1132 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1133 buffer
= ((ALshort
*)buffer
) + 2;
1137 case AL_FORMAT_QUAD16
:
1138 for(i
= 0;i
< SamplesToDo
;i
++)
1140 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1141 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1142 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1143 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1144 buffer
= ((ALshort
*)buffer
) + 4;
1147 case AL_FORMAT_51CHN16
:
1148 for(i
= 0;i
< SamplesToDo
;i
++)
1150 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1151 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1153 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][CENTER
]);
1154 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][LFE
]);
1155 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1156 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1158 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1159 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1160 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][CENTER
]);
1161 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][LFE
]);
1163 buffer
= ((ALshort
*)buffer
) + 6;
1166 case AL_FORMAT_61CHN16
:
1167 for(i
= 0;i
< SamplesToDo
;i
++)
1169 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1170 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1172 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][LFE
]);
1173 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1174 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1176 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1177 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1178 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][LFE
]);
1180 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][SIDE_LEFT
]);
1181 ((ALshort
*)buffer
)[6] = aluF2S(DryBuffer
[i
][SIDE_RIGHT
]);
1182 buffer
= ((ALshort
*)buffer
) + 7;
1185 case AL_FORMAT_71CHN16
:
1186 for(i
= 0;i
< SamplesToDo
;i
++)
1188 ((ALshort
*)buffer
)[0] = aluF2S(DryBuffer
[i
][FRONT_LEFT
]);
1189 ((ALshort
*)buffer
)[1] = aluF2S(DryBuffer
[i
][FRONT_RIGHT
]);
1191 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][CENTER
]);
1192 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][LFE
]);
1193 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1194 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1196 ((ALshort
*)buffer
)[2] = aluF2S(DryBuffer
[i
][BACK_LEFT
]);
1197 ((ALshort
*)buffer
)[3] = aluF2S(DryBuffer
[i
][BACK_RIGHT
]);
1198 ((ALshort
*)buffer
)[4] = aluF2S(DryBuffer
[i
][CENTER
]);
1199 ((ALshort
*)buffer
)[5] = aluF2S(DryBuffer
[i
][LFE
]);
1201 ((ALshort
*)buffer
)[6] = aluF2S(DryBuffer
[i
][SIDE_LEFT
]);
1202 ((ALshort
*)buffer
)[7] = aluF2S(DryBuffer
[i
][SIDE_RIGHT
]);
1203 buffer
= ((ALshort
*)buffer
) + 8;
1211 size
-= SamplesToDo
;
1214 #if defined(HAVE_FESETROUND)
1215 fesetround(fpuState
);
1216 #elif defined(HAVE__CONTROLFP)
1217 _controlfp(fpuState
, 0xfffff);
1220 ProcessContext(ALContext
);