| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708 |
- /**
- * OpenAL cross platform audio library
- * Copyright (C) 1999-2007 by authors.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- * Or go to http://www.gnu.org/copyleft/lgpl.html
- */
- #include "config.h"
- #include <stdlib.h>
- #include <math.h>
- #include <float.h>
- #include "AL/al.h"
- #include "AL/alc.h"
- #include "alMain.h"
- #include "alError.h"
- #include "alSource.h"
- #include "alBuffer.h"
- #include "alThunk.h"
- #include "alAuxEffectSlot.h"
- enum Resampler DefaultResampler = LinearResampler;
- const ALsizei ResamplerPadding[ResamplerMax] = {
- 0, /* Point */
- 1, /* Linear */
- 2, /* Cubic */
- };
- const ALsizei ResamplerPrePadding[ResamplerMax] = {
- 0, /* Point */
- 0, /* Linear */
- 1, /* Cubic */
- };
- extern inline struct ALsource *LookupSource(ALCcontext *context, ALuint id);
- extern inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id);
- static ALvoid InitSourceParams(ALsource *Source);
- static ALint64 GetSourceOffset(const ALsource *Source);
- static ALdouble GetSourceSecOffset(const ALsource *Source);
- static ALvoid GetSourceOffsets(const ALsource *Source, ALenum name, ALdouble *offsets, ALdouble updateLen);
- static ALint GetSampleOffset(ALsource *Source);
- typedef enum SrcFloatProp {
- sfPitch = AL_PITCH,
- sfGain = AL_GAIN,
- sfMinGain = AL_MIN_GAIN,
- sfMaxGain = AL_MAX_GAIN,
- sfMaxDistance = AL_MAX_DISTANCE,
- sfRolloffFactor = AL_ROLLOFF_FACTOR,
- sfDopplerFactor = AL_DOPPLER_FACTOR,
- sfConeOuterGain = AL_CONE_OUTER_GAIN,
- sfSecOffset = AL_SEC_OFFSET,
- sfSampleOffset = AL_SAMPLE_OFFSET,
- sfByteOffset = AL_BYTE_OFFSET,
- sfConeInnerAngle = AL_CONE_INNER_ANGLE,
- sfConeOuterAngle = AL_CONE_OUTER_ANGLE,
- sfRefDistance = AL_REFERENCE_DISTANCE,
- sfPosition = AL_POSITION,
- sfVelocity = AL_VELOCITY,
- sfDirection = AL_DIRECTION,
- sfSourceRelative = AL_SOURCE_RELATIVE,
- sfLooping = AL_LOOPING,
- sfBuffer = AL_BUFFER,
- sfSourceState = AL_SOURCE_STATE,
- sfBuffersQueued = AL_BUFFERS_QUEUED,
- sfBuffersProcessed = AL_BUFFERS_PROCESSED,
- sfSourceType = AL_SOURCE_TYPE,
- /* ALC_EXT_EFX */
- sfConeOuterGainHF = AL_CONE_OUTER_GAINHF,
- sfAirAbsorptionFactor = AL_AIR_ABSORPTION_FACTOR,
- sfRoomRolloffFactor = AL_ROOM_ROLLOFF_FACTOR,
- sfDirectFilterGainHFAuto = AL_DIRECT_FILTER_GAINHF_AUTO,
- sfAuxSendFilterGainAuto = AL_AUXILIARY_SEND_FILTER_GAIN_AUTO,
- sfAuxSendFilterGainHFAuto = AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO,
- /* AL_SOFT_direct_channels */
- sfDirectChannelsSOFT = AL_DIRECT_CHANNELS_SOFT,
- /* AL_EXT_source_distance_model */
- sfDistanceModel = AL_DISTANCE_MODEL,
- /* AL_SOFT_buffer_sub_data / AL_SOFT_buffer_samples */
- sfSampleRWOffsetsSOFT = AL_SAMPLE_RW_OFFSETS_SOFT,
- sfByteRWOffsetsSOFT = AL_BYTE_RW_OFFSETS_SOFT,
- /* AL_SOFT_source_latency */
- sfSecOffsetLatencySOFT = AL_SEC_OFFSET_LATENCY_SOFT,
- } SrcFloatProp;
- typedef enum SrcIntProp {
- siMaxDistance = AL_MAX_DISTANCE,
- siRolloffFactor = AL_ROLLOFF_FACTOR,
- siRefDistance = AL_REFERENCE_DISTANCE,
- siSourceRelative = AL_SOURCE_RELATIVE,
- siConeInnerAngle = AL_CONE_INNER_ANGLE,
- siConeOuterAngle = AL_CONE_OUTER_ANGLE,
- siLooping = AL_LOOPING,
- siBuffer = AL_BUFFER,
- siSourceState = AL_SOURCE_STATE,
- siBuffersQueued = AL_BUFFERS_QUEUED,
- siBuffersProcessed = AL_BUFFERS_PROCESSED,
- siSourceType = AL_SOURCE_TYPE,
- siSecOffset = AL_SEC_OFFSET,
- siSampleOffset = AL_SAMPLE_OFFSET,
- siByteOffset = AL_BYTE_OFFSET,
- siDopplerFactor = AL_DOPPLER_FACTOR,
- siPosition = AL_POSITION,
- siVelocity = AL_VELOCITY,
- siDirection = AL_DIRECTION,
- /* ALC_EXT_EFX */
- siDirectFilterGainHFAuto = AL_DIRECT_FILTER_GAINHF_AUTO,
- siAuxSendFilterGainAutio = AL_AUXILIARY_SEND_FILTER_GAIN_AUTO,
- siAuxSendFilterGainHFAuto = AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO,
- siDirectFilter = AL_DIRECT_FILTER,
- siAuxSendFilter = AL_AUXILIARY_SEND_FILTER,
- /* AL_SOFT_direct_channels */
- siDirectChannelsSOFT = AL_DIRECT_CHANNELS_SOFT,
- /* AL_EXT_source_distance_model */
- siDistanceModel = AL_DISTANCE_MODEL,
- /* AL_SOFT_buffer_sub_data / AL_SOFT_buffer_samples */
- siSampleRWOffsetsSOFT = AL_SAMPLE_RW_OFFSETS_SOFT,
- siByteRWOffsetsSOFT = AL_BYTE_RW_OFFSETS_SOFT,
- /* AL_SOFT_source_latency */
- siSampleOffsetLatencySOFT = AL_SAMPLE_OFFSET_LATENCY_SOFT,
- } SrcIntProp;
- static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SrcFloatProp prop, const ALfloat *values);
- static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SrcIntProp prop, const ALint *values);
- static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SrcIntProp prop, const ALint64SOFT *values);
- static ALboolean GetSourcedv(const ALsource *Source, ALCcontext *Context, SrcFloatProp prop, ALdouble *values);
- static ALboolean GetSourceiv(const ALsource *Source, ALCcontext *Context, SrcIntProp prop, ALint *values);
- static ALboolean GetSourcei64v(const ALsource *Source, ALCcontext *Context, SrcIntProp prop, ALint64 *values);
- static ALint FloatValsByProp(ALenum prop)
- {
- if(prop != (ALenum)((SrcFloatProp)prop))
- return 0;
- switch((SrcFloatProp)prop)
- {
- case sfPitch:
- case sfGain:
- case sfMinGain:
- case sfMaxGain:
- case sfMaxDistance:
- case sfRolloffFactor:
- case sfDopplerFactor:
- case sfConeOuterGain:
- case sfSecOffset:
- case sfSampleOffset:
- case sfByteOffset:
- case sfConeInnerAngle:
- case sfConeOuterAngle:
- case sfRefDistance:
- case sfConeOuterGainHF:
- case sfAirAbsorptionFactor:
- case sfRoomRolloffFactor:
- case sfDirectFilterGainHFAuto:
- case sfAuxSendFilterGainAuto:
- case sfAuxSendFilterGainHFAuto:
- case sfDirectChannelsSOFT:
- case sfDistanceModel:
- case sfSourceRelative:
- case sfLooping:
- case sfBuffer:
- case sfSourceState:
- case sfBuffersQueued:
- case sfBuffersProcessed:
- case sfSourceType:
- return 1;
- case sfSampleRWOffsetsSOFT:
- case sfByteRWOffsetsSOFT:
- return 2;
- case sfPosition:
- case sfVelocity:
- case sfDirection:
- return 3;
- case sfSecOffsetLatencySOFT:
- break; /* Double only */
- }
- return 0;
- }
- static ALint DoubleValsByProp(ALenum prop)
- {
- if(prop != (ALenum)((SrcFloatProp)prop))
- return 0;
- switch((SrcFloatProp)prop)
- {
- case sfPitch:
- case sfGain:
- case sfMinGain:
- case sfMaxGain:
- case sfMaxDistance:
- case sfRolloffFactor:
- case sfDopplerFactor:
- case sfConeOuterGain:
- case sfSecOffset:
- case sfSampleOffset:
- case sfByteOffset:
- case sfConeInnerAngle:
- case sfConeOuterAngle:
- case sfRefDistance:
- case sfConeOuterGainHF:
- case sfAirAbsorptionFactor:
- case sfRoomRolloffFactor:
- case sfDirectFilterGainHFAuto:
- case sfAuxSendFilterGainAuto:
- case sfAuxSendFilterGainHFAuto:
- case sfDirectChannelsSOFT:
- case sfDistanceModel:
- case sfSourceRelative:
- case sfLooping:
- case sfBuffer:
- case sfSourceState:
- case sfBuffersQueued:
- case sfBuffersProcessed:
- case sfSourceType:
- return 1;
- case sfSampleRWOffsetsSOFT:
- case sfByteRWOffsetsSOFT:
- case sfSecOffsetLatencySOFT:
- return 2;
- case sfPosition:
- case sfVelocity:
- case sfDirection:
- return 3;
- }
- return 0;
- }
- static ALint IntValsByProp(ALenum prop)
- {
- if(prop != (ALenum)((SrcIntProp)prop))
- return 0;
- switch((SrcIntProp)prop)
- {
- case siMaxDistance:
- case siRolloffFactor:
- case siRefDistance:
- case siSourceRelative:
- case siConeInnerAngle:
- case siConeOuterAngle:
- case siLooping:
- case siBuffer:
- case siSourceState:
- case siBuffersQueued:
- case siBuffersProcessed:
- case siSourceType:
- case siSecOffset:
- case siSampleOffset:
- case siByteOffset:
- case siDopplerFactor:
- case siDirectFilterGainHFAuto:
- case siAuxSendFilterGainAutio:
- case siAuxSendFilterGainHFAuto:
- case siDirectFilter:
- case siDirectChannelsSOFT:
- case siDistanceModel:
- return 1;
- case siSampleRWOffsetsSOFT:
- case siByteRWOffsetsSOFT:
- return 2;
- case siPosition:
- case siVelocity:
- case siDirection:
- case siAuxSendFilter:
- return 3;
- case siSampleOffsetLatencySOFT:
- break; /* i64 only */
- }
- return 0;
- }
- static ALint Int64ValsByProp(ALenum prop)
- {
- if(prop != (ALenum)((SrcIntProp)prop))
- return 0;
- switch((SrcIntProp)prop)
- {
- case siMaxDistance:
- case siRolloffFactor:
- case siRefDistance:
- case siSourceRelative:
- case siConeInnerAngle:
- case siConeOuterAngle:
- case siLooping:
- case siBuffer:
- case siSourceState:
- case siBuffersQueued:
- case siBuffersProcessed:
- case siSourceType:
- case siSecOffset:
- case siSampleOffset:
- case siByteOffset:
- case siDopplerFactor:
- case siDirectFilterGainHFAuto:
- case siAuxSendFilterGainAutio:
- case siAuxSendFilterGainHFAuto:
- case siDirectFilter:
- case siDirectChannelsSOFT:
- case siDistanceModel:
- return 1;
- case siSampleRWOffsetsSOFT:
- case siByteRWOffsetsSOFT:
- case siSampleOffsetLatencySOFT:
- return 2;
- case siPosition:
- case siVelocity:
- case siDirection:
- case siAuxSendFilter:
- return 3;
- }
- return 0;
- }
- #define CHECKVAL(x) do { \
- if(!(x)) \
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE); \
- } while(0)
- static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SrcFloatProp prop, const ALfloat *values)
- {
- ALint ival;
- switch(prop)
- {
- case AL_PITCH:
- CHECKVAL(*values >= 0.0f);
- Source->Pitch = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_CONE_INNER_ANGLE:
- CHECKVAL(*values >= 0.0f && *values <= 360.0f);
- Source->InnerAngle = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_CONE_OUTER_ANGLE:
- CHECKVAL(*values >= 0.0f && *values <= 360.0f);
- Source->OuterAngle = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_GAIN:
- CHECKVAL(*values >= 0.0f);
- Source->Gain = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_MAX_DISTANCE:
- CHECKVAL(*values >= 0.0f);
- Source->MaxDistance = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_ROLLOFF_FACTOR:
- CHECKVAL(*values >= 0.0f);
- Source->RollOffFactor = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_REFERENCE_DISTANCE:
- CHECKVAL(*values >= 0.0f);
- Source->RefDistance = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_MIN_GAIN:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
- Source->MinGain = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_MAX_GAIN:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
- Source->MaxGain = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_CONE_OUTER_GAIN:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
- Source->OuterGain = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_CONE_OUTER_GAINHF:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
- Source->OuterGainHF = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_AIR_ABSORPTION_FACTOR:
- CHECKVAL(*values >= 0.0f && *values <= 10.0f);
- Source->AirAbsorptionFactor = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_ROOM_ROLLOFF_FACTOR:
- CHECKVAL(*values >= 0.0f && *values <= 10.0f);
- Source->RoomRolloffFactor = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_DOPPLER_FACTOR:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
- Source->DopplerFactor = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_SEC_OFFSET:
- case AL_SAMPLE_OFFSET:
- case AL_BYTE_OFFSET:
- CHECKVAL(*values >= 0.0f);
- LockContext(Context);
- Source->OffsetType = prop;
- Source->Offset = *values;
- if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
- !Context->DeferUpdates)
- {
- if(ApplyOffset(Source) == AL_FALSE)
- {
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE);
- }
- }
- UnlockContext(Context);
- return AL_TRUE;
- case AL_SEC_OFFSET_LATENCY_SOFT:
- /* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
- case AL_POSITION:
- CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]));
- LockContext(Context);
- Source->Position[0] = values[0];
- Source->Position[1] = values[1];
- Source->Position[2] = values[2];
- UnlockContext(Context);
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_VELOCITY:
- CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]));
- LockContext(Context);
- Source->Velocity[0] = values[0];
- Source->Velocity[1] = values[1];
- Source->Velocity[2] = values[2];
- UnlockContext(Context);
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_DIRECTION:
- CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]));
- LockContext(Context);
- Source->Orientation[0] = values[0];
- Source->Orientation[1] = values[1];
- Source->Orientation[2] = values[2];
- UnlockContext(Context);
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case sfSampleRWOffsetsSOFT:
- case sfByteRWOffsetsSOFT:
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
- case sfSourceRelative:
- case sfLooping:
- case sfSourceState:
- case sfSourceType:
- case sfDistanceModel:
- case sfDirectFilterGainHFAuto:
- case sfAuxSendFilterGainAuto:
- case sfAuxSendFilterGainHFAuto:
- case sfDirectChannelsSOFT:
- ival = (ALint)values[0];
- return SetSourceiv(Source, Context, (SrcIntProp)prop, &ival);
- case sfBuffer:
- case sfBuffersQueued:
- case sfBuffersProcessed:
- ival = (ALint)((ALuint)values[0]);
- return SetSourceiv(Source, Context, (SrcIntProp)prop, &ival);
- }
- ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
- }
- static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SrcIntProp prop, const ALint *values)
- {
- ALCdevice *device = Context->Device;
- ALbuffer *buffer = NULL;
- ALfilter *filter = NULL;
- ALeffectslot *slot = NULL;
- ALbufferlistitem *oldlist;
- ALfloat fvals[3];
- switch(prop)
- {
- case AL_SOURCE_RELATIVE:
- CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
- Source->HeadRelative = (ALboolean)*values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_LOOPING:
- CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
- Source->Looping = (ALboolean)*values;
- return AL_TRUE;
- case AL_BUFFER:
- CHECKVAL(*values == 0 || (buffer=LookupBuffer(device, *values)) != NULL);
- LockContext(Context);
- if(!(Source->state == AL_STOPPED || Source->state == AL_INITIAL))
- {
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
- }
- Source->BuffersInQueue = 0;
- Source->BuffersPlayed = 0;
- if(buffer != NULL)
- {
- ALbufferlistitem *BufferListItem;
- /* Source is now Static */
- Source->SourceType = AL_STATIC;
- /* Add the selected buffer to a one-item queue */
- BufferListItem = malloc(sizeof(ALbufferlistitem));
- BufferListItem->buffer = buffer;
- BufferListItem->next = NULL;
- BufferListItem->prev = NULL;
- IncrementRef(&buffer->ref);
- oldlist = ExchangePtr((XchgPtr*)&Source->queue, BufferListItem);
- Source->BuffersInQueue = 1;
- ReadLock(&buffer->lock);
- Source->NumChannels = ChannelsFromFmt(buffer->FmtChannels);
- Source->SampleSize = BytesFromFmt(buffer->FmtType);
- ReadUnlock(&buffer->lock);
- if(buffer->FmtChannels == FmtMono)
- Source->Update = CalcSourceParams;
- else
- Source->Update = CalcNonAttnSourceParams;
- Source->NeedsUpdate = AL_TRUE;
- }
- else
- {
- /* Source is now Undetermined */
- Source->SourceType = AL_UNDETERMINED;
- oldlist = ExchangePtr((XchgPtr*)&Source->queue, NULL);
- }
- /* Delete all elements in the previous queue */
- while(oldlist != NULL)
- {
- ALbufferlistitem *temp = oldlist;
- oldlist = temp->next;
- if(temp->buffer)
- DecrementRef(&temp->buffer->ref);
- free(temp);
- }
- UnlockContext(Context);
- return AL_TRUE;
- case siSourceState:
- case siSourceType:
- case siBuffersQueued:
- case siBuffersProcessed:
- /* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
- case AL_SEC_OFFSET:
- case AL_SAMPLE_OFFSET:
- case AL_BYTE_OFFSET:
- CHECKVAL(*values >= 0);
- LockContext(Context);
- Source->OffsetType = prop;
- Source->Offset = *values;
- if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
- !Context->DeferUpdates)
- {
- if(ApplyOffset(Source) == AL_FALSE)
- {
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE);
- }
- }
- UnlockContext(Context);
- return AL_TRUE;
- case siSampleRWOffsetsSOFT:
- case siByteRWOffsetsSOFT:
- /* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
- case AL_DIRECT_FILTER:
- CHECKVAL(*values == 0 || (filter=LookupFilter(device, *values)) != NULL);
- LockContext(Context);
- if(!filter)
- {
- Source->DirectGain = 1.0f;
- Source->DirectGainHF = 1.0f;
- }
- else
- {
- Source->DirectGain = filter->Gain;
- Source->DirectGainHF = filter->GainHF;
- }
- UnlockContext(Context);
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_DIRECT_FILTER_GAINHF_AUTO:
- CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
- Source->DryGainHFAuto = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
- CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
- Source->WetGainAuto = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
- CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
- Source->WetGainHFAuto = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_DIRECT_CHANNELS_SOFT:
- CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
- Source->DirectChannels = *values;
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_DISTANCE_MODEL:
- CHECKVAL(*values == AL_NONE ||
- *values == AL_INVERSE_DISTANCE ||
- *values == AL_INVERSE_DISTANCE_CLAMPED ||
- *values == AL_LINEAR_DISTANCE ||
- *values == AL_LINEAR_DISTANCE_CLAMPED ||
- *values == AL_EXPONENT_DISTANCE ||
- *values == AL_EXPONENT_DISTANCE_CLAMPED);
- Source->DistanceModel = *values;
- if(Context->SourceDistanceModel)
- Source->NeedsUpdate = AL_TRUE;
- return AL_TRUE;
- case AL_AUXILIARY_SEND_FILTER:
- LockContext(Context);
- if(!((ALuint)values[1] < device->NumAuxSends &&
- (values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != NULL) &&
- (values[2] == 0 || (filter=LookupFilter(device, values[2])) != NULL)))
- {
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE);
- }
- /* Add refcount on the new slot, and release the previous slot */
- if(slot) IncrementRef(&slot->ref);
- slot = ExchangePtr((XchgPtr*)&Source->Send[values[1]].Slot, slot);
- if(slot) DecrementRef(&slot->ref);
- if(!filter)
- {
- /* Disable filter */
- Source->Send[values[1]].Gain = 1.0f;
- Source->Send[values[1]].GainHF = 1.0f;
- }
- else
- {
- Source->Send[values[1]].Gain = filter->Gain;
- Source->Send[values[1]].GainHF = filter->GainHF;
- }
- Source->NeedsUpdate = AL_TRUE;
- UnlockContext(Context);
- return AL_TRUE;
- case AL_MAX_DISTANCE:
- case AL_ROLLOFF_FACTOR:
- case AL_CONE_INNER_ANGLE:
- case AL_CONE_OUTER_ANGLE:
- case AL_REFERENCE_DISTANCE:
- case siDopplerFactor:
- fvals[0] = (ALfloat)*values;
- return SetSourcefv(Source, Context, (int)prop, fvals);
- case AL_POSITION:
- case AL_VELOCITY:
- case AL_DIRECTION:
- fvals[0] = (ALfloat)values[0];
- fvals[1] = (ALfloat)values[1];
- fvals[2] = (ALfloat)values[2];
- return SetSourcefv(Source, Context, (int)prop, fvals);
- case siSampleOffsetLatencySOFT:
- /* i64 only */
- break;
- }
- ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
- }
- static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SrcIntProp prop, const ALint64SOFT *values)
- {
- ALfloat fvals[3];
- ALint ivals[3];
- switch(prop)
- {
- case siSampleRWOffsetsSOFT:
- case siByteRWOffsetsSOFT:
- case siSampleOffsetLatencySOFT:
- /* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
- /* 1x int */
- case AL_SOURCE_RELATIVE:
- case AL_LOOPING:
- case AL_SOURCE_STATE:
- case AL_BYTE_OFFSET:
- case AL_SAMPLE_OFFSET:
- case siSourceType:
- case siBuffersQueued:
- case siBuffersProcessed:
- case AL_DIRECT_FILTER_GAINHF_AUTO:
- case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
- case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
- case AL_DIRECT_CHANNELS_SOFT:
- case AL_DISTANCE_MODEL:
- CHECKVAL(*values <= INT_MAX && *values >= INT_MIN);
- ivals[0] = (ALint)*values;
- return SetSourceiv(Source, Context, (int)prop, ivals);
- /* 1x uint */
- case AL_BUFFER:
- case AL_DIRECT_FILTER:
- CHECKVAL(*values <= UINT_MAX && *values >= 0);
- ivals[0] = (ALuint)*values;
- return SetSourceiv(Source, Context, (int)prop, ivals);
- /* 3x uint */
- case AL_AUXILIARY_SEND_FILTER:
- CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0 &&
- values[1] <= UINT_MAX && values[1] >= 0 &&
- values[2] <= UINT_MAX && values[2] >= 0);
- ivals[0] = (ALuint)values[0];
- ivals[1] = (ALuint)values[1];
- ivals[2] = (ALuint)values[2];
- return SetSourceiv(Source, Context, (int)prop, ivals);
- /* 1x float */
- case AL_MAX_DISTANCE:
- case AL_ROLLOFF_FACTOR:
- case AL_CONE_INNER_ANGLE:
- case AL_CONE_OUTER_ANGLE:
- case AL_REFERENCE_DISTANCE:
- case AL_SEC_OFFSET:
- case siDopplerFactor:
- fvals[0] = (ALfloat)*values;
- return SetSourcefv(Source, Context, (int)prop, fvals);
- /* 3x float */
- case AL_POSITION:
- case AL_VELOCITY:
- case AL_DIRECTION:
- fvals[0] = (ALfloat)values[0];
- fvals[1] = (ALfloat)values[1];
- fvals[2] = (ALfloat)values[2];
- return SetSourcefv(Source, Context, (int)prop, fvals);
- }
- ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
- }
- #undef CHECKVAL
- static ALboolean GetSourcedv(const ALsource *Source, ALCcontext *Context, SrcFloatProp prop, ALdouble *values)
- {
- ALdouble offsets[2];
- ALdouble updateLen;
- ALint ivals[3];
- ALboolean err;
- switch(prop)
- {
- case AL_GAIN:
- *values = Source->Gain;
- return AL_TRUE;
- case AL_PITCH:
- *values = Source->Pitch;
- return AL_TRUE;
- case AL_MAX_DISTANCE:
- *values = Source->MaxDistance;
- return AL_TRUE;
- case AL_ROLLOFF_FACTOR:
- *values = Source->RollOffFactor;
- return AL_TRUE;
- case AL_REFERENCE_DISTANCE:
- *values = Source->RefDistance;
- return AL_TRUE;
- case AL_CONE_INNER_ANGLE:
- *values = Source->InnerAngle;
- return AL_TRUE;
- case AL_CONE_OUTER_ANGLE:
- *values = Source->OuterAngle;
- return AL_TRUE;
- case AL_MIN_GAIN:
- *values = Source->MinGain;
- return AL_TRUE;
- case AL_MAX_GAIN:
- *values = Source->MaxGain;
- return AL_TRUE;
- case AL_CONE_OUTER_GAIN:
- *values = Source->OuterGain;
- return AL_TRUE;
- case AL_SEC_OFFSET:
- case AL_SAMPLE_OFFSET:
- case AL_BYTE_OFFSET:
- LockContext(Context);
- updateLen = (ALdouble)Context->Device->UpdateSize /
- Context->Device->Frequency;
- GetSourceOffsets(Source, prop, offsets, updateLen);
- UnlockContext(Context);
- *values = offsets[0];
- return AL_TRUE;
- case AL_CONE_OUTER_GAINHF:
- *values = Source->OuterGainHF;
- return AL_TRUE;
- case AL_AIR_ABSORPTION_FACTOR:
- *values = Source->AirAbsorptionFactor;
- return AL_TRUE;
- case AL_ROOM_ROLLOFF_FACTOR:
- *values = Source->RoomRolloffFactor;
- return AL_TRUE;
- case AL_DOPPLER_FACTOR:
- *values = Source->DopplerFactor;
- return AL_TRUE;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- LockContext(Context);
- updateLen = (ALdouble)Context->Device->UpdateSize /
- Context->Device->Frequency;
- GetSourceOffsets(Source, prop, values, updateLen);
- UnlockContext(Context);
- return AL_TRUE;
- case AL_SEC_OFFSET_LATENCY_SOFT:
- LockContext(Context);
- values[0] = GetSourceSecOffset(Source);
- values[1] = (ALdouble)ALCdevice_GetLatency(Context->Device) /
- 1000000000.0;
- UnlockContext(Context);
- return AL_TRUE;
- case AL_POSITION:
- LockContext(Context);
- values[0] = Source->Position[0];
- values[1] = Source->Position[1];
- values[2] = Source->Position[2];
- UnlockContext(Context);
- return AL_TRUE;
- case AL_VELOCITY:
- LockContext(Context);
- values[0] = Source->Velocity[0];
- values[1] = Source->Velocity[1];
- values[2] = Source->Velocity[2];
- UnlockContext(Context);
- return AL_TRUE;
- case AL_DIRECTION:
- LockContext(Context);
- values[0] = Source->Orientation[0];
- values[1] = Source->Orientation[1];
- values[2] = Source->Orientation[2];
- UnlockContext(Context);
- return AL_TRUE;
- case AL_SOURCE_RELATIVE:
- case AL_LOOPING:
- case AL_BUFFER:
- case AL_SOURCE_STATE:
- case AL_BUFFERS_QUEUED:
- case AL_BUFFERS_PROCESSED:
- case AL_SOURCE_TYPE:
- case AL_DIRECT_FILTER_GAINHF_AUTO:
- case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
- case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
- case AL_DIRECT_CHANNELS_SOFT:
- case AL_DISTANCE_MODEL:
- if((err=GetSourceiv(Source, Context, (int)prop, ivals)) != AL_FALSE)
- *values = (ALdouble)ivals[0];
- return err;
- }
- ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
- }
- static ALboolean GetSourceiv(const ALsource *Source, ALCcontext *Context, SrcIntProp prop, ALint *values)
- {
- ALbufferlistitem *BufferList;
- ALdouble dvals[3];
- ALboolean err;
- switch(prop)
- {
- case AL_SOURCE_RELATIVE:
- *values = Source->HeadRelative;
- return AL_TRUE;
- case AL_LOOPING:
- *values = Source->Looping;
- return AL_TRUE;
- case AL_BUFFER:
- LockContext(Context);
- BufferList = Source->queue;
- if(Source->SourceType != AL_STATIC)
- {
- ALuint i = Source->BuffersPlayed;
- while(i > 0)
- {
- BufferList = BufferList->next;
- i--;
- }
- }
- *values = ((BufferList && BufferList->buffer) ?
- BufferList->buffer->id : 0);
- UnlockContext(Context);
- return AL_TRUE;
- case AL_SOURCE_STATE:
- *values = Source->state;
- return AL_TRUE;
- case AL_BUFFERS_QUEUED:
- *values = Source->BuffersInQueue;
- return AL_TRUE;
- case AL_BUFFERS_PROCESSED:
- LockContext(Context);
- if(Source->Looping || Source->SourceType != AL_STREAMING)
- {
- /* Buffers on a looping source are in a perpetual state of
- * PENDING, so don't report any as PROCESSED */
- *values = 0;
- }
- else
- *values = Source->BuffersPlayed;
- UnlockContext(Context);
- return AL_TRUE;
- case AL_SOURCE_TYPE:
- *values = Source->SourceType;
- return AL_TRUE;
- case AL_DIRECT_FILTER_GAINHF_AUTO:
- *values = Source->DryGainHFAuto;
- return AL_TRUE;
- case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
- *values = Source->WetGainAuto;
- return AL_TRUE;
- case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
- *values = Source->WetGainHFAuto;
- return AL_TRUE;
- case AL_DIRECT_CHANNELS_SOFT:
- *values = Source->DirectChannels;
- return AL_TRUE;
- case AL_DISTANCE_MODEL:
- *values = Source->DistanceModel;
- return AL_TRUE;
- case AL_MAX_DISTANCE:
- case AL_ROLLOFF_FACTOR:
- case AL_REFERENCE_DISTANCE:
- case AL_CONE_INNER_ANGLE:
- case AL_CONE_OUTER_ANGLE:
- case AL_SEC_OFFSET:
- case AL_SAMPLE_OFFSET:
- case AL_BYTE_OFFSET:
- case AL_DOPPLER_FACTOR:
- if((err=GetSourcedv(Source, Context, (int)prop, dvals)) != AL_FALSE)
- *values = (ALint)dvals[0];
- return err;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- if((err=GetSourcedv(Source, Context, (int)prop, dvals)) != AL_FALSE)
- {
- values[0] = (ALint)dvals[0];
- values[1] = (ALint)dvals[1];
- }
- return err;
- case AL_POSITION:
- case AL_VELOCITY:
- case AL_DIRECTION:
- if((err=GetSourcedv(Source, Context, (int)prop, dvals)) != AL_FALSE)
- {
- values[0] = (ALint)dvals[0];
- values[1] = (ALint)dvals[1];
- values[2] = (ALint)dvals[2];
- }
- return err;
- case siSampleOffsetLatencySOFT:
- /* i64 only */
- break;
- case siDirectFilter:
- case siAuxSendFilter:
- /* ??? */
- break;
- }
- ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
- }
- static ALboolean GetSourcei64v(const ALsource *Source, ALCcontext *Context, SrcIntProp prop, ALint64 *values)
- {
- ALdouble dvals[3];
- ALint ivals[3];
- ALboolean err;
- switch(prop)
- {
- case AL_SAMPLE_OFFSET_LATENCY_SOFT:
- LockContext(Context);
- values[0] = GetSourceOffset(Source);
- values[1] = ALCdevice_GetLatency(Context->Device);
- UnlockContext(Context);
- return AL_TRUE;
- case AL_MAX_DISTANCE:
- case AL_ROLLOFF_FACTOR:
- case AL_REFERENCE_DISTANCE:
- case AL_CONE_INNER_ANGLE:
- case AL_CONE_OUTER_ANGLE:
- case AL_SEC_OFFSET:
- case AL_SAMPLE_OFFSET:
- case AL_BYTE_OFFSET:
- case AL_DOPPLER_FACTOR:
- if((err=GetSourcedv(Source, Context, (int)prop, dvals)) != AL_FALSE)
- *values = (ALint64)dvals[0];
- return err;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- if((err=GetSourcedv(Source, Context, (int)prop, dvals)) != AL_FALSE)
- {
- values[0] = (ALint64)dvals[0];
- values[1] = (ALint64)dvals[1];
- }
- return err;
- case AL_POSITION:
- case AL_VELOCITY:
- case AL_DIRECTION:
- if((err=GetSourcedv(Source, Context, (int)prop, dvals)) != AL_FALSE)
- {
- values[0] = (ALint64)dvals[0];
- values[1] = (ALint64)dvals[1];
- values[2] = (ALint64)dvals[2];
- }
- return err;
- case AL_SOURCE_RELATIVE:
- case AL_LOOPING:
- case AL_SOURCE_STATE:
- case AL_BUFFERS_QUEUED:
- case AL_BUFFERS_PROCESSED:
- case AL_SOURCE_TYPE:
- case AL_DIRECT_FILTER_GAINHF_AUTO:
- case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
- case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
- case AL_DIRECT_CHANNELS_SOFT:
- case AL_DISTANCE_MODEL:
- if((err=GetSourceiv(Source, Context, (int)prop, ivals)) != AL_FALSE)
- *values = ivals[0];
- return err;
- case siBuffer:
- case siDirectFilter:
- if((err=GetSourceiv(Source, Context, (int)prop, ivals)) != AL_FALSE)
- *values = ((ALuint*)ivals)[0];
- return err;
- case siAuxSendFilter:
- if((err=GetSourceiv(Source, Context, (int)prop, ivals)) != AL_FALSE)
- {
- values[0] = ((ALuint*)ivals)[0];
- values[1] = ((ALuint*)ivals)[1];
- values[2] = ((ALuint*)ivals)[2];
- }
- return err;
- }
- ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
- }
- AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
- {
- ALCcontext *context;
- ALsizei cur = 0;
- ALenum err;
- context = GetContextRef();
- if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- for(cur = 0;cur < n;cur++)
- {
- ALsource *source = al_calloc(16, sizeof(ALsource));
- if(!source)
- {
- alDeleteSources(cur, sources);
- SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
- }
- InitSourceParams(source);
- err = NewThunkEntry(&source->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&context->SourceMap, source->id, source);
- if(err != AL_NO_ERROR)
- {
- FreeThunkEntry(source->id);
- memset(source, 0, sizeof(ALsource));
- al_free(source);
- alDeleteSources(cur, sources);
- SET_ERROR_AND_GOTO(context, err, done);
- }
- sources[cur] = source->id;
- }
- done:
- ALCcontext_DecRef(context);
- }
- AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
- {
- ALCcontext *context;
- ALbufferlistitem *BufferList;
- ALsource *Source;
- ALsizei i, j;
- context = GetContextRef();
- if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- /* Check that all Sources are valid */
- for(i = 0;i < n;i++)
- {
- if(LookupSource(context, sources[i]) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- }
- for(i = 0;i < n;i++)
- {
- ALsource **srclist, **srclistend;
- if((Source=RemoveSource(context, sources[i])) == NULL)
- continue;
- FreeThunkEntry(Source->id);
- LockContext(context);
- srclist = context->ActiveSources;
- srclistend = srclist + context->ActiveSourceCount;
- while(srclist != srclistend)
- {
- if(*srclist == Source)
- {
- context->ActiveSourceCount--;
- *srclist = *(--srclistend);
- break;
- }
- srclist++;
- }
- UnlockContext(context);
- while(Source->queue != NULL)
- {
- BufferList = Source->queue;
- Source->queue = BufferList->next;
- if(BufferList->buffer != NULL)
- DecrementRef(&BufferList->buffer->ref);
- free(BufferList);
- }
- for(j = 0;j < MAX_SENDS;++j)
- {
- if(Source->Send[j].Slot)
- DecrementRef(&Source->Send[j].Slot->ref);
- Source->Send[j].Slot = NULL;
- }
- memset(Source, 0, sizeof(*Source));
- al_free(Source);
- }
- done:
- ALCcontext_DecRef(context);
- }
- AL_API ALboolean AL_APIENTRY alIsSource(ALuint source)
- {
- ALCcontext *context;
- ALboolean ret;
- context = GetContextRef();
- if(!context) return AL_FALSE;
- ret = (LookupSource(context, source) ? AL_TRUE : AL_FALSE);
- ALCcontext_DecRef(context);
- return ret;
- }
- AL_API ALvoid AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(FloatValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- SetSourcefv(Source, Context, param, &value);
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(FloatValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALfloat fvals[3] = { value1, value2, value3 };
- SetSourcefv(Source, Context, param, fvals);
- }
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(FloatValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
- else
- SetSourcefv(Source, Context, param, values);
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSourcedSOFT(ALuint source, ALenum param, ALdouble value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(DoubleValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALfloat fval = (ALfloat)value;
- SetSourcefv(Source, Context, param, &fval);
- }
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSource3dSOFT(ALuint source, ALenum param, ALdouble value1, ALdouble value2, ALdouble value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(DoubleValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALfloat fvals[3] = { (ALfloat)value1, (ALfloat)value2, (ALfloat)value3 };
- SetSourcefv(Source, Context, param, fvals);
- }
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdouble *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- ALint count;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!((count=DoubleValsByProp(param)) > 0 && count <= 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALfloat fvals[3];
- ALint i;
- for(i = 0;i < count;i++)
- fvals[i] = (ALfloat)values[i];
- SetSourcefv(Source, Context, param, fvals);
- }
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(IntValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- SetSourceiv(Source, Context, param, &value);
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, ALint value2, ALint value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(IntValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALint ivals[3] = { value1, value2, value3 };
- SetSourceiv(Source, Context, param, ivals);
- }
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alSourceiv(ALuint source, ALenum param, const ALint *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(IntValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
- else
- SetSourceiv(Source, Context, param, values);
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(Int64ValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- SetSourcei64v(Source, Context, param, &value);
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT value1, ALint64SOFT value2, ALint64SOFT value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(Int64ValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALint64SOFT i64vals[3] = { value1, value2, value3 };
- SetSourcei64v(Source, Context, param, i64vals);
- }
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alSourcei64vSOFT(ALuint source, ALenum param, const ALint64SOFT *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(Int64ValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
- else
- SetSourcei64v(Source, Context, param, values);
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(FloatValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALdouble dval;
- if(GetSourcedv(Source, Context, param, &dval))
- *value = (ALfloat)dval;
- }
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(FloatValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALdouble dvals[3];
- if(GetSourcedv(Source, Context, param, dvals))
- {
- *value1 = (ALfloat)dvals[0];
- *value2 = (ALfloat)dvals[1];
- *value3 = (ALfloat)dvals[2];
- }
- }
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- ALint count;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!((count=FloatValsByProp(param)) > 0 && count <= 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALdouble dvals[3];
- if(GetSourcedv(Source, Context, param, dvals))
- {
- ALint i;
- for(i = 0;i < count;i++)
- values[i] = (ALfloat)dvals[i];
- }
- }
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSourcedSOFT(ALuint source, ALenum param, ALdouble *value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(DoubleValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- GetSourcedv(Source, Context, param, value);
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble *value1, ALdouble *value2, ALdouble *value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(DoubleValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALdouble dvals[3];
- if(GetSourcedv(Source, Context, param, dvals))
- {
- *value1 = dvals[0];
- *value2 = dvals[1];
- *value3 = dvals[2];
- }
- }
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(DoubleValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
- else
- GetSourcedv(Source, Context, param, values);
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(IntValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- GetSourceiv(Source, Context, param, value);
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1, ALint *value2, ALint *value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(IntValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALint ivals[3];
- if(GetSourceiv(Source, Context, param, ivals))
- {
- *value1 = ivals[0];
- *value2 = ivals[1];
- *value3 = ivals[2];
- }
- }
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSourceiv(ALuint source, ALenum param, ALint *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(IntValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
- else
- GetSourceiv(Source, Context, param, values);
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT *value)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(Int64ValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
- else
- GetSourcei64v(Source, Context, param, value);
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT *value1, ALint64SOFT *value2, ALint64SOFT *value3)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(Int64ValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
- else
- {
- ALint64 i64vals[3];
- if(GetSourcei64v(Source, Context, param, i64vals))
- {
- *value1 = i64vals[0];
- *value2 = i64vals[1];
- *value3 = i64vals[2];
- }
- }
- ALCcontext_DecRef(Context);
- }
- AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64SOFT *values)
- {
- ALCcontext *Context;
- ALsource *Source;
- Context = GetContextRef();
- if(!Context) return;
- if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
- else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
- else if(!(Int64ValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
- else
- GetSourcei64v(Source, Context, param, values);
- ALCcontext_DecRef(Context);
- }
- AL_API ALvoid AL_APIENTRY alSourcePlay(ALuint source)
- {
- alSourcePlayv(1, &source);
- }
- AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
- {
- ALCcontext *context;
- ALsource *source;
- ALsizei i;
- context = GetContextRef();
- if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- for(i = 0;i < n;i++)
- {
- if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- }
- LockContext(context);
- while(n > context->MaxActiveSources-context->ActiveSourceCount)
- {
- void *temp = NULL;
- ALsizei newcount;
- newcount = context->MaxActiveSources << 1;
- if(newcount > 0)
- temp = realloc(context->ActiveSources,
- sizeof(*context->ActiveSources) * newcount);
- if(!temp)
- {
- UnlockContext(context);
- SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
- }
- context->ActiveSources = temp;
- context->MaxActiveSources = newcount;
- }
- for(i = 0;i < n;i++)
- {
- source = LookupSource(context, sources[i]);
- if(context->DeferUpdates) source->new_state = AL_PLAYING;
- else SetSourceState(source, context, AL_PLAYING);
- }
- UnlockContext(context);
- done:
- ALCcontext_DecRef(context);
- }
- AL_API ALvoid AL_APIENTRY alSourcePause(ALuint source)
- {
- alSourcePausev(1, &source);
- }
- AL_API ALvoid AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources)
- {
- ALCcontext *context;
- ALsource *source;
- ALsizei i;
- context = GetContextRef();
- if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- for(i = 0;i < n;i++)
- {
- if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- }
- LockContext(context);
- for(i = 0;i < n;i++)
- {
- source = LookupSource(context, sources[i]);
- if(context->DeferUpdates) source->new_state = AL_PAUSED;
- else SetSourceState(source, context, AL_PAUSED);
- }
- UnlockContext(context);
- done:
- ALCcontext_DecRef(context);
- }
- AL_API ALvoid AL_APIENTRY alSourceStop(ALuint source)
- {
- alSourceStopv(1, &source);
- }
- AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources)
- {
- ALCcontext *context;
- ALsource *source;
- ALsizei i;
- context = GetContextRef();
- if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- for(i = 0;i < n;i++)
- {
- if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- }
- LockContext(context);
- for(i = 0;i < n;i++)
- {
- source = LookupSource(context, sources[i]);
- source->new_state = AL_NONE;
- SetSourceState(source, context, AL_STOPPED);
- }
- UnlockContext(context);
- done:
- ALCcontext_DecRef(context);
- }
- AL_API ALvoid AL_APIENTRY alSourceRewind(ALuint source)
- {
- alSourceRewindv(1, &source);
- }
- AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources)
- {
- ALCcontext *context;
- ALsource *source;
- ALsizei i;
- context = GetContextRef();
- if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- for(i = 0;i < n;i++)
- {
- if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- }
- LockContext(context);
- for(i = 0;i < n;i++)
- {
- source = LookupSource(context, sources[i]);
- source->new_state = AL_NONE;
- SetSourceState(source, context, AL_INITIAL);
- }
- UnlockContext(context);
- done:
- ALCcontext_DecRef(context);
- }
- AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALuint *buffers)
- {
- ALCdevice *device;
- ALCcontext *context;
- ALsource *source;
- ALsizei i;
- ALbufferlistitem *BufferListStart = NULL;
- ALbufferlistitem *BufferList;
- ALbuffer *BufferFmt = NULL;
- if(nb == 0)
- return;
- context = GetContextRef();
- if(!context) return;
- device = context->Device;
- if(!(nb >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if((source=LookupSource(context, src)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- LockContext(context);
- if(source->SourceType == AL_STATIC)
- {
- UnlockContext(context);
- /* Can't queue on a Static Source */
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
- }
- /* Check for a valid Buffer, for its frequency and format */
- BufferList = source->queue;
- while(BufferList)
- {
- if(BufferList->buffer)
- {
- BufferFmt = BufferList->buffer;
- break;
- }
- BufferList = BufferList->next;
- }
- for(i = 0;i < nb;i++)
- {
- ALbuffer *buffer = NULL;
- if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == NULL)
- {
- UnlockContext(context);
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- }
- if(!BufferListStart)
- {
- BufferListStart = malloc(sizeof(ALbufferlistitem));
- BufferListStart->buffer = buffer;
- BufferListStart->next = NULL;
- BufferListStart->prev = NULL;
- BufferList = BufferListStart;
- }
- else
- {
- BufferList->next = malloc(sizeof(ALbufferlistitem));
- BufferList->next->buffer = buffer;
- BufferList->next->next = NULL;
- BufferList->next->prev = BufferList;
- BufferList = BufferList->next;
- }
- if(!buffer) continue;
- IncrementRef(&buffer->ref);
- ReadLock(&buffer->lock);
- if(BufferFmt == NULL)
- {
- BufferFmt = buffer;
- source->NumChannels = ChannelsFromFmt(buffer->FmtChannels);
- source->SampleSize = BytesFromFmt(buffer->FmtType);
- if(buffer->FmtChannels == FmtMono)
- source->Update = CalcSourceParams;
- else
- source->Update = CalcNonAttnSourceParams;
- source->NeedsUpdate = AL_TRUE;
- }
- else if(BufferFmt->Frequency != buffer->Frequency ||
- BufferFmt->OriginalChannels != buffer->OriginalChannels ||
- BufferFmt->OriginalType != buffer->OriginalType)
- {
- ReadUnlock(&buffer->lock);
- UnlockContext(context);
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
- }
- ReadUnlock(&buffer->lock);
- }
- /* Source is now streaming */
- source->SourceType = AL_STREAMING;
- if(source->queue == NULL)
- source->queue = BufferListStart;
- else
- {
- /* Append to the end of the queue */
- BufferList = source->queue;
- while(BufferList->next != NULL)
- BufferList = BufferList->next;
- BufferListStart->prev = BufferList;
- BufferList->next = BufferListStart;
- }
- BufferListStart = NULL;
- source->BuffersInQueue += nb;
- UnlockContext(context);
- done:
- while(BufferListStart)
- {
- BufferList = BufferListStart;
- BufferListStart = BufferList->next;
- if(BufferList->buffer)
- DecrementRef(&BufferList->buffer->ref);
- free(BufferList);
- }
- ALCcontext_DecRef(context);
- }
- AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint *buffers)
- {
- ALCcontext *context;
- ALsource *source;
- ALsizei i;
- ALbufferlistitem *BufferList;
- if(nb == 0)
- return;
- context = GetContextRef();
- if(!context) return;
- if(!(nb >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if((source=LookupSource(context, src)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- LockContext(context);
- if(source->Looping || source->SourceType != AL_STREAMING ||
- (ALuint)nb > source->BuffersPlayed)
- {
- UnlockContext(context);
- /* Trying to unqueue pending buffers, or a buffer that wasn't queued. */
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
- for(i = 0;i < nb;i++)
- {
- BufferList = source->queue;
- source->queue = BufferList->next;
- source->BuffersInQueue--;
- source->BuffersPlayed--;
- if(BufferList->buffer)
- {
- buffers[i] = BufferList->buffer->id;
- DecrementRef(&BufferList->buffer->ref);
- }
- else
- buffers[i] = 0;
- free(BufferList);
- }
- if(source->queue)
- source->queue->prev = NULL;
- UnlockContext(context);
- done:
- ALCcontext_DecRef(context);
- }
- static ALvoid InitSourceParams(ALsource *Source)
- {
- ALuint i;
- Source->InnerAngle = 360.0f;
- Source->OuterAngle = 360.0f;
- Source->Pitch = 1.0f;
- Source->Position[0] = 0.0f;
- Source->Position[1] = 0.0f;
- Source->Position[2] = 0.0f;
- Source->Orientation[0] = 0.0f;
- Source->Orientation[1] = 0.0f;
- Source->Orientation[2] = 0.0f;
- Source->Velocity[0] = 0.0f;
- Source->Velocity[1] = 0.0f;
- Source->Velocity[2] = 0.0f;
- Source->RefDistance = 1.0f;
- Source->MaxDistance = FLT_MAX;
- Source->RollOffFactor = 1.0f;
- Source->Looping = AL_FALSE;
- Source->Gain = 1.0f;
- Source->MinGain = 0.0f;
- Source->MaxGain = 1.0f;
- Source->OuterGain = 0.0f;
- Source->OuterGainHF = 1.0f;
- Source->DryGainHFAuto = AL_TRUE;
- Source->WetGainAuto = AL_TRUE;
- Source->WetGainHFAuto = AL_TRUE;
- Source->AirAbsorptionFactor = 0.0f;
- Source->RoomRolloffFactor = 0.0f;
- Source->DopplerFactor = 1.0f;
- Source->DirectChannels = AL_FALSE;
- Source->DistanceModel = DefaultDistanceModel;
- Source->Resampler = DefaultResampler;
- Source->state = AL_INITIAL;
- Source->new_state = AL_NONE;
- Source->SourceType = AL_UNDETERMINED;
- Source->Offset = -1.0;
- Source->DirectGain = 1.0f;
- Source->DirectGainHF = 1.0f;
- for(i = 0;i < MAX_SENDS;i++)
- {
- Source->Send[i].Gain = 1.0f;
- Source->Send[i].GainHF = 1.0f;
- }
- Source->NeedsUpdate = AL_TRUE;
- Source->Hrtf.Moving = AL_FALSE;
- Source->Hrtf.Counter = 0;
- }
- /* SetSourceState
- *
- * Sets the source's new play state given its current state.
- */
- ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
- {
- if(state == AL_PLAYING)
- {
- ALbufferlistitem *BufferList;
- ALsizei j, k;
- /* Check that there is a queue containing at least one valid, non zero
- * length Buffer. */
- BufferList = Source->queue;
- while(BufferList)
- {
- if(BufferList->buffer != NULL && BufferList->buffer->SampleLen)
- break;
- BufferList = BufferList->next;
- }
- if(Source->state != AL_PLAYING)
- {
- for(j = 0;j < MAX_INPUT_CHANNELS;j++)
- {
- for(k = 0;k < SRC_HISTORY_LENGTH;k++)
- Source->Hrtf.History[j][k] = 0.0f;
- for(k = 0;k < HRIR_LENGTH;k++)
- {
- Source->Hrtf.Values[j][k][0] = 0.0f;
- Source->Hrtf.Values[j][k][1] = 0.0f;
- }
- }
- }
- if(Source->state != AL_PAUSED)
- {
- Source->state = AL_PLAYING;
- Source->position = 0;
- Source->position_fraction = 0;
- Source->BuffersPlayed = 0;
- }
- else
- Source->state = AL_PLAYING;
- // Check if an Offset has been set
- if(Source->Offset >= 0.0)
- ApplyOffset(Source);
- /* If there's nothing to play, or device is disconnected, go right to
- * stopped */
- if(!BufferList || !Context->Device->Connected)
- {
- SetSourceState(Source, Context, AL_STOPPED);
- return;
- }
- for(j = 0;j < Context->ActiveSourceCount;j++)
- {
- if(Context->ActiveSources[j] == Source)
- break;
- }
- if(j == Context->ActiveSourceCount)
- Context->ActiveSources[Context->ActiveSourceCount++] = Source;
- }
- else if(state == AL_PAUSED)
- {
- if(Source->state == AL_PLAYING)
- {
- Source->state = AL_PAUSED;
- Source->Hrtf.Moving = AL_FALSE;
- Source->Hrtf.Counter = 0;
- }
- }
- else if(state == AL_STOPPED)
- {
- if(Source->state != AL_INITIAL)
- {
- Source->state = AL_STOPPED;
- Source->BuffersPlayed = Source->BuffersInQueue;
- Source->Hrtf.Moving = AL_FALSE;
- Source->Hrtf.Counter = 0;
- }
- Source->Offset = -1.0;
- }
- else if(state == AL_INITIAL)
- {
- if(Source->state != AL_INITIAL)
- {
- Source->state = AL_INITIAL;
- Source->position = 0;
- Source->position_fraction = 0;
- Source->BuffersPlayed = 0;
- Source->Hrtf.Moving = AL_FALSE;
- Source->Hrtf.Counter = 0;
- }
- Source->Offset = -1.0;
- }
- }
- /* GetSourceOffset
- *
- * Gets the current read offset for the given Source, in 32.32 fixed-point
- * samples. The offset is relative to the start of the queue (not the start of
- * the current buffer).
- */
- static ALint64 GetSourceOffset(const ALsource *Source)
- {
- const ALbufferlistitem *BufferList;
- ALuint64 readPos;
- ALuint i;
- if(Source->state != AL_PLAYING && Source->state != AL_PAUSED)
- return 0;
- /* NOTE: This is the offset into the *current* buffer, so add the length of
- * any played buffers */
- readPos = (ALuint64)Source->position << 32;
- readPos |= (ALuint64)Source->position_fraction << (32-FRACTIONBITS);
- BufferList = Source->queue;
- for(i = 0;i < Source->BuffersPlayed && BufferList;i++)
- {
- if(BufferList->buffer)
- readPos += (ALuint64)BufferList->buffer->SampleLen << 32;
- BufferList = BufferList->next;
- }
- return (ALint64)minu64(readPos, U64(0x7fffffffffffffff));
- }
- /* GetSourceSecOffset
- *
- * Gets the current read offset for the given Source, in seconds. The offset is
- * relative to the start of the queue (not the start of the current buffer).
- */
- static ALdouble GetSourceSecOffset(const ALsource *Source)
- {
- const ALbufferlistitem *BufferList;
- const ALbuffer *Buffer = NULL;
- ALuint64 readPos;
- ALuint i;
- BufferList = Source->queue;
- while(BufferList)
- {
- if(BufferList->buffer)
- {
- Buffer = BufferList->buffer;
- break;
- }
- BufferList = BufferList->next;
- }
- if((Source->state != AL_PLAYING && Source->state != AL_PAUSED) || !Buffer)
- return 0.0;
- /* NOTE: This is the offset into the *current* buffer, so add the length of
- * any played buffers */
- readPos = (ALuint64)Source->position << FRACTIONBITS;
- readPos |= (ALuint64)Source->position_fraction;
- BufferList = Source->queue;
- for(i = 0;i < Source->BuffersPlayed && BufferList;i++)
- {
- if(BufferList->buffer)
- readPos += (ALuint64)BufferList->buffer->SampleLen << FRACTIONBITS;
- BufferList = BufferList->next;
- }
- return (ALdouble)readPos / (ALdouble)FRACTIONONE / (ALdouble)Buffer->Frequency;
- }
- /* GetSourceOffsets
- *
- * Gets the current read and write offsets for the given Source, in the
- * appropriate format (Bytes, Samples or Seconds). The offsets are relative to
- * the start of the queue (not the start of the current buffer).
- */
- static ALvoid GetSourceOffsets(const ALsource *Source, ALenum name, ALdouble *offset, ALdouble updateLen)
- {
- const ALbufferlistitem *BufferList;
- const ALbuffer *Buffer = NULL;
- ALuint readPos, writePos;
- ALuint totalBufferLen;
- ALuint i;
- // Find the first valid Buffer in the Queue
- BufferList = Source->queue;
- while(BufferList)
- {
- if(BufferList->buffer)
- {
- Buffer = BufferList->buffer;
- break;
- }
- BufferList = BufferList->next;
- }
- if((Source->state != AL_PLAYING && Source->state != AL_PAUSED) || !Buffer)
- {
- offset[0] = 0.0;
- offset[1] = 0.0;
- return;
- }
- if(updateLen > 0.0 && updateLen < 0.015)
- updateLen = 0.015;
- /* NOTE: This is the offset into the *current* buffer, so add the length of
- * any played buffers */
- readPos = Source->position;
- totalBufferLen = 0;
- BufferList = Source->queue;
- for(i = 0;BufferList;i++)
- {
- if(BufferList->buffer)
- {
- if(i < Source->BuffersPlayed)
- readPos += BufferList->buffer->SampleLen;
- totalBufferLen += BufferList->buffer->SampleLen;
- }
- BufferList = BufferList->next;
- }
- if(Source->state == AL_PLAYING)
- writePos = readPos + (ALuint)(updateLen*Buffer->Frequency);
- else
- writePos = readPos;
- if(Source->Looping)
- {
- readPos %= totalBufferLen;
- writePos %= totalBufferLen;
- }
- else
- {
- /* Wrap positions back to 0 */
- if(readPos >= totalBufferLen)
- readPos = 0;
- if(writePos >= totalBufferLen)
- writePos = 0;
- }
- switch(name)
- {
- case AL_SEC_OFFSET:
- offset[0] = (ALdouble)readPos / Buffer->Frequency;
- offset[1] = (ALdouble)writePos / Buffer->Frequency;
- break;
- case AL_SAMPLE_OFFSET:
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- offset[0] = (ALdouble)readPos;
- offset[1] = (ALdouble)writePos;
- break;
- case AL_BYTE_OFFSET:
- case AL_BYTE_RW_OFFSETS_SOFT:
- if(Buffer->OriginalType == UserFmtIMA4)
- {
- ALuint BlockSize = 36 * ChannelsFromFmt(Buffer->FmtChannels);
- ALuint FrameBlockSize = 65;
- /* Round down to nearest ADPCM block */
- offset[0] = (ALdouble)(readPos / FrameBlockSize * BlockSize);
- if(Source->state != AL_PLAYING)
- offset[1] = offset[0];
- else
- {
- /* Round up to nearest ADPCM block */
- offset[1] = (ALdouble)((writePos+FrameBlockSize-1) /
- FrameBlockSize * BlockSize);
- }
- }
- else
- {
- ALuint FrameSize = FrameSizeFromUserFmt(Buffer->OriginalChannels, Buffer->OriginalType);
- offset[0] = (ALdouble)(readPos * FrameSize);
- offset[1] = (ALdouble)(writePos * FrameSize);
- }
- break;
- }
- }
- /* ApplyOffset
- *
- * Apply the stored playback offset to the Source. This function will update
- * the number of buffers "played" given the stored offset.
- */
- ALboolean ApplyOffset(ALsource *Source)
- {
- const ALbufferlistitem *BufferList;
- const ALbuffer *Buffer;
- ALint bufferLen, totalBufferLen;
- ALint buffersPlayed;
- ALint offset;
- /* Get sample frame offset */
- offset = GetSampleOffset(Source);
- if(offset == -1)
- return AL_FALSE;
- buffersPlayed = 0;
- totalBufferLen = 0;
- BufferList = Source->queue;
- while(BufferList)
- {
- Buffer = BufferList->buffer;
- bufferLen = Buffer ? Buffer->SampleLen : 0;
- if(bufferLen <= offset-totalBufferLen)
- {
- /* Offset is past this buffer so increment to the next buffer */
- buffersPlayed++;
- }
- else if(totalBufferLen <= offset)
- {
- /* Offset is in this buffer */
- Source->BuffersPlayed = buffersPlayed;
- Source->position = offset - totalBufferLen;
- Source->position_fraction = 0;
- return AL_TRUE;
- }
- totalBufferLen += bufferLen;
- BufferList = BufferList->next;
- }
- /* Offset is out of range of the queue */
- return AL_FALSE;
- }
- /* GetSampleOffset
- *
- * Returns the sample offset into the Source's queue (from the Sample, Byte or
- * Second offset supplied by the application). This takes into account the fact
- * that the buffer format may have been modifed since.
- */
- static ALint GetSampleOffset(ALsource *Source)
- {
- const ALbuffer *Buffer = NULL;
- const ALbufferlistitem *BufferList;
- ALint Offset = -1;
- /* Find the first valid Buffer in the Queue */
- BufferList = Source->queue;
- while(BufferList)
- {
- if(BufferList->buffer)
- {
- Buffer = BufferList->buffer;
- break;
- }
- BufferList = BufferList->next;
- }
- if(!Buffer)
- {
- Source->Offset = -1.0;
- return -1;
- }
- switch(Source->OffsetType)
- {
- case AL_BYTE_OFFSET:
- /* Determine the ByteOffset (and ensure it is block aligned) */
- Offset = (ALint)Source->Offset;
- if(Buffer->OriginalType == UserFmtIMA4)
- {
- Offset /= 36 * ChannelsFromUserFmt(Buffer->OriginalChannels);
- Offset *= 65;
- }
- else
- Offset /= FrameSizeFromUserFmt(Buffer->OriginalChannels, Buffer->OriginalType);
- break;
- case AL_SAMPLE_OFFSET:
- Offset = (ALint)Source->Offset;
- break;
- case AL_SEC_OFFSET:
- Offset = (ALint)(Source->Offset * Buffer->Frequency);
- break;
- }
- Source->Offset = -1.0;
- return Offset;
- }
- /* ReleaseALSources
- *
- * Destroys all sources in the source map.
- */
- ALvoid ReleaseALSources(ALCcontext *Context)
- {
- ALsizei pos;
- ALuint j;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
- {
- ALsource *temp = Context->SourceMap.array[pos].value;
- Context->SourceMap.array[pos].value = NULL;
- while(temp->queue != NULL)
- {
- ALbufferlistitem *BufferList = temp->queue;
- temp->queue = BufferList->next;
- if(BufferList->buffer != NULL)
- DecrementRef(&BufferList->buffer->ref);
- free(BufferList);
- }
- for(j = 0;j < MAX_SENDS;++j)
- {
- if(temp->Send[j].Slot)
- DecrementRef(&temp->Send[j].Slot->ref);
- temp->Send[j].Slot = NULL;
- }
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(*temp));
- al_free(temp);
- }
- }
|