Implement a new reverb effect
[openal-soft.git] / Alc / ALu.c
blob1f755621dff11d8aef3026c53e0d2ddf8cbb342f
1 /**
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
23 #include "config.h"
25 #include <math.h>
26 #include "alMain.h"
27 #include "AL/al.h"
28 #include "AL/alc.h"
29 #include "alSource.h"
30 #include "alBuffer.h"
31 #include "alThunk.h"
32 #include "alListener.h"
33 #include "alAuxEffectSlot.h"
34 #include "alu.h"
35 #include "bs2b.h"
36 #include "alReverb.h"
38 #if defined (HAVE_FLOAT_H)
39 #include <float.h>
40 #endif
42 #if defined(HAVE_STDINT_H)
43 #include <stdint.h>
44 typedef int64_t ALint64;
45 #elif defined(HAVE___INT64)
46 typedef __int64 ALint64;
47 #elif (SIZEOF_LONG == 8)
48 typedef long ALint64;
49 #elif (SIZEOF_LONG_LONG == 8)
50 typedef long long ALint64;
51 #endif
53 #ifdef HAVE_SQRTF
54 #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
55 #else
56 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
57 #endif
59 #ifdef HAVE_ACOSF
60 #define aluAcos(x) ((ALfloat)acosf((float)(x)))
61 #else
62 #define aluAcos(x) ((ALfloat)acos((double)(x)))
63 #endif
65 // fixes for mingw32.
66 #if defined(max) && !defined(__max)
67 #define __max max
68 #endif
69 #if defined(min) && !defined(__min)
70 #define __min min
71 #endif
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)
88 switch(format)
90 case AL_FORMAT_MONO8:
91 case AL_FORMAT_STEREO8:
92 case AL_FORMAT_QUAD8_LOKI:
93 case AL_FORMAT_QUAD8:
94 case AL_FORMAT_51CHN8:
95 case AL_FORMAT_61CHN8:
96 case AL_FORMAT_71CHN8:
97 return 1;
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:
106 return 2;
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:
114 return 4;
116 default:
117 return 0;
121 __inline ALuint aluChannelsFromFormat(ALenum format)
123 switch(format)
125 case AL_FORMAT_MONO8:
126 case AL_FORMAT_MONO16:
127 case AL_FORMAT_MONO_FLOAT32:
128 return 1;
130 case AL_FORMAT_STEREO8:
131 case AL_FORMAT_STEREO16:
132 case AL_FORMAT_STEREO_FLOAT32:
133 return 2;
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:
140 return 4;
142 case AL_FORMAT_51CHN8:
143 case AL_FORMAT_51CHN16:
144 case AL_FORMAT_51CHN32:
145 return 6;
147 case AL_FORMAT_61CHN8:
148 case AL_FORMAT_61CHN16:
149 case AL_FORMAT_61CHN32:
150 return 7;
152 case AL_FORMAT_71CHN8:
153 case AL_FORMAT_71CHN16:
154 case AL_FORMAT_71CHN32:
155 return 8;
157 default:
158 return 0;
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;
170 history[0] = output;
171 output = output + (history[1]-output)*a;
172 history[1] = output;
173 output = output + (history[2]-output)*a;
174 history[2] = output;
175 output = output + (history[3]-output)*a;
176 history[3] = output;
178 return output;
182 static __inline ALshort aluF2S(ALfloat Value)
184 ALint i;
186 i = (ALint)Value;
187 i = __min( 32767, i);
188 i = __max(-32768, i);
189 return ((ALshort)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));
210 if(length != 0.0f)
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])
221 ALfloat result[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,
234 ALfloat *wetgainhf)
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;
246 ALfloat RoomRolloff;
247 ALfloat DryGainHF = 1.0f;
248 ALfloat WetGainHF = 1.0f;
249 ALfloat cw, a, g;
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);
307 else
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)
333 break;
334 //fall-through
335 case AL_INVERSE_DISTANCE:
336 if (MinDist > 0.0f)
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)));
343 break;
345 case AL_LINEAR_DISTANCE_CLAMPED:
346 Distance=__max(Distance,MinDist);
347 Distance=__min(Distance,MaxDist);
348 if (MaxDist < MinDist)
349 break;
350 //fall-through
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));
358 break;
360 case AL_EXPONENT_DISTANCE_CLAMPED:
361 Distance=__max(Distance,MinDist);
362 Distance=__min(Distance,MaxDist);
363 if (MaxDist < MinDist)
364 break;
365 //fall-through
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);
372 break;
374 case AL_NONE:
375 flAttenuation = 1.0f;
376 RoomAttenuation = 1.0f;
377 break;
380 // Distance-based air absorption
381 if(ALSource->AirAbsorptionFactor > 0.0f && ALContext->DistanceModel != AL_NONE)
383 ALfloat dist = Distance-MinDist;
384 ALfloat absorb;
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);
392 DryGainHF *= absorb;
393 WetGainHF *= absorb;
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 /
407 3.141592654f;
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));
457 else
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
466 // reverb model.
467 WetMix *= pow(DryMix, 1.0f / 2.0f);
469 else
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
473 WetMix = DryMix;
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;
482 else
484 WetMix = 0.0f;
485 WetGainHF = 1.0f;
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;
494 break;
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;
502 break;
505 DryMix *= ListenerGain;
506 WetMix *= ListenerGain;
508 //6. Convert normalized position into pannings, then into channel volumes
509 aluNormalize(Position);
510 switch(aluChannelsFromFormat(OutputFormat))
512 case 1:
513 case 2:
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;
521 break;
522 case 4:
523 /* TODO: Add center/lfe channel in spatial calculations? */
524 case 6:
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;
538 break;
539 case 7:
540 case 8:
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;
556 else
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;
565 default:
566 break;
568 *wetsend = WetMix;
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
574 // the base gain.
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));
578 a = 0.0f;
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));
584 a = 0.0f;
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;
592 else
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;
605 *wetsend = 0.0f;
606 WetGainHF = 1.0f;
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;
626 ALfloat *DrySend;
627 ALfloat *WetSend;
628 ALuint rampLength;
629 ALfloat dryGainStep[OUTPUTCHANNELS];
630 ALfloat wetGainStep;
631 ALuint BlockAlign,BufferSize;
632 ALuint DataSize=0,DataPosInt=0,DataPosFrac=0;
633 ALuint Channels,Frequency,ulExtraSamples;
634 ALfloat Pitch;
635 ALint Looping,State;
636 ALint increment;
637 ALuint Buffer;
638 ALuint SamplesToDo;
639 ALsource *ALSource;
640 ALbuffer *ALBuffer;
641 ALeffectslot *ALEffectSlot;
642 ALfloat value;
643 ALshort *Data;
644 ALuint i,j,k;
645 ALbufferlistitem *BufferListItem;
646 ALuint loop;
647 ALint64 DataSize64,DataPos64;
648 FILTER *DryFilter, *WetFilter;
649 int fpuState;
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);
659 #else
660 (void)fpuState;
661 #endif
663 //Figure output format variables
664 BlockAlign = aluChannelsFromFormat(format);
665 BlockAlign *= aluBytesFromFormat(format);
667 size /= BlockAlign;
668 while(size > 0)
670 //Setup variables
671 SamplesToDo = min(size, BUFFERSIZE);
672 if(ALContext)
674 ALEffectSlot = ALContext->AuxiliaryEffectSlot;
675 ALSource = ALContext->Source;
676 rampLength = ALContext->Frequency * MIN_RAMP_LENGTH / 1000;
678 else
680 ALEffectSlot = NULL;
681 ALSource = NULL;
682 rampLength = 0;
684 rampLength = max(rampLength, SamplesToDo);
686 //Clear mixing buffer
687 memset(WetBuffer, 0, SamplesToDo*sizeof(ALfloat));
688 memset(DryBuffer, 0, SamplesToDo*OUTPUTCHANNELS*sizeof(ALfloat));
690 //Actual mixing loop
691 while(ALSource)
693 j = 0;
694 State = ALSource->state;
696 while(State == AL_PLAYING && j < SamplesToDo)
698 DataSize = 0;
699 DataPosInt = 0;
700 DataPosFrac = 0;
702 //Get buffer info
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)
716 goto skipmix;
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;
725 //Get source info
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];
737 dryGainStep[i] = 0;
739 *WetSend = newWetSend;
740 wetGainStep = 0;
742 else
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));
754 if(increment <= 0)
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++)
768 if(BufferListItem)
769 BufferListItem = BufferListItem->next;
771 if (BufferListItem)
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);
791 else
792 memset(&Data[DataSize*Channels], 0, (ALBuffer->padding*Channels*2));
794 BufferSize = min(BufferSize, (SamplesToDo-j));
796 //Actual sample mixing loop
797 k = 0;
798 Data += DataPosInt*Channels;
799 while(BufferSize--)
801 for(i = 0;i < OUTPUTCHANNELS;i++)
802 DrySend[i] += dryGainStep[i];
803 *WetSend += wetGainStep;
805 if(Channels==1)
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);
823 else
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];
832 if(Channels >= 4)
834 int i = 2;
835 if(Channels >= 6)
837 if(Channels != 7)
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];
842 i++;
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];
847 i++;
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];
852 i++;
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];
856 i++;
857 if(Channels >= 7)
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];
862 i++;
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];
866 i++;
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;
879 j++;
881 DataPosInt += k;
883 //Update source info
884 ALSource->position = DataPosInt;
885 ALSource->position_fraction = DataPosFrac;
887 skipmix: ;
890 //Handle looping sources
891 if(!Buffer || DataPosInt >= DataSize)
893 //queueing
894 if(ALSource->queue)
896 Looping = ALSource->bLooping;
897 if(ALSource->BuffersPlayed < (ALSource->BuffersInQueue-1))
899 BufferListItem = ALSource->queue;
900 for(loop = 0; loop <= ALSource->BuffersPlayed; loop++)
902 if(BufferListItem)
904 if(!Looping)
905 BufferListItem->bufferstate = PROCESSED;
906 BufferListItem = BufferListItem->next;
909 if(BufferListItem)
910 ALSource->ulBufferID = BufferListItem->buffer;
911 ALSource->position = DataPosInt-DataSize;
912 ALSource->position_fraction = DataPosFrac;
913 ALSource->BuffersPlayed++;
915 else
917 if(!Looping)
919 /* alSourceStop */
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;
932 else
934 /* alSourceRewind */
935 /* alSourcePlay */
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;
950 else
951 ALSource->position = DataPosInt-DataSize;
952 ALSource->position_fraction = DataPosFrac;
958 //Get source state
959 State = ALSource->state;
962 ALSource = ALSource->next;
965 // effect slot processing
966 while(ALEffectSlot)
968 if(ALEffectSlot->effect.type == AL_EFFECT_REVERB)
969 VerbProcess(ALEffectSlot->ReverbState, SamplesToDo, WetBuffer, DryBuffer);
971 ALEffectSlot = ALEffectSlot->next;
974 //Post processing loop
975 switch(format)
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;
983 break;
984 case AL_FORMAT_STEREO8:
985 if(ALContext && ALContext->bs2b)
987 for(i = 0;i < SamplesToDo;i++)
989 float samples[2];
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;
998 else
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;
1007 break;
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;
1017 break;
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);
1028 #else
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);
1033 #endif
1034 buffer = ((ALubyte*)buffer) + 6;
1036 break;
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);
1042 #ifdef _WIN32
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);
1046 #else
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);
1050 #endif
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;
1055 break;
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);
1061 #ifdef _WIN32
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);
1066 #else
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);
1071 #endif
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;
1076 break;
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;
1084 break;
1085 case AL_FORMAT_STEREO16:
1086 if(ALContext && ALContext->bs2b)
1088 for(i = 0;i < SamplesToDo;i++)
1090 float samples[2];
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;
1099 else
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;
1108 break;
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;
1118 break;
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]);
1124 #ifdef _WIN32
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]);
1129 #else
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]);
1134 #endif
1135 buffer = ((ALshort*)buffer) + 6;
1137 break;
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]);
1143 #ifdef _WIN32
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]);
1147 #else
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]);
1151 #endif
1152 ((ALshort*)buffer)[5] = aluF2S(DryBuffer[i][SIDE_LEFT]);
1153 ((ALshort*)buffer)[6] = aluF2S(DryBuffer[i][SIDE_RIGHT]);
1154 buffer = ((ALshort*)buffer) + 7;
1156 break;
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]);
1162 #ifdef _WIN32
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]);
1167 #else
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]);
1172 #endif
1173 ((ALshort*)buffer)[6] = aluF2S(DryBuffer[i][SIDE_LEFT]);
1174 ((ALshort*)buffer)[7] = aluF2S(DryBuffer[i][SIDE_RIGHT]);
1175 buffer = ((ALshort*)buffer) + 8;
1177 break;
1179 default:
1180 break;
1183 size -= SamplesToDo;
1186 #if defined(HAVE_FESETROUND)
1187 fesetround(fpuState);
1188 #elif defined(HAVE__CONTROLFP)
1189 _controlfp(fpuState, 0xfffff);
1190 #endif
1192 ProcessContext(ALContext);