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
:
62 case AL_FORMAT_51CHN8
:
65 case AL_FORMAT_MONO16
:
66 case AL_FORMAT_STEREO16
:
67 case AL_FORMAT_QUAD16
:
68 case AL_FORMAT_51CHN16
:
76 __inline ALuint
aluChannelsFromFormat(ALenum format
)
81 case AL_FORMAT_MONO16
:
84 case AL_FORMAT_STEREO8
:
85 case AL_FORMAT_STEREO16
:
89 case AL_FORMAT_QUAD16
:
92 case AL_FORMAT_51CHN8
:
93 case AL_FORMAT_51CHN16
:
101 static __inline ALint
aluF2L(ALfloat Value
)
103 if(sizeof(ALint
) == 4 && sizeof(double) == 8)
106 temp
= Value
+ (((65536.0*65536.0*16.0)+(65536.0*65536.0*8.0))*65536.0);
107 return *((ALint
*)&temp
);
112 static __inline ALshort
aluF2S(ALfloat Value
)
117 i
= __min( 32767, i
);
118 i
= __max(-32768, i
);
122 static __inline ALvoid
aluCrossproduct(ALfloat
*inVector1
,ALfloat
*inVector2
,ALfloat
*outVector
)
124 outVector
[0] = inVector1
[1]*inVector2
[2] - inVector1
[2]*inVector2
[1];
125 outVector
[1] = inVector1
[2]*inVector2
[0] - inVector1
[0]*inVector2
[2];
126 outVector
[2] = inVector1
[0]*inVector2
[1] - inVector1
[1]*inVector2
[0];
129 static __inline ALfloat
aluDotproduct(ALfloat
*inVector1
,ALfloat
*inVector2
)
131 return inVector1
[0]*inVector2
[0] + inVector1
[1]*inVector2
[1] +
132 inVector1
[2]*inVector2
[2];
135 static __inline ALvoid
aluNormalize(ALfloat
*inVector
)
137 ALfloat length
, inverse_length
;
139 length
= (ALfloat
)aluSqrt(aluDotproduct(inVector
, inVector
));
142 inverse_length
= 1.0f
/length
;
143 inVector
[0] *= inverse_length
;
144 inVector
[1] *= inverse_length
;
145 inVector
[2] *= inverse_length
;
149 static __inline ALvoid
aluMatrixVector(ALfloat
*vector
,ALfloat matrix
[3][3])
153 result
[0] = vector
[0]*matrix
[0][0] + vector
[1]*matrix
[1][0] + vector
[2]*matrix
[2][0];
154 result
[1] = vector
[0]*matrix
[0][1] + vector
[1]*matrix
[1][1] + vector
[2]*matrix
[2][1];
155 result
[2] = vector
[0]*matrix
[0][2] + vector
[1]*matrix
[1][2] + vector
[2]*matrix
[2][2];
156 memcpy(vector
, result
, sizeof(result
));
159 static ALvoid
CalcSourceParams(ALCcontext
*ALContext
, ALsource
*ALSource
,
160 ALenum isMono
, ALenum OutputFormat
,
161 ALfloat
*drysend
, ALfloat
*wetsend
,
164 ALfloat ListenerOrientation
[6],ListenerPosition
[3],ListenerVelocity
[3];
165 ALfloat InnerAngle
,OuterAngle
,OuterGain
,Angle
,Distance
,DryMix
,WetMix
;
166 ALfloat Direction
[3],Position
[3],Velocity
[3],SourceToListener
[3];
167 ALfloat MinVolume
,MaxVolume
,MinDist
,MaxDist
,Rolloff
;
168 ALfloat Pitch
,ConeVolume
,SourceVolume
,PanningFB
,PanningLR
,ListenerGain
;
169 ALfloat U
[3],V
[3],N
[3];
170 ALfloat DopplerFactor
, DopplerVelocity
, flSpeedOfSound
, flMaxVelocity
;
171 ALfloat flVSS
, flVLS
;
173 ALfloat Matrix
[3][3];
175 ALfloat flAttenuation
;
177 //Get context properties
178 DopplerFactor
= ALContext
->DopplerFactor
;
179 DistanceModel
= ALContext
->DistanceModel
;
180 DopplerVelocity
= ALContext
->DopplerVelocity
;
181 flSpeedOfSound
= ALContext
->flSpeedOfSound
;
183 //Get listener properties
184 ListenerGain
= ALContext
->Listener
.Gain
;
185 memcpy(ListenerPosition
, ALContext
->Listener
.Position
, sizeof(ALContext
->Listener
.Position
));
186 memcpy(ListenerVelocity
, ALContext
->Listener
.Velocity
, sizeof(ALContext
->Listener
.Velocity
));
187 memcpy(&ListenerOrientation
[0], ALContext
->Listener
.Forward
, sizeof(ALContext
->Listener
.Forward
));
188 memcpy(&ListenerOrientation
[3], ALContext
->Listener
.Up
, sizeof(ALContext
->Listener
.Up
));
190 //Get source properties
191 Pitch
= ALSource
->flPitch
;
192 SourceVolume
= ALSource
->flGain
;
193 memcpy(Position
, ALSource
->vPosition
, sizeof(ALSource
->vPosition
));
194 memcpy(Velocity
, ALSource
->vVelocity
, sizeof(ALSource
->vVelocity
));
195 memcpy(Direction
, ALSource
->vOrientation
, sizeof(ALSource
->vOrientation
));
196 MinVolume
= ALSource
->flMinGain
;
197 MaxVolume
= ALSource
->flMaxGain
;
198 MinDist
= ALSource
->flRefDistance
;
199 MaxDist
= ALSource
->flMaxDistance
;
200 Rolloff
= ALSource
->flRollOffFactor
;
201 OuterGain
= ALSource
->flOuterGain
;
202 InnerAngle
= ALSource
->flInnerAngle
;
203 OuterAngle
= ALSource
->flOuterAngle
;
204 HeadRelative
= ALSource
->bHeadRelative
;
206 //Set working variables
207 DryMix
= (ALfloat
)(1.0f
);
208 WetMix
= (ALfloat
)(0.0f
);
210 //Only apply 3D calculations for mono buffers
211 if(isMono
!= AL_FALSE
)
213 //1. Translate Listener to origin (convert to head relative)
214 if(HeadRelative
==AL_FALSE
)
216 Position
[0] -= ListenerPosition
[0];
217 Position
[1] -= ListenerPosition
[1];
218 Position
[2] -= ListenerPosition
[2];
221 //2. Calculate distance attenuation
222 Distance
= aluSqrt(aluDotproduct(Position
, Position
));
224 flAttenuation
= 1.0f
;
225 switch (DistanceModel
)
227 case AL_INVERSE_DISTANCE_CLAMPED
:
228 Distance
=__max(Distance
,MinDist
);
229 Distance
=__min(Distance
,MaxDist
);
230 if (MaxDist
< MinDist
)
233 case AL_INVERSE_DISTANCE
:
236 if ((MinDist
+ (Rolloff
* (Distance
- MinDist
))) > 0.0f
)
237 flAttenuation
= MinDist
/ (MinDist
+ (Rolloff
* (Distance
- MinDist
)));
241 case AL_LINEAR_DISTANCE_CLAMPED
:
242 Distance
=__max(Distance
,MinDist
);
243 Distance
=__min(Distance
,MaxDist
);
244 if (MaxDist
< MinDist
)
247 case AL_LINEAR_DISTANCE
:
248 Distance
=__min(Distance
,MaxDist
);
249 if (MaxDist
!= MinDist
)
250 flAttenuation
= 1.0f
- (Rolloff
*(Distance
-MinDist
)/(MaxDist
- MinDist
));
253 case AL_EXPONENT_DISTANCE_CLAMPED
:
254 Distance
=__max(Distance
,MinDist
);
255 Distance
=__min(Distance
,MaxDist
);
256 if (MaxDist
< MinDist
)
259 case AL_EXPONENT_DISTANCE
:
260 if ((Distance
> 0.0f
) && (MinDist
> 0.0f
))
261 flAttenuation
= (ALfloat
)pow(Distance
/MinDist
, -Rolloff
);
266 flAttenuation
= 1.0f
;
270 // Source Gain + Attenuation
271 DryMix
= SourceVolume
* flAttenuation
;
273 // Clamp to Min/Max Gain
274 DryMix
= __min(DryMix
,MaxVolume
);
275 DryMix
= __max(DryMix
,MinVolume
);
276 WetMix
= __min(WetMix
,MaxVolume
);
277 WetMix
= __max(WetMix
,MinVolume
);
278 //3. Apply directional soundcones
279 SourceToListener
[0] = -Position
[0];
280 SourceToListener
[1] = -Position
[1];
281 SourceToListener
[2] = -Position
[2];
282 aluNormalize(Direction
);
283 aluNormalize(SourceToListener
);
284 Angle
= (ALfloat
)(180.0*acos(aluDotproduct(Direction
,SourceToListener
))/3.141592654f
);
285 if(Angle
>= InnerAngle
&& Angle
<= OuterAngle
)
286 ConeVolume
= (1.0f
+(OuterGain
-1.0f
)*(Angle
-InnerAngle
)/(OuterAngle
-InnerAngle
));
287 else if(Angle
> OuterAngle
)
288 ConeVolume
= (1.0f
+(OuterGain
-1.0f
) );
292 //4. Calculate Velocity
293 if(DopplerFactor
!= 0.0f
)
295 flVLS
= aluDotproduct(ListenerVelocity
, SourceToListener
);
296 flVSS
= aluDotproduct(Velocity
, SourceToListener
);
298 flMaxVelocity
= (DopplerVelocity
* flSpeedOfSound
) / DopplerFactor
;
300 if (flVSS
>= flMaxVelocity
)
301 flVSS
= (flMaxVelocity
- 1.0f
);
302 else if (flVSS
<= -flMaxVelocity
)
303 flVSS
= -flMaxVelocity
+ 1.0f
;
305 if (flVLS
>= flMaxVelocity
)
306 flVLS
= (flMaxVelocity
- 1.0f
);
307 else if (flVLS
<= -flMaxVelocity
)
308 flVLS
= -flMaxVelocity
+ 1.0f
;
310 pitch
[0] = Pitch
* ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVLS
)) /
311 ((flSpeedOfSound
* DopplerVelocity
) - (DopplerFactor
* flVSS
));
316 //5. Align coordinate system axes
317 aluCrossproduct(&ListenerOrientation
[0], &ListenerOrientation
[3], U
); // Right-vector
318 aluNormalize(U
); // Normalized Right-vector
319 memcpy(V
, &ListenerOrientation
[3], sizeof(V
)); // Up-vector
320 aluNormalize(V
); // Normalized Up-vector
321 memcpy(N
, &ListenerOrientation
[0], sizeof(N
)); // At-vector
322 aluNormalize(N
); // Normalized At-vector
323 Matrix
[0][0] = U
[0]; Matrix
[0][1] = V
[0]; Matrix
[0][2] = -N
[0];
324 Matrix
[1][0] = U
[1]; Matrix
[1][1] = V
[1]; Matrix
[1][2] = -N
[1];
325 Matrix
[2][0] = U
[2]; Matrix
[2][1] = V
[2]; Matrix
[2][2] = -N
[2];
326 aluMatrixVector(Position
, Matrix
);
328 //6. Convert normalized position into pannings, then into channel volumes
329 aluNormalize(Position
);
332 case AL_FORMAT_MONO8
:
333 case AL_FORMAT_MONO16
:
334 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
335 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
336 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
337 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
339 case AL_FORMAT_STEREO8
:
340 case AL_FORMAT_STEREO16
:
341 PanningLR
= 0.5f
+ 0.5f
*Position
[0];
342 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
-PanningLR
); //L Direct
343 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt( PanningLR
); //R Direct
344 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt(1.0f
-PanningLR
); //L Room
345 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt( PanningLR
); //R Room
347 case AL_FORMAT_QUAD8
:
348 case AL_FORMAT_QUAD16
:
349 /* TODO: Add center/lfe channel in spatial calculations? */
350 case AL_FORMAT_51CHN8
:
351 case AL_FORMAT_51CHN16
:
352 // Apply a scalar so each individual speaker has more weight
353 PanningLR
= 0.5f
+ (0.5f
*Position
[0]*1.41421356f
);
354 PanningLR
= __min(1.0f
, PanningLR
);
355 PanningLR
= __max(0.0f
, PanningLR
);
356 PanningFB
= 0.5f
+ (0.5f
*Position
[2]*1.41421356f
);
357 PanningFB
= __min(1.0f
, PanningFB
);
358 PanningFB
= __max(0.0f
, PanningFB
);
359 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
)); //FL Direct
360 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
)); //FR Direct
361 drysend
[2] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
)); //BL Direct
362 drysend
[3] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*( PanningFB
)); //BR Direct
363 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
)); //FL Room
364 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
)); //FR Room
365 wetsend
[2] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
)); //BL Room
366 wetsend
[3] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*( PanningFB
)); //BR Room
374 //1. Multi-channel buffers always play "normal"
375 drysend
[0] = SourceVolume
* 1.0f
* ListenerGain
;
376 drysend
[1] = SourceVolume
* 1.0f
* ListenerGain
;
377 drysend
[2] = SourceVolume
* 1.0f
* ListenerGain
;
378 drysend
[3] = SourceVolume
* 1.0f
* ListenerGain
;
379 drysend
[4] = SourceVolume
* 1.0f
* ListenerGain
;
380 drysend
[5] = SourceVolume
* 1.0f
* ListenerGain
;
381 wetsend
[0] = SourceVolume
* 0.0f
* ListenerGain
;
382 wetsend
[1] = SourceVolume
* 0.0f
* ListenerGain
;
383 wetsend
[2] = SourceVolume
* 0.0f
* ListenerGain
;
384 wetsend
[3] = SourceVolume
* 0.0f
* ListenerGain
;
385 wetsend
[4] = SourceVolume
* 0.0f
* ListenerGain
;
386 wetsend
[5] = SourceVolume
* 0.0f
* ListenerGain
;
392 ALvoid
aluMixData(ALCcontext
*ALContext
,ALvoid
*buffer
,ALsizei size
,ALenum format
)
394 static float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
395 static float WetBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
396 ALfloat DrySend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
397 ALfloat WetSend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
398 ALuint BlockAlign
,BufferSize
;
399 ALuint DataSize
=0,DataPosInt
=0,DataPosFrac
=0;
400 ALuint Channels
,Bits
,Frequency
,ulExtraSamples
;
402 ALint Looping
,increment
,State
;
403 ALuint Buffer
,fraction
;
410 ALbufferlistitem
*BufferListItem
;
412 ALint64 DataSize64
,DataPos64
;
414 SuspendContext(ALContext
);
418 //Figure output format variables
419 BlockAlign
= aluChannelsFromFormat(format
);
420 BlockAlign
*= aluBytesFromFormat(format
);
426 ALSource
= (ALContext
? ALContext
->Source
: NULL
);
427 SamplesToDo
= min(size
, BUFFERSIZE
);
429 //Clear mixing buffer
430 memset(DryBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
431 memset(WetBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
437 State
= ALSource
->state
;
438 while(State
== AL_PLAYING
&& j
< SamplesToDo
)
445 if((Buffer
= ALSource
->ulBufferID
))
447 ALBuffer
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(Buffer
);
449 Data
= ALBuffer
->data
;
450 Bits
= aluBytesFromFormat(ALBuffer
->format
) * 8;
451 Channels
= aluChannelsFromFormat(ALBuffer
->format
);
452 DataSize
= ALBuffer
->size
;
453 Frequency
= ALBuffer
->frequency
;
455 CalcSourceParams(ALContext
, ALSource
,
456 (Channels
==1) ? AL_TRUE
: AL_FALSE
,
457 format
, DrySend
, WetSend
, &Pitch
);
460 Pitch
= (Pitch
*Frequency
) / ALContext
->Frequency
;
461 DataSize
= DataSize
/ (Bits
*Channels
/8);
464 DataPosInt
= ALSource
->position
;
465 DataPosFrac
= ALSource
->position_fraction
;
467 //Compute 18.14 fixed point step
468 increment
= aluF2L(Pitch
*(1L<<FRACTIONBITS
));
469 if(increment
> (MAX_PITCH
<<FRACTIONBITS
))
470 increment
= (MAX_PITCH
<<FRACTIONBITS
);
472 //Figure out how many samples we can mix.
473 //Pitch must be <= 4 (the number below !)
474 DataSize64
= DataSize
+MAX_PITCH
;
475 DataSize64
<<= FRACTIONBITS
;
476 DataPos64
= DataPosInt
;
477 DataPos64
<<= FRACTIONBITS
;
478 DataPos64
+= DataPosFrac
;
479 BufferSize
= (ALuint
)((DataSize64
-DataPos64
) / increment
);
480 BufferListItem
= ALSource
->queue
;
481 for(loop
= 0; loop
< ALSource
->BuffersPlayed
; loop
++)
484 BufferListItem
= BufferListItem
->next
;
488 if (BufferListItem
->next
)
490 if(BufferListItem
->next
->buffer
&&
491 ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
)
493 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->size
, (ALint
)(16*Channels
));
494 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
, ulExtraSamples
);
497 else if (ALSource
->bLooping
)
499 if (ALSource
->queue
->buffer
)
501 if(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
)
503 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->size
, (ALint
)(16*Channels
));
504 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
, ulExtraSamples
);
509 BufferSize
= min(BufferSize
, (SamplesToDo
-j
));
511 //Actual sample mixing loop
512 Data
+= DataPosInt
*Channels
;
515 k
= DataPosFrac
>>FRACTIONBITS
;
516 fraction
= DataPosFrac
&FRACTIONMASK
;
519 //First order interpolator
520 value
= (ALfloat
)((ALshort
)(((Data
[k
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
+1]*(fraction
)))>>FRACTIONBITS
));
521 //Direct path final mix buffer and panning
522 DryBuffer
[j
][0] += value
*DrySend
[0];
523 DryBuffer
[j
][1] += value
*DrySend
[1];
524 DryBuffer
[j
][2] += value
*DrySend
[2];
525 DryBuffer
[j
][3] += value
*DrySend
[3];
526 //Room path final mix buffer and panning
527 WetBuffer
[j
][0] += value
*WetSend
[0];
528 WetBuffer
[j
][1] += value
*WetSend
[1];
529 WetBuffer
[j
][2] += value
*WetSend
[2];
530 WetBuffer
[j
][3] += value
*WetSend
[3];
534 //First order interpolator (left)
535 value
= (ALfloat
)((ALshort
)(((Data
[k
*2 ]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
*2+2]*(fraction
)))>>FRACTIONBITS
));
536 //Direct path final mix buffer and panning (left)
537 DryBuffer
[j
][0] += value
*DrySend
[0];
538 //Room path final mix buffer and panning (left)
539 WetBuffer
[j
][0] += value
*WetSend
[0];
540 //First order interpolator (right)
541 value
= (ALfloat
)((ALshort
)(((Data
[k
*2+1]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
*2+3]*(fraction
)))>>FRACTIONBITS
));
542 //Direct path final mix buffer and panning (right)
543 DryBuffer
[j
][1] += value
*DrySend
[1];
544 //Room path final mix buffer and panning (right)
545 WetBuffer
[j
][1] += value
*WetSend
[1];
547 DataPosFrac
+= increment
;
550 DataPosInt
+= (DataPosFrac
>>FRACTIONBITS
);
551 DataPosFrac
= (DataPosFrac
&FRACTIONMASK
);
554 ALSource
->position
= DataPosInt
;
555 ALSource
->position_fraction
= DataPosFrac
;
558 //Handle looping sources
559 if(!Buffer
|| DataPosInt
>= DataSize
)
564 Looping
= ALSource
->bLooping
;
565 if(ALSource
->BuffersPlayed
< (ALSource
->BuffersInQueue
-1))
567 BufferListItem
= ALSource
->queue
;
568 for(loop
= 0; loop
<= ALSource
->BuffersPlayed
; loop
++)
573 BufferListItem
->bufferstate
= PROCESSED
;
574 BufferListItem
= BufferListItem
->next
;
578 ALSource
->BuffersProcessed
++;
580 ALSource
->ulBufferID
= BufferListItem
->buffer
;
581 ALSource
->position
= DataPosInt
-DataSize
;
582 ALSource
->position_fraction
= DataPosFrac
;
583 ALSource
->BuffersPlayed
++;
590 ALSource
->state
= AL_STOPPED
;
591 ALSource
->inuse
= AL_FALSE
;
592 ALSource
->BuffersPlayed
= ALSource
->BuffersProcessed
= ALSource
->BuffersInQueue
;
593 BufferListItem
= ALSource
->queue
;
594 while(BufferListItem
!= NULL
)
596 BufferListItem
->bufferstate
= PROCESSED
;
597 BufferListItem
= BufferListItem
->next
;
604 ALSource
->state
= AL_PLAYING
;
605 ALSource
->inuse
= AL_TRUE
;
606 ALSource
->play
= AL_TRUE
;
607 ALSource
->BuffersPlayed
= 0;
608 ALSource
->BufferPosition
= 0;
609 ALSource
->lBytesPlayed
= 0;
610 ALSource
->BuffersProcessed
= 0;
611 BufferListItem
= ALSource
->queue
;
612 while(BufferListItem
!= NULL
)
614 BufferListItem
->bufferstate
= PENDING
;
615 BufferListItem
= BufferListItem
->next
;
617 ALSource
->ulBufferID
= ALSource
->queue
->buffer
;
619 ALSource
->position
= DataPosInt
-DataSize
;
620 ALSource
->position_fraction
= DataPosFrac
;
627 State
= ALSource
->state
;
630 ALSource
= ALSource
->next
;
633 //Post processing loop
636 case AL_FORMAT_MONO8
:
637 for(i
= 0;i
< SamplesToDo
;i
++)
639 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
][0]+DryBuffer
[i
][1]+WetBuffer
[i
][0]+WetBuffer
[i
][1])>>8)+128);
640 buffer
= ((ALubyte
*)buffer
) + 1;
643 case AL_FORMAT_STEREO8
:
644 for(i
= 0;i
< SamplesToDo
*2;i
++)
646 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
>>1][i
&1]+WetBuffer
[i
>>1][i
&1])>>8)+128);
647 buffer
= ((ALubyte
*)buffer
) + 1;
650 case AL_FORMAT_QUAD8
:
651 for(i
= 0;i
< SamplesToDo
*4;i
++)
653 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
>>2][i
&3]+WetBuffer
[i
>>2][i
&3])>>8)+128);
654 buffer
= ((ALubyte
*)buffer
) + 1;
657 case AL_FORMAT_51CHN8
:
658 for(i
= 0;i
< SamplesToDo
*6;i
++)
660 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
/6][i
%6]+WetBuffer
[i
/6][i
%6])>>8)+128);
661 buffer
= ((ALubyte
*)buffer
) + 1;
664 case AL_FORMAT_MONO16
:
665 for(i
= 0;i
< SamplesToDo
;i
++)
667 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
][0]+DryBuffer
[i
][1]+WetBuffer
[i
][0]+WetBuffer
[i
][1]);
668 buffer
= ((ALshort
*)buffer
) + 1;
671 case AL_FORMAT_STEREO16
:
673 for(i
= 0;i
< SamplesToDo
*2;i
++)
675 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
>>1][i
&1]+WetBuffer
[i
>>1][i
&1]);
676 buffer
= ((ALshort
*)buffer
) + 1;
679 case AL_FORMAT_QUAD16
:
680 for(i
= 0;i
< SamplesToDo
*4;i
++)
682 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
>>2][i
&3]+WetBuffer
[i
>>2][i
&3]);
683 buffer
= ((ALshort
*)buffer
) + 1;
686 case AL_FORMAT_51CHN16
:
687 for(i
= 0;i
< SamplesToDo
*6;i
++)
689 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
/6][i
%6]+WetBuffer
[i
/6][i
%6]);
690 buffer
= ((ALshort
*)buffer
) + 1;
699 ProcessContext(ALContext
);