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
30 #if defined(HAVE_STDINT_H)
32 typedef int64_t ALint64
;
33 #elif defined(HAVE___INT64)
34 typedef __int64 ALint64
;
35 #elif (SIZEOF_LONG == 8)
37 #elif (SIZEOF_LONG_LONG == 8)
38 typedef long long ALint64
;
42 #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
44 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
48 #if defined(max) && !defined(__max)
51 #if defined(min) && !defined(__min)
55 __inline ALuint
aluBytesFromFormat(ALenum format
)
60 case AL_FORMAT_STEREO8
:
64 case AL_FORMAT_MONO16
:
65 case AL_FORMAT_STEREO16
:
66 case AL_FORMAT_QUAD16
:
74 __inline ALuint
aluChannelsFromFormat(ALenum format
)
79 case AL_FORMAT_MONO16
:
82 case AL_FORMAT_STEREO8
:
83 case AL_FORMAT_STEREO16
:
87 case AL_FORMAT_QUAD16
:
95 static __inline ALint
aluF2L(ALfloat Value
)
97 if(sizeof(ALint
) == 4 && sizeof(double) == 8)
100 temp
= Value
+ (((65536.0*65536.0*16.0)+(65536.0*65536.0*8.0))*65536.0);
101 return *((ALint
*)&temp
);
106 static __inline ALshort
aluF2S(ALfloat Value
)
111 i
= __min( 32767, i
);
112 i
= __max(-32768, i
);
116 static __inline ALvoid
aluCrossproduct(ALfloat
*inVector1
,ALfloat
*inVector2
,ALfloat
*outVector
)
118 outVector
[0] = inVector1
[1]*inVector2
[2] - inVector1
[2]*inVector2
[1];
119 outVector
[1] = inVector1
[2]*inVector2
[0] - inVector1
[0]*inVector2
[2];
120 outVector
[2] = inVector1
[0]*inVector2
[1] - inVector1
[1]*inVector2
[0];
123 static __inline ALfloat
aluDotproduct(ALfloat
*inVector1
,ALfloat
*inVector2
)
125 return inVector1
[0]*inVector2
[0] + inVector1
[1]*inVector2
[1] +
126 inVector1
[2]*inVector2
[2];
129 static __inline ALvoid
aluNormalize(ALfloat
*inVector
)
131 ALfloat length
, inverse_length
;
133 length
= (ALfloat
)aluSqrt(aluDotproduct(inVector
, inVector
));
136 inverse_length
= 1.0f
/length
;
137 inVector
[0] *= inverse_length
;
138 inVector
[1] *= inverse_length
;
139 inVector
[2] *= inverse_length
;
143 static __inline ALvoid
aluMatrixVector(ALfloat
*vector
,ALfloat matrix
[3][3])
147 result
[0] = vector
[0]*matrix
[0][0] + vector
[1]*matrix
[1][0] + vector
[2]*matrix
[2][0];
148 result
[1] = vector
[0]*matrix
[0][1] + vector
[1]*matrix
[1][1] + vector
[2]*matrix
[2][1];
149 result
[2] = vector
[0]*matrix
[0][2] + vector
[1]*matrix
[1][2] + vector
[2]*matrix
[2][2];
150 memcpy(vector
, result
, sizeof(result
));
153 static ALvoid
CalcSourceParams(ALCcontext
*ALContext
, ALsource
*ALSource
,
154 ALenum isMono
, ALenum OutputFormat
,
155 ALfloat
*drysend
, ALfloat
*wetsend
,
158 ALfloat ListenerOrientation
[6],ListenerPosition
[3],ListenerVelocity
[3];
159 ALfloat InnerAngle
,OuterAngle
,OuterGain
,Angle
,Distance
,DryMix
,WetMix
;
160 ALfloat Direction
[3],Position
[3],Velocity
[3],SourceToListener
[3];
161 ALfloat MinVolume
,MaxVolume
,MinDist
,MaxDist
,Rolloff
;
162 ALfloat Pitch
,ConeVolume
,SourceVolume
,PanningFB
,PanningLR
,ListenerGain
;
163 ALfloat U
[3],V
[3],N
[3];
164 ALfloat DopplerFactor
, DopplerVelocity
, flSpeedOfSound
, flMaxVelocity
;
165 ALfloat flVSS
, flVLS
;
167 ALfloat Matrix
[3][3];
169 ALfloat flAttenuation
;
171 //Get context properties
172 DopplerFactor
= ALContext
->DopplerFactor
;
173 DistanceModel
= ALContext
->DistanceModel
;
174 DopplerVelocity
= ALContext
->DopplerVelocity
;
175 flSpeedOfSound
= ALContext
->flSpeedOfSound
;
177 //Get listener properties
178 ListenerGain
= ALContext
->Listener
.Gain
;
179 memcpy(ListenerPosition
, ALContext
->Listener
.Position
, sizeof(ALContext
->Listener
.Position
));
180 memcpy(ListenerVelocity
, ALContext
->Listener
.Velocity
, sizeof(ALContext
->Listener
.Velocity
));
181 memcpy(&ListenerOrientation
[0], ALContext
->Listener
.Forward
, sizeof(ALContext
->Listener
.Forward
));
182 memcpy(&ListenerOrientation
[3], ALContext
->Listener
.Up
, sizeof(ALContext
->Listener
.Up
));
184 //Get source properties
185 Pitch
= ALSource
->flPitch
;
186 SourceVolume
= ALSource
->flGain
;
187 memcpy(Position
, ALSource
->vPosition
, sizeof(ALSource
->vPosition
));
188 memcpy(Velocity
, ALSource
->vVelocity
, sizeof(ALSource
->vVelocity
));
189 memcpy(Direction
, ALSource
->vOrientation
, sizeof(ALSource
->vOrientation
));
190 MinVolume
= ALSource
->flMinGain
;
191 MaxVolume
= ALSource
->flMaxGain
;
192 MinDist
= ALSource
->flRefDistance
;
193 MaxDist
= ALSource
->flMaxDistance
;
194 Rolloff
= ALSource
->flRollOffFactor
;
195 OuterGain
= ALSource
->flOuterGain
;
196 InnerAngle
= ALSource
->flInnerAngle
;
197 OuterAngle
= ALSource
->flOuterAngle
;
198 HeadRelative
= ALSource
->bHeadRelative
;
200 //Set working variables
201 DryMix
= (ALfloat
)(1.0f
);
202 WetMix
= (ALfloat
)(0.0f
);
204 //Only apply 3D calculations for mono buffers
205 if(isMono
!= AL_FALSE
)
207 //1. Translate Listener to origin (convert to head relative)
208 if(HeadRelative
==AL_FALSE
)
210 Position
[0] -= ListenerPosition
[0];
211 Position
[1] -= ListenerPosition
[1];
212 Position
[2] -= ListenerPosition
[2];
215 //2. Calculate distance attenuation
216 Distance
= aluSqrt(aluDotproduct(Position
, Position
));
218 flAttenuation
= 1.0f
;
219 switch (DistanceModel
)
221 case AL_INVERSE_DISTANCE_CLAMPED
:
222 Distance
=__max(Distance
,MinDist
);
223 Distance
=__min(Distance
,MaxDist
);
224 if (MaxDist
< MinDist
)
227 case AL_INVERSE_DISTANCE
:
230 if ((MinDist
+ (Rolloff
* (Distance
- MinDist
))) > 0.0f
)
231 flAttenuation
= MinDist
/ (MinDist
+ (Rolloff
* (Distance
- MinDist
)));
235 case AL_LINEAR_DISTANCE_CLAMPED
:
236 Distance
=__max(Distance
,MinDist
);
237 Distance
=__min(Distance
,MaxDist
);
238 if (MaxDist
< MinDist
)
241 case AL_LINEAR_DISTANCE
:
242 Distance
=__min(Distance
,MaxDist
);
243 if (MaxDist
!= MinDist
)
244 flAttenuation
= 1.0f
- (Rolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
247 case AL_EXPONENT_DISTANCE_CLAMPED
:
248 Distance
=__max(Distance
,MinDist
);
249 Distance
=__min(Distance
,MaxDist
);
250 if (MaxDist
< MinDist
)
253 case AL_EXPONENT_DISTANCE
:
254 if ((Distance
> 0.0f
) && (MinDist
> 0.0f
))
255 flAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -Rolloff
);
260 flAttenuation
= 1.0f
;
264 // Source Gain + Attenuation
265 DryMix
= SourceVolume
* flAttenuation
;
267 // Clamp to Min/Max Gain
268 DryMix
= __min(DryMix
,MaxVolume
);
269 DryMix
= __max(DryMix
,MinVolume
);
270 WetMix
= __min(WetMix
,MaxVolume
);
271 WetMix
= __max(WetMix
,MinVolume
);
272 //3. Apply directional soundcones
273 SourceToListener
[0] = -Position
[0];
274 SourceToListener
[1] = -Position
[1];
275 SourceToListener
[2] = -Position
[2];
276 aluNormalize(Direction
);
277 aluNormalize(SourceToListener
);
278 Angle
= (ALfloat
)(180.0*acos(aluDotproduct(Direction
,SourceToListener
))/3.141592654f
);
279 if(Angle
>= InnerAngle
&& Angle
<= OuterAngle
)
280 ConeVolume
= (1.0f
+(OuterGain
-1.0f
)*(Angle
-InnerAngle
)/(OuterAngle
-InnerAngle
));
281 else if(Angle
> OuterAngle
)
282 ConeVolume
= (1.0f
+(OuterGain
-1.0f
) );
286 //4. Calculate Velocity
287 if(DopplerFactor
!= 0.0f
)
289 flVLS
= aluDotproduct(ListenerVelocity
, SourceToListener
);
290 flVSS
= aluDotproduct(Velocity
, SourceToListener
);
292 flMaxVelocity
= (DopplerVelocity
* flSpeedOfSound
) / DopplerFactor
;
294 if (flVSS
>= flMaxVelocity
)
295 flVSS
= (flMaxVelocity
- 1.0f
);
296 else if (flVSS
<= -flMaxVelocity
)
297 flVSS
= -flMaxVelocity
+ 1.0f
;
299 if (flVLS
>= flMaxVelocity
)
300 flVLS
= (flMaxVelocity
- 1.0f
);
301 else if (flVLS
<= -flMaxVelocity
)
302 flVLS
= -flMaxVelocity
+ 1.0f
;
304 pitch
[0] = Pitch
* ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVLS
)) /
305 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVSS
));
310 //5. Align coordinate system axes
311 aluCrossproduct(&ListenerOrientation
[0], &ListenerOrientation
[3], U
); // Right-vector
312 aluNormalize(U
); // Normalized Right-vector
313 memcpy(V
, &ListenerOrientation
[3], sizeof(V
)); // Up-vector
314 aluNormalize(V
); // Normalized Up-vector
315 memcpy(N
, &ListenerOrientation
[0], sizeof(N
)); // At-vector
316 aluNormalize(N
); // Normalized At-vector
317 Matrix
[0][0] = U
[0]; Matrix
[0][1] = V
[0]; Matrix
[0][2] = -N
[0];
318 Matrix
[1][0] = U
[1]; Matrix
[1][1] = V
[1]; Matrix
[1][2] = -N
[1];
319 Matrix
[2][0] = U
[2]; Matrix
[2][1] = V
[2]; Matrix
[2][2] = -N
[2];
320 aluMatrixVector(Position
, Matrix
);
322 //6. Convert normalized position into left/right front/back pannings
325 aluNormalize(Position
);
326 PanningLR
= 0.5f
+ 0.5f
*Position
[0];
327 PanningFB
= 0.5f
+ 0.5f
*Position
[2];
335 //7. Convert pannings into channel volumes
338 case AL_FORMAT_MONO8
:
339 case AL_FORMAT_MONO16
:
340 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
341 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
342 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
343 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
345 case AL_FORMAT_STEREO8
:
346 case AL_FORMAT_STEREO16
:
347 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
-PanningLR
); //L Direct
348 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt( PanningLR
); //R Direct
349 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt(1.0f
-PanningLR
); //L Room
350 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt( PanningLR
); //R Room
352 case AL_FORMAT_QUAD8
:
353 case AL_FORMAT_QUAD16
:
354 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
)); //FL Direct
355 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
)); //FR Direct
356 drysend
[2] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
)); //BL Direct
357 drysend
[3] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*( PanningFB
)); //BR Direct
358 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
)); //FL Room
359 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
)); //FR Room
360 wetsend
[2] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
)); //BL Room
361 wetsend
[3] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*( PanningFB
)); //BR Room
369 //1. Multi-channel buffers always play "normal"
370 drysend
[0] = SourceVolume
* 1.0f
* ListenerGain
;
371 drysend
[1] = SourceVolume
* 1.0f
* ListenerGain
;
372 drysend
[2] = SourceVolume
* 1.0f
* ListenerGain
;
373 drysend
[3] = SourceVolume
* 1.0f
* ListenerGain
;
374 wetsend
[0] = SourceVolume
* 0.0f
* ListenerGain
;
375 wetsend
[1] = SourceVolume
* 0.0f
* ListenerGain
;
376 wetsend
[2] = SourceVolume
* 0.0f
* ListenerGain
;
377 wetsend
[3] = SourceVolume
* 0.0f
* ListenerGain
;
383 ALvoid
aluMixData(ALCcontext
*ALContext
,ALvoid
*buffer
,ALsizei size
,ALenum format
)
385 static float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
386 static float WetBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
387 ALfloat DrySend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
};
388 ALfloat WetSend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
};
389 ALuint BlockAlign
,BufferSize
;
390 ALuint DataSize
=0,DataPosInt
=0,DataPosFrac
=0;
391 ALuint Channels
,Bits
,Frequency
,ulExtraSamples
;
393 ALint Looping
,increment
,State
;
394 ALuint Buffer
,fraction
;
401 ALbufferlistitem
*BufferListItem
;
403 ALint64 DataSize64
,DataPos64
;
405 SuspendContext(ALContext
);
409 //Figure output format variables
410 BlockAlign
= aluChannelsFromFormat(format
) *
411 aluBytesFromFormat(format
);
417 ALSource
= (ALContext
? ALContext
->Source
: NULL
);
418 SamplesToDo
= min(size
, BUFFERSIZE
);
420 //Clear mixing buffer
421 memset(DryBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
422 memset(WetBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
428 State
= ALSource
->state
;
429 while(State
== AL_PLAYING
&& j
< SamplesToDo
)
436 if((Buffer
= ALSource
->ulBufferID
))
438 ALBuffer
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(Buffer
);
440 Data
= ALBuffer
->data
;
441 Bits
= aluBytesFromFormat(ALBuffer
->format
) * 8;
442 Channels
= aluChannelsFromFormat(ALBuffer
->format
);
443 DataSize
= ALBuffer
->size
;
444 Frequency
= ALBuffer
->frequency
;
446 CalcSourceParams(ALContext
, ALSource
,
447 (Channels
==1) ? AL_TRUE
: AL_FALSE
,
448 format
, DrySend
, WetSend
, &Pitch
);
451 Pitch
= (Pitch
*Frequency
) / ALContext
->Frequency
;
452 DataSize
= DataSize
/ (Bits
*Channels
/8);
455 DataPosInt
= ALSource
->position
;
456 DataPosFrac
= ALSource
->position_fraction
;
458 //Compute 18.14 fixed point step
459 increment
= aluF2L(Pitch
*(1L<<FRACTIONBITS
));
460 if(increment
> (MAX_PITCH
<<FRACTIONBITS
))
461 increment
= (MAX_PITCH
<<FRACTIONBITS
);
463 //Figure out how many samples we can mix.
464 //Pitch must be <= 4 (the number below !)
465 DataSize64
= DataSize
+MAX_PITCH
;
466 DataSize64
<<= FRACTIONBITS
;
467 DataPos64
= DataPosInt
;
468 DataPos64
<<= FRACTIONBITS
;
469 DataPos64
+= DataPosFrac
;
470 BufferSize
= (ALuint
)((DataSize64
-DataPos64
) / increment
);
471 BufferListItem
= ALSource
->queue
;
472 for(loop
= 0; loop
< ALSource
->BuffersPlayed
; loop
++)
475 BufferListItem
= BufferListItem
->next
;
479 if (BufferListItem
->next
)
481 if(BufferListItem
->next
->buffer
&&
482 ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
)
484 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->size
, (ALint
)(16*Channels
));
485 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
, ulExtraSamples
);
488 else if (ALSource
->bLooping
)
490 if (ALSource
->queue
->buffer
)
492 if(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
)
494 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->size
, (ALint
)(16*Channels
));
495 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
, ulExtraSamples
);
500 BufferSize
= min(BufferSize
, (SamplesToDo
-j
));
502 //Actual sample mixing loop
503 Data
+= DataPosInt
*Channels
;
506 k
= DataPosFrac
>>FRACTIONBITS
;
507 fraction
= DataPosFrac
&FRACTIONMASK
;
510 //First order interpolator
511 value
= (ALfloat
)((ALshort
)(((Data
[k
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
+1]*(fraction
)))>>FRACTIONBITS
));
512 //Direct path final mix buffer and panning
513 DryBuffer
[j
][0] += value
*DrySend
[0];
514 DryBuffer
[j
][1] += value
*DrySend
[1];
515 DryBuffer
[j
][2] += value
*DrySend
[2];
516 DryBuffer
[j
][3] += value
*DrySend
[3];
517 //Room path final mix buffer and panning
518 WetBuffer
[j
][0] += value
*WetSend
[0];
519 WetBuffer
[j
][1] += value
*WetSend
[1];
520 WetBuffer
[j
][2] += value
*WetSend
[2];
521 WetBuffer
[j
][3] += value
*WetSend
[3];
525 //First order interpolator (left)
526 value
= (ALfloat
)((ALshort
)(((Data
[k
*2 ]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
*2+2]*(fraction
)))>>FRACTIONBITS
));
527 //Direct path final mix buffer and panning (left)
528 DryBuffer
[j
][0] += value
*DrySend
[0];
529 //Room path final mix buffer and panning (left)
530 WetBuffer
[j
][0] += value
*WetSend
[0];
531 //First order interpolator (right)
532 value
= (ALfloat
)((ALshort
)(((Data
[k
*2+1]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
*2+3]*(fraction
)))>>FRACTIONBITS
));
533 //Direct path final mix buffer and panning (right)
534 DryBuffer
[j
][1] += value
*DrySend
[1];
535 //Room path final mix buffer and panning (right)
536 WetBuffer
[j
][1] += value
*WetSend
[1];
538 DataPosFrac
+= increment
;
541 DataPosInt
+= (DataPosFrac
>>FRACTIONBITS
);
542 DataPosFrac
= (DataPosFrac
&FRACTIONMASK
);
545 ALSource
->position
= DataPosInt
;
546 ALSource
->position_fraction
= DataPosFrac
;
549 //Handle looping sources
550 if(!Buffer
|| DataPosInt
>= DataSize
)
555 Looping
= ALSource
->bLooping
;
556 if(ALSource
->BuffersPlayed
< (ALSource
->BuffersInQueue
-1))
558 BufferListItem
= ALSource
->queue
;
559 for(loop
= 0; loop
<= ALSource
->BuffersPlayed
; loop
++)
564 BufferListItem
->bufferstate
= PROCESSED
;
565 BufferListItem
= BufferListItem
->next
;
569 ALSource
->BuffersProcessed
++;
571 ALSource
->ulBufferID
= BufferListItem
->buffer
;
572 ALSource
->position
= DataPosInt
-DataSize
;
573 ALSource
->position_fraction
= DataPosFrac
;
574 ALSource
->BuffersPlayed
++;
581 ALSource
->state
= AL_STOPPED
;
582 ALSource
->inuse
= AL_FALSE
;
583 ALSource
->BuffersPlayed
= ALSource
->BuffersProcessed
= ALSource
->BuffersInQueue
;
584 BufferListItem
= ALSource
->queue
;
585 while(BufferListItem
!= NULL
)
587 BufferListItem
->bufferstate
= PROCESSED
;
588 BufferListItem
= BufferListItem
->next
;
595 ALSource
->state
= AL_PLAYING
;
596 ALSource
->inuse
= AL_TRUE
;
597 ALSource
->play
= AL_TRUE
;
598 ALSource
->BuffersPlayed
= 0;
599 ALSource
->BufferPosition
= 0;
600 ALSource
->lBytesPlayed
= 0;
601 ALSource
->BuffersProcessed
= 0;
602 BufferListItem
= ALSource
->queue
;
603 while(BufferListItem
!= NULL
)
605 BufferListItem
->bufferstate
= PENDING
;
606 BufferListItem
= BufferListItem
->next
;
608 ALSource
->ulBufferID
= ALSource
->queue
->buffer
;
610 ALSource
->position
= DataPosInt
-DataSize
;
611 ALSource
->position_fraction
= DataPosFrac
;
618 State
= ALSource
->state
;
621 ALSource
= ALSource
->next
;
624 //Post processing loop
627 case AL_FORMAT_MONO8
:
628 for(i
= 0;i
< SamplesToDo
;i
++)
630 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
][0]+DryBuffer
[i
][1]+WetBuffer
[i
][0]+WetBuffer
[i
][1])>>8)+128);
631 buffer
= ((ALubyte
*)buffer
) + 1;
634 case AL_FORMAT_STEREO8
:
635 for(i
= 0;i
< SamplesToDo
*2;i
++)
637 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
>>1][i
&1]+WetBuffer
[i
>>1][i
&1])>>8)+128);
638 buffer
= ((ALubyte
*)buffer
) + 1;
641 case AL_FORMAT_QUAD8
:
642 for(i
= 0;i
< SamplesToDo
*4;i
++)
644 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
>>2][i
&3]+WetBuffer
[i
>>2][i
&3])>>8)+128);
645 buffer
= ((ALubyte
*)buffer
) + 1;
648 case AL_FORMAT_MONO16
:
649 for(i
= 0;i
< SamplesToDo
;i
++)
651 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
][0]+DryBuffer
[i
][1]+WetBuffer
[i
][0]+WetBuffer
[i
][1]);
652 buffer
= ((ALshort
*)buffer
) + 1;
655 case AL_FORMAT_STEREO16
:
657 for(i
= 0;i
< SamplesToDo
*2;i
++)
659 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
>>1][i
&1]+WetBuffer
[i
>>1][i
&1]);
660 buffer
= ((ALshort
*)buffer
) + 1;
663 case AL_FORMAT_QUAD16
:
664 for(i
= 0;i
< SamplesToDo
*4;i
++)
666 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
>>2][i
&3]+WetBuffer
[i
>>2][i
&3]);
667 buffer
= ((ALshort
*)buffer
) + 1;
676 ProcessContext(ALContext
);