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
34 #include "alAuxEffectSlot.h"
39 enum Resampler DefaultResampler
= LinearResampler
;
40 const ALsizei ResamplerPadding
[ResamplerMax
] = {
45 const ALsizei ResamplerPrePadding
[ResamplerMax
] = {
52 extern inline struct ALsource
*LookupSource(ALCcontext
*context
, ALuint id
);
53 extern inline struct ALsource
*RemoveSource(ALCcontext
*context
, ALuint id
);
55 static ALvoid
InitSourceParams(ALsource
*Source
);
56 static ALint64
GetSourceOffset(const ALsource
*Source
);
57 static ALdouble
GetSourceSecOffset(const ALsource
*Source
);
58 static ALvoid
GetSourceOffsets(const ALsource
*Source
, ALenum name
, ALdouble
*offsets
, ALdouble updateLen
);
59 static ALint
GetSampleOffset(ALsource
*Source
);
61 typedef enum SrcFloatProp
{
64 sfMinGain
= AL_MIN_GAIN
,
65 sfMaxGain
= AL_MAX_GAIN
,
66 sfMaxDistance
= AL_MAX_DISTANCE
,
67 sfRolloffFactor
= AL_ROLLOFF_FACTOR
,
68 sfDopplerFactor
= AL_DOPPLER_FACTOR
,
69 sfConeOuterGain
= AL_CONE_OUTER_GAIN
,
70 sfSecOffset
= AL_SEC_OFFSET
,
71 sfSampleOffset
= AL_SAMPLE_OFFSET
,
72 sfByteOffset
= AL_BYTE_OFFSET
,
73 sfConeInnerAngle
= AL_CONE_INNER_ANGLE
,
74 sfConeOuterAngle
= AL_CONE_OUTER_ANGLE
,
75 sfRefDistance
= AL_REFERENCE_DISTANCE
,
77 sfPosition
= AL_POSITION
,
78 sfVelocity
= AL_VELOCITY
,
79 sfDirection
= AL_DIRECTION
,
81 sfSourceRelative
= AL_SOURCE_RELATIVE
,
82 sfLooping
= AL_LOOPING
,
84 sfSourceState
= AL_SOURCE_STATE
,
85 sfBuffersQueued
= AL_BUFFERS_QUEUED
,
86 sfBuffersProcessed
= AL_BUFFERS_PROCESSED
,
87 sfSourceType
= AL_SOURCE_TYPE
,
90 sfConeOuterGainHF
= AL_CONE_OUTER_GAINHF
,
91 sfAirAbsorptionFactor
= AL_AIR_ABSORPTION_FACTOR
,
92 sfRoomRolloffFactor
= AL_ROOM_ROLLOFF_FACTOR
,
93 sfDirectFilterGainHFAuto
= AL_DIRECT_FILTER_GAINHF_AUTO
,
94 sfAuxSendFilterGainAuto
= AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
,
95 sfAuxSendFilterGainHFAuto
= AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
,
97 /* AL_SOFT_direct_channels */
98 sfDirectChannelsSOFT
= AL_DIRECT_CHANNELS_SOFT
,
100 /* AL_EXT_source_distance_model */
101 sfDistanceModel
= AL_DISTANCE_MODEL
,
103 sfSecLength
= AL_SEC_LENGTH_SOFT
,
105 /* AL_SOFT_buffer_sub_data / AL_SOFT_buffer_samples */
106 sfSampleRWOffsetsSOFT
= AL_SAMPLE_RW_OFFSETS_SOFT
,
107 sfByteRWOffsetsSOFT
= AL_BYTE_RW_OFFSETS_SOFT
,
109 /* AL_SOFT_source_latency */
110 sfSecOffsetLatencySOFT
= AL_SEC_OFFSET_LATENCY_SOFT
,
113 typedef enum SrcIntProp
{
114 siMaxDistance
= AL_MAX_DISTANCE
,
115 siRolloffFactor
= AL_ROLLOFF_FACTOR
,
116 siRefDistance
= AL_REFERENCE_DISTANCE
,
117 siSourceRelative
= AL_SOURCE_RELATIVE
,
118 siConeInnerAngle
= AL_CONE_INNER_ANGLE
,
119 siConeOuterAngle
= AL_CONE_OUTER_ANGLE
,
120 siLooping
= AL_LOOPING
,
121 siBuffer
= AL_BUFFER
,
122 siSourceState
= AL_SOURCE_STATE
,
123 siBuffersQueued
= AL_BUFFERS_QUEUED
,
124 siBuffersProcessed
= AL_BUFFERS_PROCESSED
,
125 siSourceType
= AL_SOURCE_TYPE
,
126 siSecOffset
= AL_SEC_OFFSET
,
127 siSampleOffset
= AL_SAMPLE_OFFSET
,
128 siByteOffset
= AL_BYTE_OFFSET
,
129 siDopplerFactor
= AL_DOPPLER_FACTOR
,
130 siPosition
= AL_POSITION
,
131 siVelocity
= AL_VELOCITY
,
132 siDirection
= AL_DIRECTION
,
135 siDirectFilterGainHFAuto
= AL_DIRECT_FILTER_GAINHF_AUTO
,
136 siAuxSendFilterGainAutio
= AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
,
137 siAuxSendFilterGainHFAuto
= AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
,
138 siDirectFilter
= AL_DIRECT_FILTER
,
139 siAuxSendFilter
= AL_AUXILIARY_SEND_FILTER
,
141 /* AL_SOFT_direct_channels */
142 siDirectChannelsSOFT
= AL_DIRECT_CHANNELS_SOFT
,
144 /* AL_EXT_source_distance_model */
145 siDistanceModel
= AL_DISTANCE_MODEL
,
147 siByteLength
= AL_BYTE_LENGTH_SOFT
,
148 siSampleLength
= AL_SAMPLE_LENGTH_SOFT
,
150 /* AL_SOFT_buffer_sub_data / AL_SOFT_buffer_samples */
151 siSampleRWOffsetsSOFT
= AL_SAMPLE_RW_OFFSETS_SOFT
,
152 siByteRWOffsetsSOFT
= AL_BYTE_RW_OFFSETS_SOFT
,
154 /* AL_SOFT_source_latency */
155 siSampleOffsetLatencySOFT
= AL_SAMPLE_OFFSET_LATENCY_SOFT
,
158 static ALboolean
SetSourcefv(ALsource
*Source
, ALCcontext
*Context
, SrcFloatProp prop
, const ALfloat
*values
);
159 static ALboolean
SetSourceiv(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, const ALint
*values
);
160 static ALboolean
SetSourcei64v(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, const ALint64SOFT
*values
);
162 static ALboolean
GetSourcedv(ALsource
*Source
, ALCcontext
*Context
, SrcFloatProp prop
, ALdouble
*values
);
163 static ALboolean
GetSourceiv(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, ALint
*values
);
164 static ALboolean
GetSourcei64v(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, ALint64
*values
);
166 static ALint
FloatValsByProp(ALenum prop
)
168 if(prop
!= (ALenum
)((SrcFloatProp
)prop
))
170 switch((SrcFloatProp
)prop
)
177 case sfRolloffFactor
:
178 case sfDopplerFactor
:
179 case sfConeOuterGain
:
183 case sfConeInnerAngle
:
184 case sfConeOuterAngle
:
186 case sfConeOuterGainHF
:
187 case sfAirAbsorptionFactor
:
188 case sfRoomRolloffFactor
:
189 case sfDirectFilterGainHFAuto
:
190 case sfAuxSendFilterGainAuto
:
191 case sfAuxSendFilterGainHFAuto
:
192 case sfDirectChannelsSOFT
:
193 case sfDistanceModel
:
194 case sfSourceRelative
:
198 case sfBuffersQueued
:
199 case sfBuffersProcessed
:
204 case sfSampleRWOffsetsSOFT
:
205 case sfByteRWOffsetsSOFT
:
213 case sfSecOffsetLatencySOFT
:
214 break; /* Double only */
218 static ALint
DoubleValsByProp(ALenum prop
)
220 if(prop
!= (ALenum
)((SrcFloatProp
)prop
))
222 switch((SrcFloatProp
)prop
)
229 case sfRolloffFactor
:
230 case sfDopplerFactor
:
231 case sfConeOuterGain
:
235 case sfConeInnerAngle
:
236 case sfConeOuterAngle
:
238 case sfConeOuterGainHF
:
239 case sfAirAbsorptionFactor
:
240 case sfRoomRolloffFactor
:
241 case sfDirectFilterGainHFAuto
:
242 case sfAuxSendFilterGainAuto
:
243 case sfAuxSendFilterGainHFAuto
:
244 case sfDirectChannelsSOFT
:
245 case sfDistanceModel
:
246 case sfSourceRelative
:
250 case sfBuffersQueued
:
251 case sfBuffersProcessed
:
256 case sfSampleRWOffsetsSOFT
:
257 case sfByteRWOffsetsSOFT
:
258 case sfSecOffsetLatencySOFT
:
269 static ALint
IntValsByProp(ALenum prop
)
271 if(prop
!= (ALenum
)((SrcIntProp
)prop
))
273 switch((SrcIntProp
)prop
)
276 case siRolloffFactor
:
278 case siSourceRelative
:
279 case siConeInnerAngle
:
280 case siConeOuterAngle
:
284 case siBuffersQueued
:
285 case siBuffersProcessed
:
290 case siDopplerFactor
:
291 case siDirectFilterGainHFAuto
:
292 case siAuxSendFilterGainAutio
:
293 case siAuxSendFilterGainHFAuto
:
295 case siDirectChannelsSOFT
:
296 case siDistanceModel
:
301 case siSampleRWOffsetsSOFT
:
302 case siByteRWOffsetsSOFT
:
308 case siAuxSendFilter
:
311 case siSampleOffsetLatencySOFT
:
312 break; /* i64 only */
316 static ALint
Int64ValsByProp(ALenum prop
)
318 if(prop
!= (ALenum
)((SrcIntProp
)prop
))
320 switch((SrcIntProp
)prop
)
323 case siRolloffFactor
:
325 case siSourceRelative
:
326 case siConeInnerAngle
:
327 case siConeOuterAngle
:
331 case siBuffersQueued
:
332 case siBuffersProcessed
:
337 case siDopplerFactor
:
338 case siDirectFilterGainHFAuto
:
339 case siAuxSendFilterGainAutio
:
340 case siAuxSendFilterGainHFAuto
:
342 case siDirectChannelsSOFT
:
343 case siDistanceModel
:
348 case siSampleRWOffsetsSOFT
:
349 case siByteRWOffsetsSOFT
:
350 case siSampleOffsetLatencySOFT
:
356 case siAuxSendFilter
:
363 #define CHECKVAL(x) do { \
365 SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE); \
368 static ALboolean
SetSourcefv(ALsource
*Source
, ALCcontext
*Context
, SrcFloatProp prop
, const ALfloat
*values
)
375 CHECKVAL(*values
>= 0.0f
);
377 Source
->Pitch
= *values
;
378 Source
->NeedsUpdate
= AL_TRUE
;
381 case AL_CONE_INNER_ANGLE
:
382 CHECKVAL(*values
>= 0.0f
&& *values
<= 360.0f
);
384 Source
->InnerAngle
= *values
;
385 Source
->NeedsUpdate
= AL_TRUE
;
388 case AL_CONE_OUTER_ANGLE
:
389 CHECKVAL(*values
>= 0.0f
&& *values
<= 360.0f
);
391 Source
->OuterAngle
= *values
;
392 Source
->NeedsUpdate
= AL_TRUE
;
396 CHECKVAL(*values
>= 0.0f
);
398 Source
->Gain
= *values
;
399 Source
->NeedsUpdate
= AL_TRUE
;
402 case AL_MAX_DISTANCE
:
403 CHECKVAL(*values
>= 0.0f
);
405 Source
->MaxDistance
= *values
;
406 Source
->NeedsUpdate
= AL_TRUE
;
409 case AL_ROLLOFF_FACTOR
:
410 CHECKVAL(*values
>= 0.0f
);
412 Source
->RollOffFactor
= *values
;
413 Source
->NeedsUpdate
= AL_TRUE
;
416 case AL_REFERENCE_DISTANCE
:
417 CHECKVAL(*values
>= 0.0f
);
419 Source
->RefDistance
= *values
;
420 Source
->NeedsUpdate
= AL_TRUE
;
424 CHECKVAL(*values
>= 0.0f
&& *values
<= 1.0f
);
426 Source
->MinGain
= *values
;
427 Source
->NeedsUpdate
= AL_TRUE
;
431 CHECKVAL(*values
>= 0.0f
&& *values
<= 1.0f
);
433 Source
->MaxGain
= *values
;
434 Source
->NeedsUpdate
= AL_TRUE
;
437 case AL_CONE_OUTER_GAIN
:
438 CHECKVAL(*values
>= 0.0f
&& *values
<= 1.0f
);
440 Source
->OuterGain
= *values
;
441 Source
->NeedsUpdate
= AL_TRUE
;
444 case AL_CONE_OUTER_GAINHF
:
445 CHECKVAL(*values
>= 0.0f
&& *values
<= 1.0f
);
447 Source
->OuterGainHF
= *values
;
448 Source
->NeedsUpdate
= AL_TRUE
;
451 case AL_AIR_ABSORPTION_FACTOR
:
452 CHECKVAL(*values
>= 0.0f
&& *values
<= 10.0f
);
454 Source
->AirAbsorptionFactor
= *values
;
455 Source
->NeedsUpdate
= AL_TRUE
;
458 case AL_ROOM_ROLLOFF_FACTOR
:
459 CHECKVAL(*values
>= 0.0f
&& *values
<= 10.0f
);
461 Source
->RoomRolloffFactor
= *values
;
462 Source
->NeedsUpdate
= AL_TRUE
;
465 case AL_DOPPLER_FACTOR
:
466 CHECKVAL(*values
>= 0.0f
&& *values
<= 1.0f
);
468 Source
->DopplerFactor
= *values
;
469 Source
->NeedsUpdate
= AL_TRUE
;
473 case AL_SAMPLE_OFFSET
:
475 CHECKVAL(*values
>= 0.0f
);
477 LockContext(Context
);
478 Source
->OffsetType
= prop
;
479 Source
->Offset
= *values
;
481 if((Source
->state
== AL_PLAYING
|| Source
->state
== AL_PAUSED
) &&
482 !Context
->DeferUpdates
)
484 if(ApplyOffset(Source
) == AL_FALSE
)
486 UnlockContext(Context
);
487 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_VALUE
, AL_FALSE
);
490 UnlockContext(Context
);
495 case AL_SEC_OFFSET_LATENCY_SOFT
:
497 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_OPERATION
, AL_FALSE
);
501 CHECKVAL(isfinite(values
[0]) && isfinite(values
[1]) && isfinite(values
[2]));
503 LockContext(Context
);
504 Source
->Position
[0] = values
[0];
505 Source
->Position
[1] = values
[1];
506 Source
->Position
[2] = values
[2];
507 UnlockContext(Context
);
508 Source
->NeedsUpdate
= AL_TRUE
;
512 CHECKVAL(isfinite(values
[0]) && isfinite(values
[1]) && isfinite(values
[2]));
514 LockContext(Context
);
515 Source
->Velocity
[0] = values
[0];
516 Source
->Velocity
[1] = values
[1];
517 Source
->Velocity
[2] = values
[2];
518 UnlockContext(Context
);
519 Source
->NeedsUpdate
= AL_TRUE
;
523 CHECKVAL(isfinite(values
[0]) && isfinite(values
[1]) && isfinite(values
[2]));
525 LockContext(Context
);
526 Source
->Orientation
[0] = values
[0];
527 Source
->Orientation
[1] = values
[1];
528 Source
->Orientation
[2] = values
[2];
529 UnlockContext(Context
);
530 Source
->NeedsUpdate
= AL_TRUE
;
534 case sfSampleRWOffsetsSOFT
:
535 case sfByteRWOffsetsSOFT
:
536 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_OPERATION
, AL_FALSE
);
539 case sfSourceRelative
:
543 case sfDistanceModel
:
544 case sfDirectFilterGainHFAuto
:
545 case sfAuxSendFilterGainAuto
:
546 case sfAuxSendFilterGainHFAuto
:
547 case sfDirectChannelsSOFT
:
548 ival
= (ALint
)values
[0];
549 return SetSourceiv(Source
, Context
, (SrcIntProp
)prop
, &ival
);
552 case sfBuffersQueued
:
553 case sfBuffersProcessed
:
554 ival
= (ALint
)((ALuint
)values
[0]);
555 return SetSourceiv(Source
, Context
, (SrcIntProp
)prop
, &ival
);
558 ERR("Unexpected property: 0x%04x\n", prop
);
559 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_ENUM
, AL_FALSE
);
562 static ALboolean
SetSourceiv(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, const ALint
*values
)
564 ALCdevice
*device
= Context
->Device
;
565 ALbuffer
*buffer
= NULL
;
566 ALfilter
*filter
= NULL
;
567 ALeffectslot
*slot
= NULL
;
568 ALbufferlistitem
*oldlist
;
573 case AL_SOURCE_RELATIVE
:
574 CHECKVAL(*values
== AL_FALSE
|| *values
== AL_TRUE
);
576 Source
->HeadRelative
= (ALboolean
)*values
;
577 Source
->NeedsUpdate
= AL_TRUE
;
581 CHECKVAL(*values
== AL_FALSE
|| *values
== AL_TRUE
);
583 Source
->Looping
= (ALboolean
)*values
;
587 CHECKVAL(*values
== 0 || (buffer
=LookupBuffer(device
, *values
)) != NULL
);
589 WriteLock(&Source
->queue_lock
);
590 if(!(Source
->state
== AL_STOPPED
|| Source
->state
== AL_INITIAL
))
592 WriteUnlock(&Source
->queue_lock
);
593 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_OPERATION
, AL_FALSE
);
598 ALbufferlistitem
*BufferListItem
;
600 /* Add the selected buffer to a one-item queue */
601 BufferListItem
= malloc(sizeof(ALbufferlistitem
));
602 BufferListItem
->buffer
= buffer
;
603 BufferListItem
->next
= NULL
;
604 BufferListItem
->prev
= NULL
;
605 IncrementRef(&buffer
->ref
);
607 /* Source is now Static */
608 Source
->SourceType
= AL_STATIC
;
609 oldlist
= ExchangePtr((XchgPtr
*)&Source
->queue
, BufferListItem
);
611 ReadLock(&buffer
->lock
);
612 Source
->NumChannels
= ChannelsFromFmt(buffer
->FmtChannels
);
613 Source
->SampleSize
= BytesFromFmt(buffer
->FmtType
);
614 ReadUnlock(&buffer
->lock
);
618 /* Source is now Undetermined */
619 Source
->SourceType
= AL_UNDETERMINED
;
620 oldlist
= ExchangePtr((XchgPtr
*)&Source
->queue
, NULL
);
622 Source
->current_buffer
= Source
->queue
;
623 WriteUnlock(&Source
->queue_lock
);
625 /* Delete all elements in the previous queue */
626 while(oldlist
!= NULL
)
628 ALbufferlistitem
*temp
= oldlist
;
629 oldlist
= temp
->next
;
632 DecrementRef(&temp
->buffer
->ref
);
639 case siBuffersQueued
:
640 case siBuffersProcessed
:
642 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_OPERATION
, AL_FALSE
);
645 case AL_SAMPLE_OFFSET
:
647 CHECKVAL(*values
>= 0);
649 LockContext(Context
);
650 Source
->OffsetType
= prop
;
651 Source
->Offset
= *values
;
653 if((Source
->state
== AL_PLAYING
|| Source
->state
== AL_PAUSED
) &&
654 !Context
->DeferUpdates
)
656 if(ApplyOffset(Source
) == AL_FALSE
)
658 UnlockContext(Context
);
659 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_VALUE
, AL_FALSE
);
662 UnlockContext(Context
);
668 case siSampleRWOffsetsSOFT
:
669 case siByteRWOffsetsSOFT
:
671 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_OPERATION
, AL_FALSE
);
674 case AL_DIRECT_FILTER
:
675 CHECKVAL(*values
== 0 || (filter
=LookupFilter(device
, *values
)) != NULL
);
677 LockContext(Context
);
680 Source
->Direct
.Gain
= 1.0f
;
681 Source
->Direct
.GainHF
= 1.0f
;
682 Source
->Direct
.HFReference
= LOWPASSFREQREF
;
683 Source
->Direct
.GainLF
= 1.0f
;
684 Source
->Direct
.LFReference
= HIGHPASSFREQREF
;
688 Source
->Direct
.Gain
= filter
->Gain
;
689 Source
->Direct
.GainHF
= filter
->GainHF
;
690 Source
->Direct
.HFReference
= filter
->HFReference
;
691 Source
->Direct
.GainLF
= filter
->GainLF
;
692 Source
->Direct
.LFReference
= filter
->LFReference
;
694 UnlockContext(Context
);
695 Source
->NeedsUpdate
= AL_TRUE
;
698 case AL_DIRECT_FILTER_GAINHF_AUTO
:
699 CHECKVAL(*values
== AL_FALSE
|| *values
== AL_TRUE
);
701 Source
->DryGainHFAuto
= *values
;
702 Source
->NeedsUpdate
= AL_TRUE
;
705 case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
:
706 CHECKVAL(*values
== AL_FALSE
|| *values
== AL_TRUE
);
708 Source
->WetGainAuto
= *values
;
709 Source
->NeedsUpdate
= AL_TRUE
;
712 case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
:
713 CHECKVAL(*values
== AL_FALSE
|| *values
== AL_TRUE
);
715 Source
->WetGainHFAuto
= *values
;
716 Source
->NeedsUpdate
= AL_TRUE
;
719 case AL_DIRECT_CHANNELS_SOFT
:
720 CHECKVAL(*values
== AL_FALSE
|| *values
== AL_TRUE
);
722 Source
->DirectChannels
= *values
;
723 Source
->NeedsUpdate
= AL_TRUE
;
726 case AL_DISTANCE_MODEL
:
727 CHECKVAL(*values
== AL_NONE
||
728 *values
== AL_INVERSE_DISTANCE
||
729 *values
== AL_INVERSE_DISTANCE_CLAMPED
||
730 *values
== AL_LINEAR_DISTANCE
||
731 *values
== AL_LINEAR_DISTANCE_CLAMPED
||
732 *values
== AL_EXPONENT_DISTANCE
||
733 *values
== AL_EXPONENT_DISTANCE_CLAMPED
);
735 Source
->DistanceModel
= *values
;
736 if(Context
->SourceDistanceModel
)
737 Source
->NeedsUpdate
= AL_TRUE
;
741 case AL_AUXILIARY_SEND_FILTER
:
742 LockContext(Context
);
743 if(!((ALuint
)values
[1] < device
->NumAuxSends
&&
744 (values
[0] == 0 || (slot
=LookupEffectSlot(Context
, values
[0])) != NULL
) &&
745 (values
[2] == 0 || (filter
=LookupFilter(device
, values
[2])) != NULL
)))
747 UnlockContext(Context
);
748 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_VALUE
, AL_FALSE
);
751 /* Add refcount on the new slot, and release the previous slot */
752 if(slot
) IncrementRef(&slot
->ref
);
753 slot
= ExchangePtr((XchgPtr
*)&Source
->Send
[values
[1]].Slot
, slot
);
754 if(slot
) DecrementRef(&slot
->ref
);
759 Source
->Send
[values
[1]].Gain
= 1.0f
;
760 Source
->Send
[values
[1]].GainHF
= 1.0f
;
761 Source
->Send
[values
[1]].HFReference
= LOWPASSFREQREF
;
762 Source
->Send
[values
[1]].GainLF
= 1.0f
;
763 Source
->Send
[values
[1]].LFReference
= HIGHPASSFREQREF
;
767 Source
->Send
[values
[1]].Gain
= filter
->Gain
;
768 Source
->Send
[values
[1]].GainHF
= filter
->GainHF
;
769 Source
->Send
[values
[1]].HFReference
= filter
->HFReference
;
770 Source
->Send
[values
[1]].GainLF
= filter
->GainLF
;
771 Source
->Send
[values
[1]].LFReference
= filter
->LFReference
;
773 Source
->NeedsUpdate
= AL_TRUE
;
774 UnlockContext(Context
);
778 case AL_MAX_DISTANCE
:
779 case AL_ROLLOFF_FACTOR
:
780 case AL_CONE_INNER_ANGLE
:
781 case AL_CONE_OUTER_ANGLE
:
782 case AL_REFERENCE_DISTANCE
:
783 case siDopplerFactor
:
784 fvals
[0] = (ALfloat
)*values
;
785 return SetSourcefv(Source
, Context
, (int)prop
, fvals
);
790 fvals
[0] = (ALfloat
)values
[0];
791 fvals
[1] = (ALfloat
)values
[1];
792 fvals
[2] = (ALfloat
)values
[2];
793 return SetSourcefv(Source
, Context
, (int)prop
, fvals
);
795 case siSampleOffsetLatencySOFT
:
800 ERR("Unexpected property: 0x%04x\n", prop
);
801 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_ENUM
, AL_FALSE
);
804 static ALboolean
SetSourcei64v(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, const ALint64SOFT
*values
)
811 case siSampleRWOffsetsSOFT
:
812 case siByteRWOffsetsSOFT
:
813 case siSampleOffsetLatencySOFT
:
815 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_OPERATION
, AL_FALSE
);
819 case AL_SOURCE_RELATIVE
:
821 case AL_SOURCE_STATE
:
823 case AL_SAMPLE_OFFSET
:
827 case siBuffersQueued
:
828 case siBuffersProcessed
:
829 case AL_DIRECT_FILTER_GAINHF_AUTO
:
830 case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
:
831 case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
:
832 case AL_DIRECT_CHANNELS_SOFT
:
833 case AL_DISTANCE_MODEL
:
834 CHECKVAL(*values
<= INT_MAX
&& *values
>= INT_MIN
);
836 ivals
[0] = (ALint
)*values
;
837 return SetSourceiv(Source
, Context
, (int)prop
, ivals
);
841 case AL_DIRECT_FILTER
:
842 CHECKVAL(*values
<= UINT_MAX
&& *values
>= 0);
844 ivals
[0] = (ALuint
)*values
;
845 return SetSourceiv(Source
, Context
, (int)prop
, ivals
);
848 case AL_AUXILIARY_SEND_FILTER
:
849 CHECKVAL(values
[0] <= UINT_MAX
&& values
[0] >= 0 &&
850 values
[1] <= UINT_MAX
&& values
[1] >= 0 &&
851 values
[2] <= UINT_MAX
&& values
[2] >= 0);
853 ivals
[0] = (ALuint
)values
[0];
854 ivals
[1] = (ALuint
)values
[1];
855 ivals
[2] = (ALuint
)values
[2];
856 return SetSourceiv(Source
, Context
, (int)prop
, ivals
);
859 case AL_MAX_DISTANCE
:
860 case AL_ROLLOFF_FACTOR
:
861 case AL_CONE_INNER_ANGLE
:
862 case AL_CONE_OUTER_ANGLE
:
863 case AL_REFERENCE_DISTANCE
:
865 case siDopplerFactor
:
866 fvals
[0] = (ALfloat
)*values
;
867 return SetSourcefv(Source
, Context
, (int)prop
, fvals
);
873 fvals
[0] = (ALfloat
)values
[0];
874 fvals
[1] = (ALfloat
)values
[1];
875 fvals
[2] = (ALfloat
)values
[2];
876 return SetSourcefv(Source
, Context
, (int)prop
, fvals
);
879 ERR("Unexpected property: 0x%04x\n", prop
);
880 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_ENUM
, AL_FALSE
);
886 static ALboolean
GetSourcedv(ALsource
*Source
, ALCcontext
*Context
, SrcFloatProp prop
, ALdouble
*values
)
888 ALbufferlistitem
*BufferList
;
897 *values
= Source
->Gain
;
901 *values
= Source
->Pitch
;
904 case AL_MAX_DISTANCE
:
905 *values
= Source
->MaxDistance
;
908 case AL_ROLLOFF_FACTOR
:
909 *values
= Source
->RollOffFactor
;
912 case AL_REFERENCE_DISTANCE
:
913 *values
= Source
->RefDistance
;
916 case AL_CONE_INNER_ANGLE
:
917 *values
= Source
->InnerAngle
;
920 case AL_CONE_OUTER_ANGLE
:
921 *values
= Source
->OuterAngle
;
925 *values
= Source
->MinGain
;
929 *values
= Source
->MaxGain
;
932 case AL_CONE_OUTER_GAIN
:
933 *values
= Source
->OuterGain
;
937 case AL_SAMPLE_OFFSET
:
939 ReadLock(&Source
->queue_lock
);
940 LockContext(Context
);
941 GetSourceOffsets(Source
, prop
, offsets
, 0.0);
942 UnlockContext(Context
);
943 ReadUnlock(&Source
->queue_lock
);
944 *values
= offsets
[0];
947 case AL_CONE_OUTER_GAINHF
:
948 *values
= Source
->OuterGainHF
;
951 case AL_AIR_ABSORPTION_FACTOR
:
952 *values
= Source
->AirAbsorptionFactor
;
955 case AL_ROOM_ROLLOFF_FACTOR
:
956 *values
= Source
->RoomRolloffFactor
;
959 case AL_DOPPLER_FACTOR
:
960 *values
= Source
->DopplerFactor
;
964 ReadLock(&Source
->queue_lock
);
965 if(!(BufferList
=Source
->queue
))
972 ALbuffer
*buffer
= BufferList
->buffer
;
973 if(buffer
&& buffer
->SampleLen
> 0)
975 freq
= buffer
->Frequency
;
976 length
+= buffer
->SampleLen
;
978 } while((BufferList
=BufferList
->next
) != NULL
);
979 *values
= (ALdouble
)length
/ (ALdouble
)freq
;
981 ReadUnlock(&Source
->queue_lock
);
984 case AL_SAMPLE_RW_OFFSETS_SOFT
:
985 case AL_BYTE_RW_OFFSETS_SOFT
:
986 ReadLock(&Source
->queue_lock
);
987 LockContext(Context
);
988 updateLen
= (ALdouble
)Context
->Device
->UpdateSize
/
989 Context
->Device
->Frequency
;
990 GetSourceOffsets(Source
, prop
, values
, updateLen
);
991 UnlockContext(Context
);
992 ReadUnlock(&Source
->queue_lock
);
995 case AL_SEC_OFFSET_LATENCY_SOFT
:
996 ReadLock(&Source
->queue_lock
);
997 LockContext(Context
);
998 values
[0] = GetSourceSecOffset(Source
);
999 values
[1] = (ALdouble
)ALCdevice_GetLatency(Context
->Device
) /
1001 UnlockContext(Context
);
1002 ReadUnlock(&Source
->queue_lock
);
1006 LockContext(Context
);
1007 values
[0] = Source
->Position
[0];
1008 values
[1] = Source
->Position
[1];
1009 values
[2] = Source
->Position
[2];
1010 UnlockContext(Context
);
1014 LockContext(Context
);
1015 values
[0] = Source
->Velocity
[0];
1016 values
[1] = Source
->Velocity
[1];
1017 values
[2] = Source
->Velocity
[2];
1018 UnlockContext(Context
);
1022 LockContext(Context
);
1023 values
[0] = Source
->Orientation
[0];
1024 values
[1] = Source
->Orientation
[1];
1025 values
[2] = Source
->Orientation
[2];
1026 UnlockContext(Context
);
1029 case AL_SOURCE_RELATIVE
:
1032 case AL_SOURCE_STATE
:
1033 case AL_BUFFERS_QUEUED
:
1034 case AL_BUFFERS_PROCESSED
:
1035 case AL_SOURCE_TYPE
:
1036 case AL_DIRECT_FILTER_GAINHF_AUTO
:
1037 case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
:
1038 case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
:
1039 case AL_DIRECT_CHANNELS_SOFT
:
1040 case AL_DISTANCE_MODEL
:
1041 if((err
=GetSourceiv(Source
, Context
, (int)prop
, ivals
)) != AL_FALSE
)
1042 *values
= (ALdouble
)ivals
[0];
1046 ERR("Unexpected property: 0x%04x\n", prop
);
1047 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_ENUM
, AL_FALSE
);
1050 static ALboolean
GetSourceiv(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, ALint
*values
)
1052 ALbufferlistitem
*BufferList
;
1058 case AL_SOURCE_RELATIVE
:
1059 *values
= Source
->HeadRelative
;
1063 *values
= Source
->Looping
;
1067 ReadLock(&Source
->queue_lock
);
1068 BufferList
= (Source
->SourceType
== AL_STATIC
) ? Source
->queue
:
1069 Source
->current_buffer
;
1070 *values
= (BufferList
&& BufferList
->buffer
) ? BufferList
->buffer
->id
: 0;
1071 ReadUnlock(&Source
->queue_lock
);
1074 case AL_SOURCE_STATE
:
1075 *values
= Source
->state
;
1079 ReadLock(&Source
->queue_lock
);
1080 if(!(BufferList
=Source
->queue
))
1086 ALbuffer
*buffer
= BufferList
->buffer
;
1087 if(buffer
&& buffer
->SampleLen
> 0)
1089 ALuint byte_align
, sample_align
;
1090 if(buffer
->OriginalType
== UserFmtIMA4
)
1092 ALsizei align
= (buffer
->OriginalAlign
-1)/2 + 4;
1093 byte_align
= align
* ChannelsFromFmt(buffer
->FmtChannels
);
1094 sample_align
= buffer
->OriginalAlign
;
1096 else if(buffer
->OriginalType
== UserFmtMSADPCM
)
1098 ALsizei align
= (buffer
->OriginalAlign
-2)/2 + 7;
1099 byte_align
= align
* ChannelsFromFmt(buffer
->FmtChannels
);
1100 sample_align
= buffer
->OriginalAlign
;
1104 ALsizei align
= buffer
->OriginalAlign
;
1105 byte_align
= align
* ChannelsFromFmt(buffer
->FmtChannels
);
1106 sample_align
= buffer
->OriginalAlign
;
1109 length
+= buffer
->SampleLen
/ sample_align
* byte_align
;
1111 } while((BufferList
=BufferList
->next
) != NULL
);
1114 ReadUnlock(&Source
->queue_lock
);
1117 case siSampleLength
:
1118 ReadLock(&Source
->queue_lock
);
1119 if(!(BufferList
=Source
->queue
))
1125 ALbuffer
*buffer
= BufferList
->buffer
;
1126 if(buffer
) length
+= buffer
->SampleLen
;
1127 } while((BufferList
=BufferList
->next
) != NULL
);
1130 ReadUnlock(&Source
->queue_lock
);
1133 case AL_BUFFERS_QUEUED
:
1134 ReadLock(&Source
->queue_lock
);
1135 if(!(BufferList
=Source
->queue
))
1142 } while((BufferList
=BufferList
->next
) != NULL
);
1145 ReadUnlock(&Source
->queue_lock
);
1148 case AL_BUFFERS_PROCESSED
:
1149 ReadLock(&Source
->queue_lock
);
1150 if(Source
->Looping
|| Source
->SourceType
!= AL_STREAMING
)
1152 /* Buffers on a looping source are in a perpetual state of
1153 * PENDING, so don't report any as PROCESSED */
1158 const ALbufferlistitem
*BufferList
= Source
->queue
;
1160 while(BufferList
&& BufferList
!= Source
->current_buffer
)
1163 BufferList
= BufferList
->next
;
1167 ReadUnlock(&Source
->queue_lock
);
1170 case AL_SOURCE_TYPE
:
1171 *values
= Source
->SourceType
;
1174 case AL_DIRECT_FILTER_GAINHF_AUTO
:
1175 *values
= Source
->DryGainHFAuto
;
1178 case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
:
1179 *values
= Source
->WetGainAuto
;
1182 case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
:
1183 *values
= Source
->WetGainHFAuto
;
1186 case AL_DIRECT_CHANNELS_SOFT
:
1187 *values
= Source
->DirectChannels
;
1190 case AL_DISTANCE_MODEL
:
1191 *values
= Source
->DistanceModel
;
1194 case AL_MAX_DISTANCE
:
1195 case AL_ROLLOFF_FACTOR
:
1196 case AL_REFERENCE_DISTANCE
:
1197 case AL_CONE_INNER_ANGLE
:
1198 case AL_CONE_OUTER_ANGLE
:
1200 case AL_SAMPLE_OFFSET
:
1201 case AL_BYTE_OFFSET
:
1202 case AL_DOPPLER_FACTOR
:
1203 if((err
=GetSourcedv(Source
, Context
, (int)prop
, dvals
)) != AL_FALSE
)
1204 *values
= (ALint
)dvals
[0];
1207 case AL_SAMPLE_RW_OFFSETS_SOFT
:
1208 case AL_BYTE_RW_OFFSETS_SOFT
:
1209 if((err
=GetSourcedv(Source
, Context
, (int)prop
, dvals
)) != AL_FALSE
)
1211 values
[0] = (ALint
)dvals
[0];
1212 values
[1] = (ALint
)dvals
[1];
1219 if((err
=GetSourcedv(Source
, Context
, (int)prop
, dvals
)) != AL_FALSE
)
1221 values
[0] = (ALint
)dvals
[0];
1222 values
[1] = (ALint
)dvals
[1];
1223 values
[2] = (ALint
)dvals
[2];
1227 case siSampleOffsetLatencySOFT
:
1231 case siDirectFilter
:
1232 case siAuxSendFilter
:
1237 ERR("Unexpected property: 0x%04x\n", prop
);
1238 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_ENUM
, AL_FALSE
);
1241 static ALboolean
GetSourcei64v(ALsource
*Source
, ALCcontext
*Context
, SrcIntProp prop
, ALint64
*values
)
1249 case AL_SAMPLE_OFFSET_LATENCY_SOFT
:
1250 ReadLock(&Source
->queue_lock
);
1251 LockContext(Context
);
1252 values
[0] = GetSourceOffset(Source
);
1253 values
[1] = ALCdevice_GetLatency(Context
->Device
);
1254 UnlockContext(Context
);
1255 ReadUnlock(&Source
->queue_lock
);
1258 case AL_MAX_DISTANCE
:
1259 case AL_ROLLOFF_FACTOR
:
1260 case AL_REFERENCE_DISTANCE
:
1261 case AL_CONE_INNER_ANGLE
:
1262 case AL_CONE_OUTER_ANGLE
:
1264 case AL_SAMPLE_OFFSET
:
1265 case AL_BYTE_OFFSET
:
1266 case AL_DOPPLER_FACTOR
:
1267 if((err
=GetSourcedv(Source
, Context
, (int)prop
, dvals
)) != AL_FALSE
)
1268 *values
= (ALint64
)dvals
[0];
1271 case AL_SAMPLE_RW_OFFSETS_SOFT
:
1272 case AL_BYTE_RW_OFFSETS_SOFT
:
1273 if((err
=GetSourcedv(Source
, Context
, (int)prop
, dvals
)) != AL_FALSE
)
1275 values
[0] = (ALint64
)dvals
[0];
1276 values
[1] = (ALint64
)dvals
[1];
1283 if((err
=GetSourcedv(Source
, Context
, (int)prop
, dvals
)) != AL_FALSE
)
1285 values
[0] = (ALint64
)dvals
[0];
1286 values
[1] = (ALint64
)dvals
[1];
1287 values
[2] = (ALint64
)dvals
[2];
1291 case AL_SOURCE_RELATIVE
:
1293 case AL_SOURCE_STATE
:
1294 case AL_BUFFERS_QUEUED
:
1295 case AL_BUFFERS_PROCESSED
:
1297 case siSampleLength
:
1298 case AL_SOURCE_TYPE
:
1299 case AL_DIRECT_FILTER_GAINHF_AUTO
:
1300 case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
:
1301 case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
:
1302 case AL_DIRECT_CHANNELS_SOFT
:
1303 case AL_DISTANCE_MODEL
:
1304 if((err
=GetSourceiv(Source
, Context
, (int)prop
, ivals
)) != AL_FALSE
)
1309 case siDirectFilter
:
1310 if((err
=GetSourceiv(Source
, Context
, (int)prop
, ivals
)) != AL_FALSE
)
1311 *values
= (ALuint
)ivals
[0];
1314 case siAuxSendFilter
:
1315 if((err
=GetSourceiv(Source
, Context
, (int)prop
, ivals
)) != AL_FALSE
)
1317 values
[0] = (ALuint
)ivals
[0];
1318 values
[1] = (ALuint
)ivals
[1];
1319 values
[2] = (ALuint
)ivals
[2];
1324 ERR("Unexpected property: 0x%04x\n", prop
);
1325 SET_ERROR_AND_RETURN_VALUE(Context
, AL_INVALID_ENUM
, AL_FALSE
);
1329 AL_API ALvoid AL_APIENTRY
alGenSources(ALsizei n
, ALuint
*sources
)
1331 ALCcontext
*context
;
1335 context
= GetContextRef();
1336 if(!context
) return;
1339 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
1340 for(cur
= 0;cur
< n
;cur
++)
1342 ALsource
*source
= al_calloc(16, sizeof(ALsource
));
1345 alDeleteSources(cur
, sources
);
1346 SET_ERROR_AND_GOTO(context
, AL_OUT_OF_MEMORY
, done
);
1348 InitSourceParams(source
);
1350 err
= NewThunkEntry(&source
->id
);
1351 if(err
== AL_NO_ERROR
)
1352 err
= InsertUIntMapEntry(&context
->SourceMap
, source
->id
, source
);
1353 if(err
!= AL_NO_ERROR
)
1355 FreeThunkEntry(source
->id
);
1356 memset(source
, 0, sizeof(ALsource
));
1359 alDeleteSources(cur
, sources
);
1360 SET_ERROR_AND_GOTO(context
, err
, done
);
1363 sources
[cur
] = source
->id
;
1367 ALCcontext_DecRef(context
);
1371 AL_API ALvoid AL_APIENTRY
alDeleteSources(ALsizei n
, const ALuint
*sources
)
1373 ALCcontext
*context
;
1374 ALbufferlistitem
*BufferList
;
1378 context
= GetContextRef();
1379 if(!context
) return;
1382 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
1384 /* Check that all Sources are valid */
1385 for(i
= 0;i
< n
;i
++)
1387 if(LookupSource(context
, sources
[i
]) == NULL
)
1388 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
1390 for(i
= 0;i
< n
;i
++)
1392 ALactivesource
**srclist
, **srclistend
;
1394 if((Source
=RemoveSource(context
, sources
[i
])) == NULL
)
1396 FreeThunkEntry(Source
->id
);
1398 LockContext(context
);
1399 srclist
= context
->ActiveSources
;
1400 srclistend
= srclist
+ context
->ActiveSourceCount
;
1401 while(srclist
!= srclistend
)
1403 if((*srclist
)->Source
== Source
)
1405 ALactivesource
*temp
= *(--srclistend
);
1406 *srclistend
= *srclist
;
1408 --(context
->ActiveSourceCount
);
1413 UnlockContext(context
);
1415 while(Source
->queue
!= NULL
)
1417 BufferList
= Source
->queue
;
1418 Source
->queue
= BufferList
->next
;
1420 if(BufferList
->buffer
!= NULL
)
1421 DecrementRef(&BufferList
->buffer
->ref
);
1425 for(j
= 0;j
< MAX_SENDS
;++j
)
1427 if(Source
->Send
[j
].Slot
)
1428 DecrementRef(&Source
->Send
[j
].Slot
->ref
);
1429 Source
->Send
[j
].Slot
= NULL
;
1432 memset(Source
, 0, sizeof(*Source
));
1437 ALCcontext_DecRef(context
);
1441 AL_API ALboolean AL_APIENTRY
alIsSource(ALuint source
)
1443 ALCcontext
*context
;
1446 context
= GetContextRef();
1447 if(!context
) return AL_FALSE
;
1449 ret
= (LookupSource(context
, source
) ? AL_TRUE
: AL_FALSE
);
1451 ALCcontext_DecRef(context
);
1457 AL_API ALvoid AL_APIENTRY
alSourcef(ALuint source
, ALenum param
, ALfloat value
)
1459 ALCcontext
*Context
;
1462 Context
= GetContextRef();
1463 if(!Context
) return;
1465 if((Source
=LookupSource(Context
, source
)) == NULL
)
1466 alSetError(Context
, AL_INVALID_NAME
);
1467 else if(!(FloatValsByProp(param
) == 1))
1468 alSetError(Context
, AL_INVALID_ENUM
);
1470 SetSourcefv(Source
, Context
, param
, &value
);
1472 ALCcontext_DecRef(Context
);
1475 AL_API ALvoid AL_APIENTRY
alSource3f(ALuint source
, ALenum param
, ALfloat value1
, ALfloat value2
, ALfloat value3
)
1477 ALCcontext
*Context
;
1480 Context
= GetContextRef();
1481 if(!Context
) return;
1483 if((Source
=LookupSource(Context
, source
)) == NULL
)
1484 alSetError(Context
, AL_INVALID_NAME
);
1485 else if(!(FloatValsByProp(param
) == 3))
1486 alSetError(Context
, AL_INVALID_ENUM
);
1489 ALfloat fvals
[3] = { value1
, value2
, value3
};
1490 SetSourcefv(Source
, Context
, param
, fvals
);
1493 ALCcontext_DecRef(Context
);
1496 AL_API ALvoid AL_APIENTRY
alSourcefv(ALuint source
, ALenum param
, const ALfloat
*values
)
1498 ALCcontext
*Context
;
1501 Context
= GetContextRef();
1502 if(!Context
) return;
1504 if((Source
=LookupSource(Context
, source
)) == NULL
)
1505 alSetError(Context
, AL_INVALID_NAME
);
1507 alSetError(Context
, AL_INVALID_VALUE
);
1508 else if(!(FloatValsByProp(param
) > 0))
1509 alSetError(Context
, AL_INVALID_ENUM
);
1511 SetSourcefv(Source
, Context
, param
, values
);
1513 ALCcontext_DecRef(Context
);
1517 AL_API ALvoid AL_APIENTRY
alSourcedSOFT(ALuint source
, ALenum param
, ALdouble value
)
1519 ALCcontext
*Context
;
1522 Context
= GetContextRef();
1523 if(!Context
) return;
1525 if((Source
=LookupSource(Context
, source
)) == NULL
)
1526 alSetError(Context
, AL_INVALID_NAME
);
1527 else if(!(DoubleValsByProp(param
) == 1))
1528 alSetError(Context
, AL_INVALID_ENUM
);
1531 ALfloat fval
= (ALfloat
)value
;
1532 SetSourcefv(Source
, Context
, param
, &fval
);
1535 ALCcontext_DecRef(Context
);
1538 AL_API ALvoid AL_APIENTRY
alSource3dSOFT(ALuint source
, ALenum param
, ALdouble value1
, ALdouble value2
, ALdouble value3
)
1540 ALCcontext
*Context
;
1543 Context
= GetContextRef();
1544 if(!Context
) return;
1546 if((Source
=LookupSource(Context
, source
)) == NULL
)
1547 alSetError(Context
, AL_INVALID_NAME
);
1548 else if(!(DoubleValsByProp(param
) == 3))
1549 alSetError(Context
, AL_INVALID_ENUM
);
1552 ALfloat fvals
[3] = { (ALfloat
)value1
, (ALfloat
)value2
, (ALfloat
)value3
};
1553 SetSourcefv(Source
, Context
, param
, fvals
);
1556 ALCcontext_DecRef(Context
);
1559 AL_API ALvoid AL_APIENTRY
alSourcedvSOFT(ALuint source
, ALenum param
, const ALdouble
*values
)
1561 ALCcontext
*Context
;
1565 Context
= GetContextRef();
1566 if(!Context
) return;
1568 if((Source
=LookupSource(Context
, source
)) == NULL
)
1569 alSetError(Context
, AL_INVALID_NAME
);
1571 alSetError(Context
, AL_INVALID_VALUE
);
1572 else if(!((count
=DoubleValsByProp(param
)) > 0 && count
<= 3))
1573 alSetError(Context
, AL_INVALID_ENUM
);
1579 for(i
= 0;i
< count
;i
++)
1580 fvals
[i
] = (ALfloat
)values
[i
];
1581 SetSourcefv(Source
, Context
, param
, fvals
);
1584 ALCcontext_DecRef(Context
);
1588 AL_API ALvoid AL_APIENTRY
alSourcei(ALuint source
, ALenum param
, ALint value
)
1590 ALCcontext
*Context
;
1593 Context
= GetContextRef();
1594 if(!Context
) return;
1596 if((Source
=LookupSource(Context
, source
)) == NULL
)
1597 alSetError(Context
, AL_INVALID_NAME
);
1598 else if(!(IntValsByProp(param
) == 1))
1599 alSetError(Context
, AL_INVALID_ENUM
);
1601 SetSourceiv(Source
, Context
, param
, &value
);
1603 ALCcontext_DecRef(Context
);
1606 AL_API
void AL_APIENTRY
alSource3i(ALuint source
, ALenum param
, ALint value1
, ALint value2
, ALint value3
)
1608 ALCcontext
*Context
;
1611 Context
= GetContextRef();
1612 if(!Context
) return;
1614 if((Source
=LookupSource(Context
, source
)) == NULL
)
1615 alSetError(Context
, AL_INVALID_NAME
);
1616 else if(!(IntValsByProp(param
) == 3))
1617 alSetError(Context
, AL_INVALID_ENUM
);
1620 ALint ivals
[3] = { value1
, value2
, value3
};
1621 SetSourceiv(Source
, Context
, param
, ivals
);
1624 ALCcontext_DecRef(Context
);
1627 AL_API
void AL_APIENTRY
alSourceiv(ALuint source
, ALenum param
, const ALint
*values
)
1629 ALCcontext
*Context
;
1632 Context
= GetContextRef();
1633 if(!Context
) return;
1635 if((Source
=LookupSource(Context
, source
)) == NULL
)
1636 alSetError(Context
, AL_INVALID_NAME
);
1638 alSetError(Context
, AL_INVALID_VALUE
);
1639 else if(!(IntValsByProp(param
) > 0))
1640 alSetError(Context
, AL_INVALID_ENUM
);
1642 SetSourceiv(Source
, Context
, param
, values
);
1644 ALCcontext_DecRef(Context
);
1648 AL_API ALvoid AL_APIENTRY
alSourcei64SOFT(ALuint source
, ALenum param
, ALint64SOFT value
)
1650 ALCcontext
*Context
;
1653 Context
= GetContextRef();
1654 if(!Context
) return;
1656 if((Source
=LookupSource(Context
, source
)) == NULL
)
1657 alSetError(Context
, AL_INVALID_NAME
);
1658 else if(!(Int64ValsByProp(param
) == 1))
1659 alSetError(Context
, AL_INVALID_ENUM
);
1661 SetSourcei64v(Source
, Context
, param
, &value
);
1663 ALCcontext_DecRef(Context
);
1666 AL_API
void AL_APIENTRY
alSource3i64SOFT(ALuint source
, ALenum param
, ALint64SOFT value1
, ALint64SOFT value2
, ALint64SOFT value3
)
1668 ALCcontext
*Context
;
1671 Context
= GetContextRef();
1672 if(!Context
) return;
1674 if((Source
=LookupSource(Context
, source
)) == NULL
)
1675 alSetError(Context
, AL_INVALID_NAME
);
1676 else if(!(Int64ValsByProp(param
) == 3))
1677 alSetError(Context
, AL_INVALID_ENUM
);
1680 ALint64SOFT i64vals
[3] = { value1
, value2
, value3
};
1681 SetSourcei64v(Source
, Context
, param
, i64vals
);
1684 ALCcontext_DecRef(Context
);
1687 AL_API
void AL_APIENTRY
alSourcei64vSOFT(ALuint source
, ALenum param
, const ALint64SOFT
*values
)
1689 ALCcontext
*Context
;
1692 Context
= GetContextRef();
1693 if(!Context
) return;
1695 if((Source
=LookupSource(Context
, source
)) == NULL
)
1696 alSetError(Context
, AL_INVALID_NAME
);
1698 alSetError(Context
, AL_INVALID_VALUE
);
1699 else if(!(Int64ValsByProp(param
) > 0))
1700 alSetError(Context
, AL_INVALID_ENUM
);
1702 SetSourcei64v(Source
, Context
, param
, values
);
1704 ALCcontext_DecRef(Context
);
1708 AL_API ALvoid AL_APIENTRY
alGetSourcef(ALuint source
, ALenum param
, ALfloat
*value
)
1710 ALCcontext
*Context
;
1713 Context
= GetContextRef();
1714 if(!Context
) return;
1716 if((Source
=LookupSource(Context
, source
)) == NULL
)
1717 alSetError(Context
, AL_INVALID_NAME
);
1719 alSetError(Context
, AL_INVALID_VALUE
);
1720 else if(!(FloatValsByProp(param
) == 1))
1721 alSetError(Context
, AL_INVALID_ENUM
);
1725 if(GetSourcedv(Source
, Context
, param
, &dval
))
1726 *value
= (ALfloat
)dval
;
1729 ALCcontext_DecRef(Context
);
1733 AL_API ALvoid AL_APIENTRY
alGetSource3f(ALuint source
, ALenum param
, ALfloat
*value1
, ALfloat
*value2
, ALfloat
*value3
)
1735 ALCcontext
*Context
;
1738 Context
= GetContextRef();
1739 if(!Context
) return;
1741 if((Source
=LookupSource(Context
, source
)) == NULL
)
1742 alSetError(Context
, AL_INVALID_NAME
);
1743 else if(!(value1
&& value2
&& value3
))
1744 alSetError(Context
, AL_INVALID_VALUE
);
1745 else if(!(FloatValsByProp(param
) == 3))
1746 alSetError(Context
, AL_INVALID_ENUM
);
1750 if(GetSourcedv(Source
, Context
, param
, dvals
))
1752 *value1
= (ALfloat
)dvals
[0];
1753 *value2
= (ALfloat
)dvals
[1];
1754 *value3
= (ALfloat
)dvals
[2];
1758 ALCcontext_DecRef(Context
);
1762 AL_API ALvoid AL_APIENTRY
alGetSourcefv(ALuint source
, ALenum param
, ALfloat
*values
)
1764 ALCcontext
*Context
;
1768 Context
= GetContextRef();
1769 if(!Context
) return;
1771 if((Source
=LookupSource(Context
, source
)) == NULL
)
1772 alSetError(Context
, AL_INVALID_NAME
);
1774 alSetError(Context
, AL_INVALID_VALUE
);
1775 else if(!((count
=FloatValsByProp(param
)) > 0 && count
<= 3))
1776 alSetError(Context
, AL_INVALID_ENUM
);
1780 if(GetSourcedv(Source
, Context
, param
, dvals
))
1783 for(i
= 0;i
< count
;i
++)
1784 values
[i
] = (ALfloat
)dvals
[i
];
1788 ALCcontext_DecRef(Context
);
1792 AL_API
void AL_APIENTRY
alGetSourcedSOFT(ALuint source
, ALenum param
, ALdouble
*value
)
1794 ALCcontext
*Context
;
1797 Context
= GetContextRef();
1798 if(!Context
) return;
1800 if((Source
=LookupSource(Context
, source
)) == NULL
)
1801 alSetError(Context
, AL_INVALID_NAME
);
1803 alSetError(Context
, AL_INVALID_VALUE
);
1804 else if(!(DoubleValsByProp(param
) == 1))
1805 alSetError(Context
, AL_INVALID_ENUM
);
1807 GetSourcedv(Source
, Context
, param
, value
);
1809 ALCcontext_DecRef(Context
);
1812 AL_API
void AL_APIENTRY
alGetSource3dSOFT(ALuint source
, ALenum param
, ALdouble
*value1
, ALdouble
*value2
, ALdouble
*value3
)
1814 ALCcontext
*Context
;
1817 Context
= GetContextRef();
1818 if(!Context
) return;
1820 if((Source
=LookupSource(Context
, source
)) == NULL
)
1821 alSetError(Context
, AL_INVALID_NAME
);
1822 else if(!(value1
&& value2
&& value3
))
1823 alSetError(Context
, AL_INVALID_VALUE
);
1824 else if(!(DoubleValsByProp(param
) == 3))
1825 alSetError(Context
, AL_INVALID_ENUM
);
1829 if(GetSourcedv(Source
, Context
, param
, dvals
))
1837 ALCcontext_DecRef(Context
);
1840 AL_API
void AL_APIENTRY
alGetSourcedvSOFT(ALuint source
, ALenum param
, ALdouble
*values
)
1842 ALCcontext
*Context
;
1845 Context
= GetContextRef();
1846 if(!Context
) return;
1848 if((Source
=LookupSource(Context
, source
)) == NULL
)
1849 alSetError(Context
, AL_INVALID_NAME
);
1851 alSetError(Context
, AL_INVALID_VALUE
);
1852 else if(!(DoubleValsByProp(param
) > 0))
1853 alSetError(Context
, AL_INVALID_ENUM
);
1855 GetSourcedv(Source
, Context
, param
, values
);
1857 ALCcontext_DecRef(Context
);
1861 AL_API ALvoid AL_APIENTRY
alGetSourcei(ALuint source
, ALenum param
, ALint
*value
)
1863 ALCcontext
*Context
;
1866 Context
= GetContextRef();
1867 if(!Context
) return;
1869 if((Source
=LookupSource(Context
, source
)) == NULL
)
1870 alSetError(Context
, AL_INVALID_NAME
);
1872 alSetError(Context
, AL_INVALID_VALUE
);
1873 else if(!(IntValsByProp(param
) == 1))
1874 alSetError(Context
, AL_INVALID_ENUM
);
1876 GetSourceiv(Source
, Context
, param
, value
);
1878 ALCcontext_DecRef(Context
);
1882 AL_API
void AL_APIENTRY
alGetSource3i(ALuint source
, ALenum param
, ALint
*value1
, ALint
*value2
, ALint
*value3
)
1884 ALCcontext
*Context
;
1887 Context
= GetContextRef();
1888 if(!Context
) return;
1890 if((Source
=LookupSource(Context
, source
)) == NULL
)
1891 alSetError(Context
, AL_INVALID_NAME
);
1892 else if(!(value1
&& value2
&& value3
))
1893 alSetError(Context
, AL_INVALID_VALUE
);
1894 else if(!(IntValsByProp(param
) == 3))
1895 alSetError(Context
, AL_INVALID_ENUM
);
1899 if(GetSourceiv(Source
, Context
, param
, ivals
))
1907 ALCcontext_DecRef(Context
);
1911 AL_API
void AL_APIENTRY
alGetSourceiv(ALuint source
, ALenum param
, ALint
*values
)
1913 ALCcontext
*Context
;
1916 Context
= GetContextRef();
1917 if(!Context
) return;
1919 if((Source
=LookupSource(Context
, source
)) == NULL
)
1920 alSetError(Context
, AL_INVALID_NAME
);
1922 alSetError(Context
, AL_INVALID_VALUE
);
1923 else if(!(IntValsByProp(param
) > 0))
1924 alSetError(Context
, AL_INVALID_ENUM
);
1926 GetSourceiv(Source
, Context
, param
, values
);
1928 ALCcontext_DecRef(Context
);
1932 AL_API
void AL_APIENTRY
alGetSourcei64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value
)
1934 ALCcontext
*Context
;
1937 Context
= GetContextRef();
1938 if(!Context
) return;
1940 if((Source
=LookupSource(Context
, source
)) == NULL
)
1941 alSetError(Context
, AL_INVALID_NAME
);
1943 alSetError(Context
, AL_INVALID_VALUE
);
1944 else if(!(Int64ValsByProp(param
) == 1))
1945 alSetError(Context
, AL_INVALID_ENUM
);
1947 GetSourcei64v(Source
, Context
, param
, value
);
1949 ALCcontext_DecRef(Context
);
1952 AL_API
void AL_APIENTRY
alGetSource3i64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value1
, ALint64SOFT
*value2
, ALint64SOFT
*value3
)
1954 ALCcontext
*Context
;
1957 Context
= GetContextRef();
1958 if(!Context
) return;
1960 if((Source
=LookupSource(Context
, source
)) == NULL
)
1961 alSetError(Context
, AL_INVALID_NAME
);
1962 else if(!(value1
&& value2
&& value3
))
1963 alSetError(Context
, AL_INVALID_VALUE
);
1964 else if(!(Int64ValsByProp(param
) == 3))
1965 alSetError(Context
, AL_INVALID_ENUM
);
1969 if(GetSourcei64v(Source
, Context
, param
, i64vals
))
1971 *value1
= i64vals
[0];
1972 *value2
= i64vals
[1];
1973 *value3
= i64vals
[2];
1977 ALCcontext_DecRef(Context
);
1980 AL_API
void AL_APIENTRY
alGetSourcei64vSOFT(ALuint source
, ALenum param
, ALint64SOFT
*values
)
1982 ALCcontext
*Context
;
1985 Context
= GetContextRef();
1986 if(!Context
) return;
1988 if((Source
=LookupSource(Context
, source
)) == NULL
)
1989 alSetError(Context
, AL_INVALID_NAME
);
1991 alSetError(Context
, AL_INVALID_VALUE
);
1992 else if(!(Int64ValsByProp(param
) > 0))
1993 alSetError(Context
, AL_INVALID_ENUM
);
1995 GetSourcei64v(Source
, Context
, param
, values
);
1997 ALCcontext_DecRef(Context
);
2001 AL_API ALvoid AL_APIENTRY
alSourcePlay(ALuint source
)
2003 alSourcePlayv(1, &source
);
2005 AL_API ALvoid AL_APIENTRY
alSourcePlayv(ALsizei n
, const ALuint
*sources
)
2007 ALCcontext
*context
;
2011 context
= GetContextRef();
2012 if(!context
) return;
2015 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2016 for(i
= 0;i
< n
;i
++)
2018 if(!LookupSource(context
, sources
[i
]))
2019 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
2022 LockContext(context
);
2023 while(n
> context
->MaxActiveSources
-context
->ActiveSourceCount
)
2025 ALactivesource
**temp
= NULL
;
2028 newcount
= context
->MaxActiveSources
<< 1;
2030 temp
= realloc(context
->ActiveSources
,
2031 newcount
* sizeof(context
->ActiveSources
[0]));
2034 UnlockContext(context
);
2035 SET_ERROR_AND_GOTO(context
, AL_OUT_OF_MEMORY
, done
);
2037 for(i
= context
->MaxActiveSources
;i
< newcount
;i
++)
2040 context
->ActiveSources
= temp
;
2041 context
->MaxActiveSources
= newcount
;
2044 for(i
= 0;i
< n
;i
++)
2046 source
= LookupSource(context
, sources
[i
]);
2047 if(context
->DeferUpdates
) source
->new_state
= AL_PLAYING
;
2048 else SetSourceState(source
, context
, AL_PLAYING
);
2050 UnlockContext(context
);
2053 ALCcontext_DecRef(context
);
2056 AL_API ALvoid AL_APIENTRY
alSourcePause(ALuint source
)
2058 alSourcePausev(1, &source
);
2060 AL_API ALvoid AL_APIENTRY
alSourcePausev(ALsizei n
, const ALuint
*sources
)
2062 ALCcontext
*context
;
2066 context
= GetContextRef();
2067 if(!context
) return;
2070 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2071 for(i
= 0;i
< n
;i
++)
2073 if(!LookupSource(context
, sources
[i
]))
2074 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
2077 LockContext(context
);
2078 for(i
= 0;i
< n
;i
++)
2080 source
= LookupSource(context
, sources
[i
]);
2081 if(context
->DeferUpdates
) source
->new_state
= AL_PAUSED
;
2082 else SetSourceState(source
, context
, AL_PAUSED
);
2084 UnlockContext(context
);
2087 ALCcontext_DecRef(context
);
2090 AL_API ALvoid AL_APIENTRY
alSourceStop(ALuint source
)
2092 alSourceStopv(1, &source
);
2094 AL_API ALvoid AL_APIENTRY
alSourceStopv(ALsizei n
, const ALuint
*sources
)
2096 ALCcontext
*context
;
2100 context
= GetContextRef();
2101 if(!context
) return;
2104 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2105 for(i
= 0;i
< n
;i
++)
2107 if(!LookupSource(context
, sources
[i
]))
2108 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
2111 LockContext(context
);
2112 for(i
= 0;i
< n
;i
++)
2114 source
= LookupSource(context
, sources
[i
]);
2115 source
->new_state
= AL_NONE
;
2116 SetSourceState(source
, context
, AL_STOPPED
);
2118 UnlockContext(context
);
2121 ALCcontext_DecRef(context
);
2124 AL_API ALvoid AL_APIENTRY
alSourceRewind(ALuint source
)
2126 alSourceRewindv(1, &source
);
2128 AL_API ALvoid AL_APIENTRY
alSourceRewindv(ALsizei n
, const ALuint
*sources
)
2130 ALCcontext
*context
;
2134 context
= GetContextRef();
2135 if(!context
) return;
2138 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2139 for(i
= 0;i
< n
;i
++)
2141 if(!LookupSource(context
, sources
[i
]))
2142 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
2145 LockContext(context
);
2146 for(i
= 0;i
< n
;i
++)
2148 source
= LookupSource(context
, sources
[i
]);
2149 source
->new_state
= AL_NONE
;
2150 SetSourceState(source
, context
, AL_INITIAL
);
2152 UnlockContext(context
);
2155 ALCcontext_DecRef(context
);
2159 AL_API ALvoid AL_APIENTRY
alSourceQueueBuffers(ALuint src
, ALsizei nb
, const ALuint
*buffers
)
2162 ALCcontext
*context
;
2165 ALbufferlistitem
*BufferListStart
;
2166 ALbufferlistitem
*BufferList
;
2167 ALbuffer
*BufferFmt
= NULL
;
2172 context
= GetContextRef();
2173 if(!context
) return;
2175 device
= context
->Device
;
2178 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2179 if((source
=LookupSource(context
, src
)) == NULL
)
2180 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
2182 WriteLock(&source
->queue_lock
);
2183 if(source
->SourceType
== AL_STATIC
)
2185 WriteUnlock(&source
->queue_lock
);
2186 /* Can't queue on a Static Source */
2187 SET_ERROR_AND_GOTO(context
, AL_INVALID_OPERATION
, done
);
2190 /* Check for a valid Buffer, for its frequency and format */
2191 BufferList
= source
->queue
;
2194 if(BufferList
->buffer
)
2196 BufferFmt
= BufferList
->buffer
;
2199 BufferList
= BufferList
->next
;
2202 BufferListStart
= NULL
;
2204 for(i
= 0;i
< nb
;i
++)
2206 ALbuffer
*buffer
= NULL
;
2207 if(buffers
[i
] && (buffer
=LookupBuffer(device
, buffers
[i
])) == NULL
)
2209 WriteUnlock(&source
->queue_lock
);
2210 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, buffer_error
);
2213 if(!BufferListStart
)
2215 BufferListStart
= malloc(sizeof(ALbufferlistitem
));
2216 BufferListStart
->buffer
= buffer
;
2217 BufferListStart
->next
= NULL
;
2218 BufferListStart
->prev
= NULL
;
2219 BufferList
= BufferListStart
;
2223 BufferList
->next
= malloc(sizeof(ALbufferlistitem
));
2224 BufferList
->next
->buffer
= buffer
;
2225 BufferList
->next
->next
= NULL
;
2226 BufferList
->next
->prev
= BufferList
;
2227 BufferList
= BufferList
->next
;
2229 if(!buffer
) continue;
2231 /* Hold a read lock on each buffer being queued while checking all
2232 * provided buffers. This is done so other threads don't see an extra
2233 * reference on some buffers if this operation ends up failing. */
2234 ReadLock(&buffer
->lock
);
2235 IncrementRef(&buffer
->ref
);
2237 if(BufferFmt
== NULL
)
2241 source
->NumChannels
= ChannelsFromFmt(buffer
->FmtChannels
);
2242 source
->SampleSize
= BytesFromFmt(buffer
->FmtType
);
2244 else if(BufferFmt
->Frequency
!= buffer
->Frequency
||
2245 BufferFmt
->OriginalChannels
!= buffer
->OriginalChannels
||
2246 BufferFmt
->OriginalType
!= buffer
->OriginalType
)
2248 WriteUnlock(&source
->queue_lock
);
2249 SET_ERROR_AND_GOTO(context
, AL_INVALID_OPERATION
, buffer_error
);
2252 /* A buffer failed (invalid ID or format), so unlock and release
2253 * each buffer we had. */
2254 while(BufferList
!= NULL
)
2256 ALbufferlistitem
*prev
= BufferList
->prev
;
2257 if((buffer
=BufferList
->buffer
) != NULL
)
2259 DecrementRef(&buffer
->ref
);
2260 ReadUnlock(&buffer
->lock
);
2268 /* All buffers good, unlock them now. */
2269 while(BufferList
!= NULL
)
2271 ALbuffer
*buffer
= BufferList
->buffer
;
2272 if(buffer
) ReadUnlock(&buffer
->lock
);
2273 BufferList
= BufferList
->prev
;
2276 /* Source is now streaming */
2277 source
->SourceType
= AL_STREAMING
;
2279 if((BufferList
=CompExchangePtr((XchgPtr
*)&source
->queue
, NULL
, BufferListStart
)) != NULL
)
2281 /* Queue head is not NULL, append to the end of the queue */
2282 while(BufferList
->next
!= NULL
)
2283 BufferList
= BufferList
->next
;
2285 BufferListStart
->prev
= BufferList
;
2286 BufferList
->next
= BufferListStart
;
2288 CompExchangePtr((XchgPtr
*)&source
->current_buffer
, NULL
, BufferListStart
);
2289 WriteUnlock(&source
->queue_lock
);
2292 ALCcontext_DecRef(context
);
2295 AL_API ALvoid AL_APIENTRY
alSourceUnqueueBuffers(ALuint src
, ALsizei nb
, ALuint
*buffers
)
2297 ALCcontext
*context
;
2299 ALbufferlistitem
*BufferList
;
2300 ALbufferlistitem
*OldHead
;
2306 context
= GetContextRef();
2307 if(!context
) return;
2310 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2312 if((source
=LookupSource(context
, src
)) == NULL
)
2313 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
2315 WriteLock(&source
->queue_lock
);
2316 /* Find the new buffer queue head */
2317 BufferList
= source
->queue
;
2318 for(i
= 0;i
< nb
&& BufferList
;i
++)
2320 if(BufferList
== source
->current_buffer
)
2322 BufferList
= BufferList
->next
;
2324 if(source
->Looping
|| source
->SourceType
!= AL_STREAMING
|| i
!= nb
)
2326 WriteUnlock(&source
->queue_lock
);
2327 /* Trying to unqueue pending buffers, or a buffer that wasn't queued. */
2328 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
2331 /* Swap it, and cut the new head from the old. */
2332 OldHead
= ExchangePtr((XchgPtr
*)&source
->queue
, BufferList
);
2335 ALCdevice
*device
= context
->Device
;
2338 /* Cut the new head's link back to the old body. The mixer is robust
2339 * enough to handle the link back going away. Once the active mix (if
2340 * any) is complete, it's safe to finish cutting the old tail from the
2342 BufferList
= ExchangePtr((XchgPtr
*)&BufferList
->prev
, NULL
);
2343 if(((count
=ReadRef(&device
->MixCount
))&1) != 0)
2345 while(count
== ReadRef(&device
->MixCount
))
2348 BufferList
->next
= NULL
;
2350 WriteUnlock(&source
->queue_lock
);
2352 while(OldHead
!= NULL
)
2354 ALbufferlistitem
*next
= OldHead
->next
;
2355 ALbuffer
*buffer
= OldHead
->buffer
;
2361 *(buffers
++) = buffer
->id
;
2362 DecrementRef(&buffer
->ref
);
2370 ALCcontext_DecRef(context
);
2374 static ALvoid
InitSourceParams(ALsource
*Source
)
2378 RWLockInit(&Source
->queue_lock
);
2380 Source
->InnerAngle
= 360.0f
;
2381 Source
->OuterAngle
= 360.0f
;
2382 Source
->Pitch
= 1.0f
;
2383 Source
->Position
[0] = 0.0f
;
2384 Source
->Position
[1] = 0.0f
;
2385 Source
->Position
[2] = 0.0f
;
2386 Source
->Orientation
[0] = 0.0f
;
2387 Source
->Orientation
[1] = 0.0f
;
2388 Source
->Orientation
[2] = 0.0f
;
2389 Source
->Velocity
[0] = 0.0f
;
2390 Source
->Velocity
[1] = 0.0f
;
2391 Source
->Velocity
[2] = 0.0f
;
2392 Source
->RefDistance
= 1.0f
;
2393 Source
->MaxDistance
= FLT_MAX
;
2394 Source
->RollOffFactor
= 1.0f
;
2395 Source
->Looping
= AL_FALSE
;
2396 Source
->Gain
= 1.0f
;
2397 Source
->MinGain
= 0.0f
;
2398 Source
->MaxGain
= 1.0f
;
2399 Source
->OuterGain
= 0.0f
;
2400 Source
->OuterGainHF
= 1.0f
;
2402 Source
->DryGainHFAuto
= AL_TRUE
;
2403 Source
->WetGainAuto
= AL_TRUE
;
2404 Source
->WetGainHFAuto
= AL_TRUE
;
2405 Source
->AirAbsorptionFactor
= 0.0f
;
2406 Source
->RoomRolloffFactor
= 0.0f
;
2407 Source
->DopplerFactor
= 1.0f
;
2408 Source
->DirectChannels
= AL_FALSE
;
2410 Source
->Radius
= 0.0f
;
2412 Source
->DistanceModel
= DefaultDistanceModel
;
2414 Source
->Resampler
= DefaultResampler
;
2416 Source
->state
= AL_INITIAL
;
2417 Source
->new_state
= AL_NONE
;
2418 Source
->SourceType
= AL_UNDETERMINED
;
2419 Source
->Offset
= -1.0;
2421 Source
->queue
= NULL
;
2422 Source
->current_buffer
= NULL
;
2424 Source
->Direct
.Gain
= 1.0f
;
2425 Source
->Direct
.GainHF
= 1.0f
;
2426 Source
->Direct
.HFReference
= LOWPASSFREQREF
;
2427 Source
->Direct
.GainLF
= 1.0f
;
2428 Source
->Direct
.LFReference
= HIGHPASSFREQREF
;
2429 for(i
= 0;i
< MAX_SENDS
;i
++)
2431 Source
->Send
[i
].Gain
= 1.0f
;
2432 Source
->Send
[i
].GainHF
= 1.0f
;
2433 Source
->Send
[i
].HFReference
= LOWPASSFREQREF
;
2434 Source
->Send
[i
].GainLF
= 1.0f
;
2435 Source
->Send
[i
].LFReference
= HIGHPASSFREQREF
;
2438 Source
->NeedsUpdate
= AL_TRUE
;
2444 * Sets the source's new play state given its current state.
2446 ALvoid
SetSourceState(ALsource
*Source
, ALCcontext
*Context
, ALenum state
)
2448 ReadLock(&Source
->queue_lock
);
2449 if(state
== AL_PLAYING
)
2451 ALCdevice
*device
= Context
->Device
;
2452 ALbufferlistitem
*BufferList
;
2453 ALactivesource
*src
= NULL
;
2456 /* Check that there is a queue containing at least one valid, non zero
2458 BufferList
= Source
->queue
;
2462 if((buffer
=BufferList
->buffer
) != NULL
&& buffer
->SampleLen
> 0)
2464 BufferList
= BufferList
->next
;
2467 if(Source
->state
!= AL_PAUSED
)
2469 Source
->state
= AL_PLAYING
;
2470 Source
->position
= 0;
2471 Source
->position_fraction
= 0;
2472 Source
->current_buffer
= BufferList
;
2475 Source
->state
= AL_PLAYING
;
2477 // Check if an Offset has been set
2478 if(Source
->Offset
>= 0.0)
2479 ApplyOffset(Source
);
2481 /* If there's nothing to play, or device is disconnected, go right to
2483 if(!BufferList
|| !device
->Connected
)
2486 for(j
= 0;j
< Context
->ActiveSourceCount
;j
++)
2488 if(Context
->ActiveSources
[j
]->Source
== Source
)
2490 src
= Context
->ActiveSources
[j
];
2496 src
= Context
->ActiveSources
[Context
->ActiveSourceCount
];
2499 src
= al_malloc(16, sizeof(src
[0]));
2500 Context
->ActiveSources
[Context
->ActiveSourceCount
] = src
;
2502 memset(src
, 0, sizeof(*src
));
2504 src
->Source
= Source
;
2505 if(BufferList
->buffer
->FmtChannels
== FmtMono
)
2506 src
->Update
= CalcSourceParams
;
2508 src
->Update
= CalcNonAttnSourceParams
;
2509 Context
->ActiveSourceCount
++;
2515 src
->Direct
.Moving
= AL_FALSE
;
2516 src
->Direct
.Counter
= 0;
2517 for(j
= 0;j
< MAX_INPUT_CHANNELS
;j
++)
2519 for(k
= 0;k
< SRC_HISTORY_LENGTH
;k
++)
2520 src
->Direct
.Mix
.Hrtf
.State
[j
].History
[k
] = 0.0f
;
2521 for(k
= 0;k
< HRIR_LENGTH
;k
++)
2523 src
->Direct
.Mix
.Hrtf
.State
[j
].Values
[k
][0] = 0.0f
;
2524 src
->Direct
.Mix
.Hrtf
.State
[j
].Values
[k
][1] = 0.0f
;
2527 for(i
= 0;i
< device
->NumAuxSends
;i
++)
2529 src
->Send
[i
].Counter
= 0;
2530 src
->Send
[i
].Moving
= AL_FALSE
;
2533 Source
->NeedsUpdate
= AL_TRUE
;
2535 else if(state
== AL_PAUSED
)
2537 if(Source
->state
== AL_PLAYING
)
2538 Source
->state
= AL_PAUSED
;
2540 else if(state
== AL_STOPPED
)
2543 if(Source
->state
!= AL_INITIAL
)
2545 Source
->state
= AL_STOPPED
;
2546 Source
->current_buffer
= NULL
;
2548 Source
->Offset
= -1.0;
2550 else if(state
== AL_INITIAL
)
2552 if(Source
->state
!= AL_INITIAL
)
2554 Source
->state
= AL_INITIAL
;
2555 Source
->position
= 0;
2556 Source
->position_fraction
= 0;
2557 Source
->current_buffer
= Source
->queue
;
2559 Source
->Offset
= -1.0;
2561 ReadUnlock(&Source
->queue_lock
);
2566 * Gets the current read offset for the given Source, in 32.32 fixed-point
2567 * samples. The offset is relative to the start of the queue (not the start of
2568 * the current buffer).
2570 static ALint64
GetSourceOffset(const ALsource
*Source
)
2572 const ALbufferlistitem
*BufferList
;
2575 if(Source
->state
!= AL_PLAYING
&& Source
->state
!= AL_PAUSED
)
2578 /* NOTE: This is the offset into the *current* buffer, so add the length of
2579 * any played buffers */
2580 readPos
= (ALuint64
)Source
->position
<< 32;
2581 readPos
|= (ALuint64
)Source
->position_fraction
<< (32-FRACTIONBITS
);
2582 BufferList
= Source
->queue
;
2583 while(BufferList
&& BufferList
!= Source
->current_buffer
)
2585 if(BufferList
->buffer
)
2586 readPos
+= (ALuint64
)BufferList
->buffer
->SampleLen
<< 32;
2587 BufferList
= BufferList
->next
;
2590 return (ALint64
)minu64(readPos
, U64(0x7fffffffffffffff));
2593 /* GetSourceSecOffset
2595 * Gets the current read offset for the given Source, in seconds. The offset is
2596 * relative to the start of the queue (not the start of the current buffer).
2598 static ALdouble
GetSourceSecOffset(const ALsource
*Source
)
2600 const ALbufferlistitem
*BufferList
;
2601 const ALbuffer
*Buffer
= NULL
;
2604 if(Source
->state
!= AL_PLAYING
&& Source
->state
!= AL_PAUSED
)
2607 /* NOTE: This is the offset into the *current* buffer, so add the length of
2608 * any played buffers */
2609 readPos
= (ALuint64
)Source
->position
<< FRACTIONBITS
;
2610 readPos
|= (ALuint64
)Source
->position_fraction
;
2611 BufferList
= Source
->queue
;
2612 while(BufferList
&& BufferList
!= Source
->current_buffer
)
2614 const ALbuffer
*buffer
= BufferList
->buffer
;
2617 if(!Buffer
) Buffer
= buffer
;
2618 readPos
+= (ALuint64
)buffer
->SampleLen
<< FRACTIONBITS
;
2620 BufferList
= BufferList
->next
;
2623 while(BufferList
&& !Buffer
)
2625 Buffer
= BufferList
->buffer
;
2626 BufferList
= BufferList
->next
;
2628 assert(Buffer
!= NULL
);
2630 return (ALdouble
)readPos
/ (ALdouble
)FRACTIONONE
/ (ALdouble
)Buffer
->Frequency
;
2635 * Gets the current read and write offsets for the given Source, in the
2636 * appropriate format (Bytes, Samples or Seconds). The offsets are relative to
2637 * the start of the queue (not the start of the current buffer).
2639 static ALvoid
GetSourceOffsets(const ALsource
*Source
, ALenum name
, ALdouble
*offset
, ALdouble updateLen
)
2641 const ALbufferlistitem
*BufferList
;
2642 const ALbuffer
*Buffer
= NULL
;
2643 ALboolean readFin
= AL_FALSE
;
2644 ALuint readPos
, writePos
;
2645 ALuint totalBufferLen
;
2647 if(Source
->state
!= AL_PLAYING
&& Source
->state
!= AL_PAUSED
)
2654 if(updateLen
> 0.0 && updateLen
< 0.015)
2657 /* NOTE: This is the offset into the *current* buffer, so add the length of
2658 * any played buffers */
2660 readPos
= Source
->position
;
2661 BufferList
= Source
->queue
;
2662 while(BufferList
!= NULL
)
2664 const ALbuffer
*buffer
;
2665 readFin
= readFin
|| (BufferList
== Source
->current_buffer
);
2666 if((buffer
=BufferList
->buffer
) != NULL
)
2668 if(!Buffer
) Buffer
= buffer
;
2669 totalBufferLen
+= buffer
->SampleLen
;
2670 if(!readFin
) readPos
+= buffer
->SampleLen
;
2672 BufferList
= BufferList
->next
;
2674 assert(Buffer
!= NULL
);
2676 if(Source
->state
== AL_PLAYING
)
2677 writePos
= readPos
+ (ALuint
)(updateLen
*Buffer
->Frequency
);
2683 readPos
%= totalBufferLen
;
2684 writePos
%= totalBufferLen
;
2688 /* Wrap positions back to 0 */
2689 if(readPos
>= totalBufferLen
)
2691 if(writePos
>= totalBufferLen
)
2698 offset
[0] = (ALdouble
)readPos
/ Buffer
->Frequency
;
2699 offset
[1] = (ALdouble
)writePos
/ Buffer
->Frequency
;
2702 case AL_SAMPLE_OFFSET
:
2703 case AL_SAMPLE_RW_OFFSETS_SOFT
:
2704 offset
[0] = (ALdouble
)readPos
;
2705 offset
[1] = (ALdouble
)writePos
;
2708 case AL_BYTE_OFFSET
:
2709 case AL_BYTE_RW_OFFSETS_SOFT
:
2710 if(Buffer
->OriginalType
== UserFmtIMA4
)
2712 ALsizei align
= (Buffer
->OriginalAlign
-1)/2 + 4;
2713 ALuint BlockSize
= align
* ChannelsFromFmt(Buffer
->FmtChannels
);
2714 ALuint FrameBlockSize
= Buffer
->OriginalAlign
;
2716 /* Round down to nearest ADPCM block */
2717 offset
[0] = (ALdouble
)(readPos
/ FrameBlockSize
* BlockSize
);
2718 if(Source
->state
!= AL_PLAYING
)
2719 offset
[1] = offset
[0];
2722 /* Round up to nearest ADPCM block */
2723 offset
[1] = (ALdouble
)((writePos
+FrameBlockSize
-1) /
2724 FrameBlockSize
* BlockSize
);
2727 else if(Buffer
->OriginalType
== UserFmtMSADPCM
)
2729 ALsizei align
= (Buffer
->OriginalAlign
-2)/2 + 7;
2730 ALuint BlockSize
= align
* ChannelsFromFmt(Buffer
->FmtChannels
);
2731 ALuint FrameBlockSize
= Buffer
->OriginalAlign
;
2733 /* Round down to nearest ADPCM block */
2734 offset
[0] = (ALdouble
)(readPos
/ FrameBlockSize
* BlockSize
);
2735 if(Source
->state
!= AL_PLAYING
)
2736 offset
[1] = offset
[0];
2739 /* Round up to nearest ADPCM block */
2740 offset
[1] = (ALdouble
)((writePos
+FrameBlockSize
-1) /
2741 FrameBlockSize
* BlockSize
);
2746 ALuint FrameSize
= FrameSizeFromUserFmt(Buffer
->OriginalChannels
, Buffer
->OriginalType
);
2747 offset
[0] = (ALdouble
)(readPos
* FrameSize
);
2748 offset
[1] = (ALdouble
)(writePos
* FrameSize
);
2757 * Apply the stored playback offset to the Source. This function will update
2758 * the number of buffers "played" given the stored offset.
2760 ALboolean
ApplyOffset(ALsource
*Source
)
2762 ALbufferlistitem
*BufferList
;
2763 const ALbuffer
*Buffer
;
2764 ALint bufferLen
, totalBufferLen
;
2767 /* Get sample frame offset */
2768 offset
= GetSampleOffset(Source
);
2773 BufferList
= Source
->queue
;
2774 while(BufferList
&& totalBufferLen
<= offset
)
2776 Buffer
= BufferList
->buffer
;
2777 bufferLen
= Buffer
? Buffer
->SampleLen
: 0;
2779 if(bufferLen
> offset
-totalBufferLen
)
2781 /* Offset is in this buffer */
2782 Source
->current_buffer
= BufferList
;
2784 Source
->position
= offset
- totalBufferLen
;
2785 Source
->position_fraction
= 0;
2789 totalBufferLen
+= bufferLen
;
2791 BufferList
= BufferList
->next
;
2794 /* Offset is out of range of the queue */
2801 * Returns the sample offset into the Source's queue (from the Sample, Byte or
2802 * Second offset supplied by the application). This takes into account the fact
2803 * that the buffer format may have been modifed since.
2805 static ALint
GetSampleOffset(ALsource
*Source
)
2807 const ALbuffer
*Buffer
= NULL
;
2808 const ALbufferlistitem
*BufferList
;
2811 /* Find the first valid Buffer in the Queue */
2812 BufferList
= Source
->queue
;
2815 if(BufferList
->buffer
)
2817 Buffer
= BufferList
->buffer
;
2820 BufferList
= BufferList
->next
;
2825 Source
->Offset
= -1.0;
2829 switch(Source
->OffsetType
)
2831 case AL_BYTE_OFFSET
:
2832 /* Determine the ByteOffset (and ensure it is block aligned) */
2833 Offset
= (ALint
)Source
->Offset
;
2834 if(Buffer
->OriginalType
== UserFmtIMA4
)
2836 ALsizei align
= (Buffer
->OriginalAlign
-1)/2 + 4;
2837 Offset
/= align
* ChannelsFromUserFmt(Buffer
->OriginalChannels
);
2838 Offset
*= Buffer
->OriginalAlign
;
2840 else if(Buffer
->OriginalType
== UserFmtMSADPCM
)
2842 ALsizei align
= (Buffer
->OriginalAlign
-2)/2 + 7;
2843 Offset
/= align
* ChannelsFromUserFmt(Buffer
->OriginalChannels
);
2844 Offset
*= Buffer
->OriginalAlign
;
2847 Offset
/= FrameSizeFromUserFmt(Buffer
->OriginalChannels
, Buffer
->OriginalType
);
2850 case AL_SAMPLE_OFFSET
:
2851 Offset
= (ALint
)Source
->Offset
;
2855 Offset
= (ALint
)(Source
->Offset
* Buffer
->Frequency
);
2858 Source
->Offset
= -1.0;
2866 * Destroys all sources in the source map.
2868 ALvoid
ReleaseALSources(ALCcontext
*Context
)
2872 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
2874 ALsource
*temp
= Context
->SourceMap
.array
[pos
].value
;
2875 Context
->SourceMap
.array
[pos
].value
= NULL
;
2877 while(temp
->queue
!= NULL
)
2879 ALbufferlistitem
*BufferList
= temp
->queue
;
2880 temp
->queue
= BufferList
->next
;
2882 if(BufferList
->buffer
!= NULL
)
2883 DecrementRef(&BufferList
->buffer
->ref
);
2887 for(j
= 0;j
< MAX_SENDS
;++j
)
2889 if(temp
->Send
[j
].Slot
)
2890 DecrementRef(&temp
->Send
[j
].Slot
->ref
);
2891 temp
->Send
[j
].Slot
= NULL
;
2894 FreeThunkEntry(temp
->id
);
2895 memset(temp
, 0, sizeof(*temp
));