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
);
330 switch(aluChannelsFromFormat(OutputFormat
))
333 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
334 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
); //Direct
335 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
336 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt(1.0f
); //Room
339 PanningLR
= 0.5f
+ 0.5f
*Position
[0];
340 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(1.0f
-PanningLR
); //L Direct
341 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt( PanningLR
); //R Direct
342 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt(1.0f
-PanningLR
); //L Room
343 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt( PanningLR
); //R Room
346 /* TODO: Add center/lfe channel in spatial calculations? */
348 // Apply a scalar so each individual speaker has more weight
349 PanningLR
= 0.5f
+ (0.5f
*Position
[0]*1.41421356f
);
350 PanningLR
= __min(1.0f
, PanningLR
);
351 PanningLR
= __max(0.0f
, PanningLR
);
352 PanningFB
= 0.5f
+ (0.5f
*Position
[2]*1.41421356f
);
353 PanningFB
= __min(1.0f
, PanningFB
);
354 PanningFB
= __max(0.0f
, PanningFB
);
355 drysend
[0] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
)); //FL Direct
356 drysend
[1] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
)); //FR Direct
357 drysend
[2] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
)); //BL Direct
358 drysend
[3] = ConeVolume
* ListenerGain
* DryMix
* aluSqrt(( PanningLR
)*( PanningFB
)); //BR Direct
359 wetsend
[0] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*(1.0f
-PanningFB
)); //FL Room
360 wetsend
[1] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*(1.0f
-PanningFB
)); //FR Room
361 wetsend
[2] = ListenerGain
* WetMix
* aluSqrt((1.0f
-PanningLR
)*( PanningFB
)); //BL Room
362 wetsend
[3] = ListenerGain
* WetMix
* aluSqrt(( PanningLR
)*( PanningFB
)); //BR Room
370 //1. Multi-channel buffers always play "normal"
371 drysend
[0] = SourceVolume
* 1.0f
* ListenerGain
;
372 drysend
[1] = SourceVolume
* 1.0f
* ListenerGain
;
373 drysend
[2] = SourceVolume
* 1.0f
* ListenerGain
;
374 drysend
[3] = SourceVolume
* 1.0f
* ListenerGain
;
375 drysend
[4] = SourceVolume
* 1.0f
* ListenerGain
;
376 drysend
[5] = SourceVolume
* 1.0f
* ListenerGain
;
377 wetsend
[0] = SourceVolume
* 0.0f
* ListenerGain
;
378 wetsend
[1] = SourceVolume
* 0.0f
* ListenerGain
;
379 wetsend
[2] = SourceVolume
* 0.0f
* ListenerGain
;
380 wetsend
[3] = SourceVolume
* 0.0f
* ListenerGain
;
381 wetsend
[4] = SourceVolume
* 0.0f
* ListenerGain
;
382 wetsend
[5] = SourceVolume
* 0.0f
* ListenerGain
;
388 ALvoid
aluMixData(ALCcontext
*ALContext
,ALvoid
*buffer
,ALsizei size
,ALenum format
)
390 static float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
391 static float WetBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
392 ALfloat DrySend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
393 ALfloat WetSend
[OUTPUTCHANNELS
] = { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
};
394 ALuint BlockAlign
,BufferSize
;
395 ALuint DataSize
=0,DataPosInt
=0,DataPosFrac
=0;
396 ALuint Channels
,Bits
,Frequency
,ulExtraSamples
;
398 ALint Looping
,increment
,State
;
399 ALuint Buffer
,fraction
;
406 ALbufferlistitem
*BufferListItem
;
408 ALint64 DataSize64
,DataPos64
;
410 SuspendContext(ALContext
);
414 //Figure output format variables
415 BlockAlign
= aluChannelsFromFormat(format
);
416 BlockAlign
*= aluBytesFromFormat(format
);
422 ALSource
= (ALContext
? ALContext
->Source
: NULL
);
423 SamplesToDo
= min(size
, BUFFERSIZE
);
425 //Clear mixing buffer
426 memset(DryBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
427 memset(WetBuffer
, 0, SamplesToDo
*OUTPUTCHANNELS
*sizeof(ALfloat
));
433 State
= ALSource
->state
;
434 while(State
== AL_PLAYING
&& j
< SamplesToDo
)
441 if((Buffer
= ALSource
->ulBufferID
))
443 ALBuffer
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(Buffer
);
445 Data
= ALBuffer
->data
;
446 Bits
= aluBytesFromFormat(ALBuffer
->format
) * 8;
447 Channels
= aluChannelsFromFormat(ALBuffer
->format
);
448 DataSize
= ALBuffer
->size
;
449 Frequency
= ALBuffer
->frequency
;
451 CalcSourceParams(ALContext
, ALSource
,
452 (Channels
==1) ? AL_TRUE
: AL_FALSE
,
453 format
, DrySend
, WetSend
, &Pitch
);
456 Pitch
= (Pitch
*Frequency
) / ALContext
->Frequency
;
457 DataSize
= DataSize
/ (Bits
*Channels
/8);
460 DataPosInt
= ALSource
->position
;
461 DataPosFrac
= ALSource
->position_fraction
;
463 //Compute 18.14 fixed point step
464 increment
= aluF2L(Pitch
*(1L<<FRACTIONBITS
));
465 if(increment
> (MAX_PITCH
<<FRACTIONBITS
))
466 increment
= (MAX_PITCH
<<FRACTIONBITS
);
468 //Figure out how many samples we can mix.
469 //Pitch must be <= 4 (the number below !)
470 DataSize64
= DataSize
+MAX_PITCH
;
471 DataSize64
<<= FRACTIONBITS
;
472 DataPos64
= DataPosInt
;
473 DataPos64
<<= FRACTIONBITS
;
474 DataPos64
+= DataPosFrac
;
475 BufferSize
= (ALuint
)((DataSize64
-DataPos64
) / increment
);
476 BufferListItem
= ALSource
->queue
;
477 for(loop
= 0; loop
< ALSource
->BuffersPlayed
; loop
++)
480 BufferListItem
= BufferListItem
->next
;
484 if (BufferListItem
->next
)
486 if(BufferListItem
->next
->buffer
&&
487 ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
)
489 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->size
, (ALint
)(16*Channels
));
490 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(BufferListItem
->next
->buffer
))->data
, ulExtraSamples
);
493 else if (ALSource
->bLooping
)
495 if (ALSource
->queue
->buffer
)
497 if(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
)
499 ulExtraSamples
= min(((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->size
, (ALint
)(16*Channels
));
500 memcpy(&Data
[DataSize
*Channels
], ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(ALSource
->queue
->buffer
))->data
, ulExtraSamples
);
505 BufferSize
= min(BufferSize
, (SamplesToDo
-j
));
507 //Actual sample mixing loop
508 Data
+= DataPosInt
*Channels
;
511 k
= DataPosFrac
>>FRACTIONBITS
;
512 fraction
= DataPosFrac
&FRACTIONMASK
;
515 //First order interpolator
516 value
= (ALfloat
)((ALshort
)(((Data
[k
]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
+1]*(fraction
)))>>FRACTIONBITS
));
517 //Direct path final mix buffer and panning
518 DryBuffer
[j
][0] += value
*DrySend
[0];
519 DryBuffer
[j
][1] += value
*DrySend
[1];
520 DryBuffer
[j
][2] += value
*DrySend
[2];
521 DryBuffer
[j
][3] += value
*DrySend
[3];
522 //Room path final mix buffer and panning
523 WetBuffer
[j
][0] += value
*WetSend
[0];
524 WetBuffer
[j
][1] += value
*WetSend
[1];
525 WetBuffer
[j
][2] += value
*WetSend
[2];
526 WetBuffer
[j
][3] += value
*WetSend
[3];
530 //First order interpolator (left)
531 value
= (ALfloat
)((ALshort
)(((Data
[k
*2 ]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
*2+2]*(fraction
)))>>FRACTIONBITS
));
532 //Direct path final mix buffer and panning (left)
533 DryBuffer
[j
][0] += value
*DrySend
[0];
534 //Room path final mix buffer and panning (left)
535 WetBuffer
[j
][0] += value
*WetSend
[0];
536 //First order interpolator (right)
537 value
= (ALfloat
)((ALshort
)(((Data
[k
*2+1]*((1L<<FRACTIONBITS
)-fraction
))+(Data
[k
*2+3]*(fraction
)))>>FRACTIONBITS
));
538 //Direct path final mix buffer and panning (right)
539 DryBuffer
[j
][1] += value
*DrySend
[1];
540 //Room path final mix buffer and panning (right)
541 WetBuffer
[j
][1] += value
*WetSend
[1];
543 DataPosFrac
+= increment
;
546 DataPosInt
+= (DataPosFrac
>>FRACTIONBITS
);
547 DataPosFrac
= (DataPosFrac
&FRACTIONMASK
);
550 ALSource
->position
= DataPosInt
;
551 ALSource
->position_fraction
= DataPosFrac
;
554 //Handle looping sources
555 if(!Buffer
|| DataPosInt
>= DataSize
)
560 Looping
= ALSource
->bLooping
;
561 if(ALSource
->BuffersPlayed
< (ALSource
->BuffersInQueue
-1))
563 BufferListItem
= ALSource
->queue
;
564 for(loop
= 0; loop
<= ALSource
->BuffersPlayed
; loop
++)
569 BufferListItem
->bufferstate
= PROCESSED
;
570 BufferListItem
= BufferListItem
->next
;
574 ALSource
->BuffersProcessed
++;
576 ALSource
->ulBufferID
= BufferListItem
->buffer
;
577 ALSource
->position
= DataPosInt
-DataSize
;
578 ALSource
->position_fraction
= DataPosFrac
;
579 ALSource
->BuffersPlayed
++;
586 ALSource
->state
= AL_STOPPED
;
587 ALSource
->inuse
= AL_FALSE
;
588 ALSource
->BuffersPlayed
= ALSource
->BuffersProcessed
= ALSource
->BuffersInQueue
;
589 BufferListItem
= ALSource
->queue
;
590 while(BufferListItem
!= NULL
)
592 BufferListItem
->bufferstate
= PROCESSED
;
593 BufferListItem
= BufferListItem
->next
;
600 ALSource
->state
= AL_PLAYING
;
601 ALSource
->inuse
= AL_TRUE
;
602 ALSource
->play
= AL_TRUE
;
603 ALSource
->BuffersPlayed
= 0;
604 ALSource
->BufferPosition
= 0;
605 ALSource
->lBytesPlayed
= 0;
606 ALSource
->BuffersProcessed
= 0;
607 BufferListItem
= ALSource
->queue
;
608 while(BufferListItem
!= NULL
)
610 BufferListItem
->bufferstate
= PENDING
;
611 BufferListItem
= BufferListItem
->next
;
613 ALSource
->ulBufferID
= ALSource
->queue
->buffer
;
615 ALSource
->position
= DataPosInt
-DataSize
;
616 ALSource
->position_fraction
= DataPosFrac
;
623 State
= ALSource
->state
;
626 ALSource
= ALSource
->next
;
629 //Post processing loop
632 case AL_FORMAT_MONO8
:
633 for(i
= 0;i
< SamplesToDo
;i
++)
635 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
][0]+DryBuffer
[i
][1]+WetBuffer
[i
][0]+WetBuffer
[i
][1])>>8)+128);
636 buffer
= ((ALubyte
*)buffer
) + 1;
639 case AL_FORMAT_STEREO8
:
640 for(i
= 0;i
< SamplesToDo
*2;i
++)
642 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
>>1][i
&1]+WetBuffer
[i
>>1][i
&1])>>8)+128);
643 buffer
= ((ALubyte
*)buffer
) + 1;
646 case AL_FORMAT_QUAD8
:
647 for(i
= 0;i
< SamplesToDo
*4;i
++)
649 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
>>2][i
&3]+WetBuffer
[i
>>2][i
&3])>>8)+128);
650 buffer
= ((ALubyte
*)buffer
) + 1;
653 case AL_FORMAT_51CHN8
:
654 for(i
= 0;i
< SamplesToDo
*6;i
++)
656 *((ALubyte
*)buffer
) = (ALubyte
)((aluF2S(DryBuffer
[i
/6][i
%6]+WetBuffer
[i
/6][i
%6])>>8)+128);
657 buffer
= ((ALubyte
*)buffer
) + 1;
660 case AL_FORMAT_MONO16
:
661 for(i
= 0;i
< SamplesToDo
;i
++)
663 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
][0]+DryBuffer
[i
][1]+WetBuffer
[i
][0]+WetBuffer
[i
][1]);
664 buffer
= ((ALshort
*)buffer
) + 1;
667 case AL_FORMAT_STEREO16
:
669 for(i
= 0;i
< SamplesToDo
*2;i
++)
671 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
>>1][i
&1]+WetBuffer
[i
>>1][i
&1]);
672 buffer
= ((ALshort
*)buffer
) + 1;
675 case AL_FORMAT_QUAD16
:
676 for(i
= 0;i
< SamplesToDo
*4;i
++)
678 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
>>2][i
&3]+WetBuffer
[i
>>2][i
&3]);
679 buffer
= ((ALshort
*)buffer
) + 1;
682 case AL_FORMAT_51CHN16
:
683 for(i
= 0;i
< SamplesToDo
*6;i
++)
685 *((ALshort
*)buffer
) = aluF2S(DryBuffer
[i
/6][i
%6]+WetBuffer
[i
/6][i
%6]);
686 buffer
= ((ALshort
*)buffer
) + 1;
695 ProcessContext(ALContext
);