| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558 |
- /**
- * 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 <math.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <memory.h>
- #include <ctype.h>
- #include <signal.h>
- #include "alMain.h"
- #include "alSource.h"
- #include "alListener.h"
- #include "alThunk.h"
- #include "alSource.h"
- #include "alBuffer.h"
- #include "alAuxEffectSlot.h"
- #include "alError.h"
- #include "alMidi.h"
- #include "bs2b.h"
- #include "alu.h"
- #include "backends/base.h"
- #include "midi/base.h"
- /************************************************
- * Backends
- ************************************************/
- struct BackendInfo {
- const char *name;
- ALCbackendFactory* (*getFactory)(void);
- ALCboolean (*Init)(BackendFuncs*);
- void (*Deinit)(void);
- void (*Probe)(enum DevProbe);
- BackendFuncs Funcs;
- };
- #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
- static struct BackendInfo BackendList[] = {
- #ifdef HAVE_PULSEAUDIO
- { "pulse", ALCpulseBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
- #endif
- #ifdef HAVE_ALSA
- { "alsa", ALCalsaBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
- #endif
- #ifdef HAVE_COREAUDIO
- { "core", NULL, alc_ca_init, alc_ca_deinit, alc_ca_probe, EmptyFuncs },
- #endif
- #ifdef HAVE_OSS
- { "oss", ALCossBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
- #endif
- #ifdef HAVE_SOLARIS
- { "solaris", NULL, alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs },
- #endif
- #ifdef HAVE_SNDIO
- { "sndio", NULL, alc_sndio_init, alc_sndio_deinit, alc_sndio_probe, EmptyFuncs },
- #endif
- #ifdef HAVE_QSA
- { "qsa", NULL, alc_qsa_init, alc_qsa_deinit, alc_qsa_probe, EmptyFuncs },
- #endif
- #ifdef HAVE_MMDEVAPI
- { "mmdevapi", NULL, alcMMDevApiInit, alcMMDevApiDeinit, alcMMDevApiProbe, EmptyFuncs },
- #endif
- #ifdef HAVE_DSOUND
- { "dsound", NULL, alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs },
- #endif
- #ifdef HAVE_WINMM
- { "winmm", NULL, alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs },
- #endif
- #ifdef HAVE_PORTAUDIO
- { "port", NULL, alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs },
- #endif
- #ifdef HAVE_OPENSL
- { "opensl", NULL, alc_opensl_init, alc_opensl_deinit, alc_opensl_probe, EmptyFuncs },
- #endif
- { "null", ALCnullBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
- #ifdef HAVE_WAVE
- { "wave", NULL, alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs },
- #endif
- { NULL, NULL, NULL, NULL, NULL, EmptyFuncs }
- };
- #undef EmptyFuncs
- static struct BackendInfo PlaybackBackend;
- static struct BackendInfo CaptureBackend;
- /************************************************
- * Functions, enums, and errors
- ************************************************/
- typedef struct ALCfunction {
- const ALCchar *funcName;
- ALCvoid *address;
- } ALCfunction;
- typedef struct ALCenums {
- const ALCchar *enumName;
- ALCenum value;
- } ALCenums;
- #define DECL(x) { #x, (ALCvoid*)(x) }
- static const ALCfunction alcFunctions[] = {
- DECL(alcCreateContext),
- DECL(alcMakeContextCurrent),
- DECL(alcProcessContext),
- DECL(alcSuspendContext),
- DECL(alcDestroyContext),
- DECL(alcGetCurrentContext),
- DECL(alcGetContextsDevice),
- DECL(alcOpenDevice),
- DECL(alcCloseDevice),
- DECL(alcGetError),
- DECL(alcIsExtensionPresent),
- DECL(alcGetProcAddress),
- DECL(alcGetEnumValue),
- DECL(alcGetString),
- DECL(alcGetIntegerv),
- DECL(alcCaptureOpenDevice),
- DECL(alcCaptureCloseDevice),
- DECL(alcCaptureStart),
- DECL(alcCaptureStop),
- DECL(alcCaptureSamples),
- DECL(alcSetThreadContext),
- DECL(alcGetThreadContext),
- DECL(alcLoopbackOpenDeviceSOFT),
- DECL(alcIsRenderFormatSupportedSOFT),
- DECL(alcRenderSamplesSOFT),
- DECL(alcDevicePauseSOFT),
- DECL(alcDeviceResumeSOFT),
- DECL(alEnable),
- DECL(alDisable),
- DECL(alIsEnabled),
- DECL(alGetString),
- DECL(alGetBooleanv),
- DECL(alGetIntegerv),
- DECL(alGetFloatv),
- DECL(alGetDoublev),
- DECL(alGetBoolean),
- DECL(alGetInteger),
- DECL(alGetFloat),
- DECL(alGetDouble),
- DECL(alGetError),
- DECL(alIsExtensionPresent),
- DECL(alGetProcAddress),
- DECL(alGetEnumValue),
- DECL(alListenerf),
- DECL(alListener3f),
- DECL(alListenerfv),
- DECL(alListeneri),
- DECL(alListener3i),
- DECL(alListeneriv),
- DECL(alGetListenerf),
- DECL(alGetListener3f),
- DECL(alGetListenerfv),
- DECL(alGetListeneri),
- DECL(alGetListener3i),
- DECL(alGetListeneriv),
- DECL(alGenSources),
- DECL(alDeleteSources),
- DECL(alIsSource),
- DECL(alSourcef),
- DECL(alSource3f),
- DECL(alSourcefv),
- DECL(alSourcei),
- DECL(alSource3i),
- DECL(alSourceiv),
- DECL(alGetSourcef),
- DECL(alGetSource3f),
- DECL(alGetSourcefv),
- DECL(alGetSourcei),
- DECL(alGetSource3i),
- DECL(alGetSourceiv),
- DECL(alSourcePlayv),
- DECL(alSourceStopv),
- DECL(alSourceRewindv),
- DECL(alSourcePausev),
- DECL(alSourcePlay),
- DECL(alSourceStop),
- DECL(alSourceRewind),
- DECL(alSourcePause),
- DECL(alSourceQueueBuffers),
- DECL(alSourceUnqueueBuffers),
- DECL(alGenBuffers),
- DECL(alDeleteBuffers),
- DECL(alIsBuffer),
- DECL(alBufferData),
- DECL(alBufferf),
- DECL(alBuffer3f),
- DECL(alBufferfv),
- DECL(alBufferi),
- DECL(alBuffer3i),
- DECL(alBufferiv),
- DECL(alGetBufferf),
- DECL(alGetBuffer3f),
- DECL(alGetBufferfv),
- DECL(alGetBufferi),
- DECL(alGetBuffer3i),
- DECL(alGetBufferiv),
- DECL(alDopplerFactor),
- DECL(alDopplerVelocity),
- DECL(alSpeedOfSound),
- DECL(alDistanceModel),
- DECL(alGenFilters),
- DECL(alDeleteFilters),
- DECL(alIsFilter),
- DECL(alFilteri),
- DECL(alFilteriv),
- DECL(alFilterf),
- DECL(alFilterfv),
- DECL(alGetFilteri),
- DECL(alGetFilteriv),
- DECL(alGetFilterf),
- DECL(alGetFilterfv),
- DECL(alGenEffects),
- DECL(alDeleteEffects),
- DECL(alIsEffect),
- DECL(alEffecti),
- DECL(alEffectiv),
- DECL(alEffectf),
- DECL(alEffectfv),
- DECL(alGetEffecti),
- DECL(alGetEffectiv),
- DECL(alGetEffectf),
- DECL(alGetEffectfv),
- DECL(alGenAuxiliaryEffectSlots),
- DECL(alDeleteAuxiliaryEffectSlots),
- DECL(alIsAuxiliaryEffectSlot),
- DECL(alAuxiliaryEffectSloti),
- DECL(alAuxiliaryEffectSlotiv),
- DECL(alAuxiliaryEffectSlotf),
- DECL(alAuxiliaryEffectSlotfv),
- DECL(alGetAuxiliaryEffectSloti),
- DECL(alGetAuxiliaryEffectSlotiv),
- DECL(alGetAuxiliaryEffectSlotf),
- DECL(alGetAuxiliaryEffectSlotfv),
- DECL(alBufferSubDataSOFT),
- DECL(alBufferSamplesSOFT),
- DECL(alBufferSubSamplesSOFT),
- DECL(alGetBufferSamplesSOFT),
- DECL(alIsBufferFormatSupportedSOFT),
- DECL(alDeferUpdatesSOFT),
- DECL(alProcessUpdatesSOFT),
- DECL(alSourcedSOFT),
- DECL(alSource3dSOFT),
- DECL(alSourcedvSOFT),
- DECL(alGetSourcedSOFT),
- DECL(alGetSource3dSOFT),
- DECL(alGetSourcedvSOFT),
- DECL(alSourcei64SOFT),
- DECL(alSource3i64SOFT),
- DECL(alSourcei64vSOFT),
- DECL(alGetSourcei64SOFT),
- DECL(alGetSource3i64SOFT),
- DECL(alGetSourcei64vSOFT),
- DECL(alGenSoundfontsSOFT),
- DECL(alDeleteSoundfontsSOFT),
- DECL(alIsSoundfontSOFT),
- DECL(alSoundfontSamplesSOFT),
- DECL(alGetSoundfontSamplesSOFT),
- DECL(alSoundfontMapSamplesSOFT),
- DECL(alSoundfontUnmapSamplesSOFT),
- DECL(alGetSoundfontivSOFT),
- DECL(alSoundfontPresetsSOFT),
- DECL(alGenPresetsSOFT),
- DECL(alDeletePresetsSOFT),
- DECL(alIsPresetSOFT),
- DECL(alPresetiSOFT),
- DECL(alPresetivSOFT),
- DECL(alGetPresetivSOFT),
- DECL(alPresetFontsoundsSOFT),
- DECL(alGenFontsoundsSOFT),
- DECL(alDeleteFontsoundsSOFT),
- DECL(alIsFontsoundSOFT),
- DECL(alFontsoundiSOFT),
- DECL(alFontsound2iSOFT),
- DECL(alFontsoundivSOFT),
- DECL(alGetFontsoundivSOFT),
- DECL(alFontsoundModulatoriSOFT),
- DECL(alGetFontsoundModulatorivSOFT),
- DECL(alMidiSoundfontSOFT),
- DECL(alMidiSoundfontvSOFT),
- DECL(alMidiEventSOFT),
- DECL(alMidiSysExSOFT),
- DECL(alMidiPlaySOFT),
- DECL(alMidiPauseSOFT),
- DECL(alMidiStopSOFT),
- DECL(alMidiResetSOFT),
- DECL(alMidiGainSOFT),
- DECL(alGetInteger64SOFT),
- DECL(alGetInteger64vSOFT),
- DECL(alLoadSoundfontSOFT),
- { NULL, NULL }
- };
- #undef DECL
- #define DECL(x) { #x, (x) }
- static const ALCenums enumeration[] = {
- DECL(ALC_INVALID),
- DECL(ALC_FALSE),
- DECL(ALC_TRUE),
- DECL(ALC_MAJOR_VERSION),
- DECL(ALC_MINOR_VERSION),
- DECL(ALC_ATTRIBUTES_SIZE),
- DECL(ALC_ALL_ATTRIBUTES),
- DECL(ALC_DEFAULT_DEVICE_SPECIFIER),
- DECL(ALC_DEVICE_SPECIFIER),
- DECL(ALC_ALL_DEVICES_SPECIFIER),
- DECL(ALC_DEFAULT_ALL_DEVICES_SPECIFIER),
- DECL(ALC_EXTENSIONS),
- DECL(ALC_FREQUENCY),
- DECL(ALC_REFRESH),
- DECL(ALC_SYNC),
- DECL(ALC_MONO_SOURCES),
- DECL(ALC_STEREO_SOURCES),
- DECL(ALC_CAPTURE_DEVICE_SPECIFIER),
- DECL(ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER),
- DECL(ALC_CAPTURE_SAMPLES),
- DECL(ALC_CONNECTED),
- DECL(ALC_EFX_MAJOR_VERSION),
- DECL(ALC_EFX_MINOR_VERSION),
- DECL(ALC_MAX_AUXILIARY_SENDS),
- DECL(ALC_FORMAT_CHANNELS_SOFT),
- DECL(ALC_FORMAT_TYPE_SOFT),
- DECL(ALC_MONO_SOFT),
- DECL(ALC_STEREO_SOFT),
- DECL(ALC_QUAD_SOFT),
- DECL(ALC_5POINT1_SOFT),
- DECL(ALC_6POINT1_SOFT),
- DECL(ALC_7POINT1_SOFT),
- DECL(ALC_BYTE_SOFT),
- DECL(ALC_UNSIGNED_BYTE_SOFT),
- DECL(ALC_SHORT_SOFT),
- DECL(ALC_UNSIGNED_SHORT_SOFT),
- DECL(ALC_INT_SOFT),
- DECL(ALC_UNSIGNED_INT_SOFT),
- DECL(ALC_FLOAT_SOFT),
- DECL(ALC_NO_ERROR),
- DECL(ALC_INVALID_DEVICE),
- DECL(ALC_INVALID_CONTEXT),
- DECL(ALC_INVALID_ENUM),
- DECL(ALC_INVALID_VALUE),
- DECL(ALC_OUT_OF_MEMORY),
- DECL(AL_INVALID),
- DECL(AL_NONE),
- DECL(AL_FALSE),
- DECL(AL_TRUE),
- DECL(AL_SOURCE_RELATIVE),
- DECL(AL_CONE_INNER_ANGLE),
- DECL(AL_CONE_OUTER_ANGLE),
- DECL(AL_PITCH),
- DECL(AL_POSITION),
- DECL(AL_DIRECTION),
- DECL(AL_VELOCITY),
- DECL(AL_LOOPING),
- DECL(AL_BUFFER),
- DECL(AL_GAIN),
- DECL(AL_MIN_GAIN),
- DECL(AL_MAX_GAIN),
- DECL(AL_ORIENTATION),
- DECL(AL_REFERENCE_DISTANCE),
- DECL(AL_ROLLOFF_FACTOR),
- DECL(AL_CONE_OUTER_GAIN),
- DECL(AL_MAX_DISTANCE),
- DECL(AL_SEC_OFFSET),
- DECL(AL_SAMPLE_OFFSET),
- DECL(AL_SAMPLE_RW_OFFSETS_SOFT),
- DECL(AL_BYTE_OFFSET),
- DECL(AL_BYTE_RW_OFFSETS_SOFT),
- DECL(AL_SOURCE_TYPE),
- DECL(AL_STATIC),
- DECL(AL_STREAMING),
- DECL(AL_UNDETERMINED),
- DECL(AL_METERS_PER_UNIT),
- DECL(AL_DIRECT_CHANNELS_SOFT),
- DECL(AL_DIRECT_FILTER),
- DECL(AL_AUXILIARY_SEND_FILTER),
- DECL(AL_AIR_ABSORPTION_FACTOR),
- DECL(AL_ROOM_ROLLOFF_FACTOR),
- DECL(AL_CONE_OUTER_GAINHF),
- DECL(AL_DIRECT_FILTER_GAINHF_AUTO),
- DECL(AL_AUXILIARY_SEND_FILTER_GAIN_AUTO),
- DECL(AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO),
- DECL(AL_SOURCE_STATE),
- DECL(AL_INITIAL),
- DECL(AL_PLAYING),
- DECL(AL_PAUSED),
- DECL(AL_STOPPED),
- DECL(AL_BUFFERS_QUEUED),
- DECL(AL_BUFFERS_PROCESSED),
- DECL(AL_FORMAT_MONO8),
- DECL(AL_FORMAT_MONO16),
- DECL(AL_FORMAT_MONO_FLOAT32),
- DECL(AL_FORMAT_MONO_DOUBLE_EXT),
- DECL(AL_FORMAT_STEREO8),
- DECL(AL_FORMAT_STEREO16),
- DECL(AL_FORMAT_STEREO_FLOAT32),
- DECL(AL_FORMAT_STEREO_DOUBLE_EXT),
- DECL(AL_FORMAT_MONO_IMA4),
- DECL(AL_FORMAT_STEREO_IMA4),
- DECL(AL_FORMAT_QUAD8_LOKI),
- DECL(AL_FORMAT_QUAD16_LOKI),
- DECL(AL_FORMAT_QUAD8),
- DECL(AL_FORMAT_QUAD16),
- DECL(AL_FORMAT_QUAD32),
- DECL(AL_FORMAT_51CHN8),
- DECL(AL_FORMAT_51CHN16),
- DECL(AL_FORMAT_51CHN32),
- DECL(AL_FORMAT_61CHN8),
- DECL(AL_FORMAT_61CHN16),
- DECL(AL_FORMAT_61CHN32),
- DECL(AL_FORMAT_71CHN8),
- DECL(AL_FORMAT_71CHN16),
- DECL(AL_FORMAT_71CHN32),
- DECL(AL_FORMAT_REAR8),
- DECL(AL_FORMAT_REAR16),
- DECL(AL_FORMAT_REAR32),
- DECL(AL_FORMAT_MONO_MULAW),
- DECL(AL_FORMAT_MONO_MULAW_EXT),
- DECL(AL_FORMAT_STEREO_MULAW),
- DECL(AL_FORMAT_STEREO_MULAW_EXT),
- DECL(AL_FORMAT_QUAD_MULAW),
- DECL(AL_FORMAT_51CHN_MULAW),
- DECL(AL_FORMAT_61CHN_MULAW),
- DECL(AL_FORMAT_71CHN_MULAW),
- DECL(AL_FORMAT_REAR_MULAW),
- DECL(AL_FORMAT_MONO_ALAW_EXT),
- DECL(AL_FORMAT_STEREO_ALAW_EXT),
- DECL(AL_MONO8_SOFT),
- DECL(AL_MONO16_SOFT),
- DECL(AL_MONO32F_SOFT),
- DECL(AL_STEREO8_SOFT),
- DECL(AL_STEREO16_SOFT),
- DECL(AL_STEREO32F_SOFT),
- DECL(AL_QUAD8_SOFT),
- DECL(AL_QUAD16_SOFT),
- DECL(AL_QUAD32F_SOFT),
- DECL(AL_REAR8_SOFT),
- DECL(AL_REAR16_SOFT),
- DECL(AL_REAR32F_SOFT),
- DECL(AL_5POINT1_8_SOFT),
- DECL(AL_5POINT1_16_SOFT),
- DECL(AL_5POINT1_32F_SOFT),
- DECL(AL_6POINT1_8_SOFT),
- DECL(AL_6POINT1_16_SOFT),
- DECL(AL_6POINT1_32F_SOFT),
- DECL(AL_7POINT1_8_SOFT),
- DECL(AL_7POINT1_16_SOFT),
- DECL(AL_7POINT1_32F_SOFT),
- DECL(AL_MONO_SOFT),
- DECL(AL_STEREO_SOFT),
- DECL(AL_QUAD_SOFT),
- DECL(AL_REAR_SOFT),
- DECL(AL_5POINT1_SOFT),
- DECL(AL_6POINT1_SOFT),
- DECL(AL_7POINT1_SOFT),
- DECL(AL_BYTE_SOFT),
- DECL(AL_UNSIGNED_BYTE_SOFT),
- DECL(AL_SHORT_SOFT),
- DECL(AL_UNSIGNED_SHORT_SOFT),
- DECL(AL_INT_SOFT),
- DECL(AL_UNSIGNED_INT_SOFT),
- DECL(AL_FLOAT_SOFT),
- DECL(AL_DOUBLE_SOFT),
- DECL(AL_BYTE3_SOFT),
- DECL(AL_UNSIGNED_BYTE3_SOFT),
- DECL(AL_FREQUENCY),
- DECL(AL_BITS),
- DECL(AL_CHANNELS),
- DECL(AL_SIZE),
- DECL(AL_INTERNAL_FORMAT_SOFT),
- DECL(AL_BYTE_LENGTH_SOFT),
- DECL(AL_SAMPLE_LENGTH_SOFT),
- DECL(AL_SEC_LENGTH_SOFT),
- DECL(AL_UNUSED),
- DECL(AL_PENDING),
- DECL(AL_PROCESSED),
- DECL(AL_NO_ERROR),
- DECL(AL_INVALID_NAME),
- DECL(AL_INVALID_ENUM),
- DECL(AL_INVALID_VALUE),
- DECL(AL_INVALID_OPERATION),
- DECL(AL_OUT_OF_MEMORY),
- DECL(AL_VENDOR),
- DECL(AL_VERSION),
- DECL(AL_RENDERER),
- DECL(AL_EXTENSIONS),
- DECL(AL_DOPPLER_FACTOR),
- DECL(AL_DOPPLER_VELOCITY),
- DECL(AL_DISTANCE_MODEL),
- DECL(AL_SPEED_OF_SOUND),
- DECL(AL_SOURCE_DISTANCE_MODEL),
- DECL(AL_DEFERRED_UPDATES_SOFT),
- DECL(AL_INVERSE_DISTANCE),
- DECL(AL_INVERSE_DISTANCE_CLAMPED),
- DECL(AL_LINEAR_DISTANCE),
- DECL(AL_LINEAR_DISTANCE_CLAMPED),
- DECL(AL_EXPONENT_DISTANCE),
- DECL(AL_EXPONENT_DISTANCE_CLAMPED),
- DECL(AL_FILTER_TYPE),
- DECL(AL_FILTER_NULL),
- DECL(AL_FILTER_LOWPASS),
- #if 0
- DECL(AL_FILTER_HIGHPASS),
- DECL(AL_FILTER_BANDPASS),
- #endif
- DECL(AL_LOWPASS_GAIN),
- DECL(AL_LOWPASS_GAINHF),
- DECL(AL_EFFECT_TYPE),
- DECL(AL_EFFECT_NULL),
- DECL(AL_EFFECT_REVERB),
- DECL(AL_EFFECT_EAXREVERB),
- DECL(AL_EFFECT_CHORUS),
- DECL(AL_EFFECT_DISTORTION),
- DECL(AL_EFFECT_ECHO),
- DECL(AL_EFFECT_FLANGER),
- #if 0
- DECL(AL_EFFECT_FREQUENCY_SHIFTER),
- DECL(AL_EFFECT_VOCAL_MORPHER),
- DECL(AL_EFFECT_PITCH_SHIFTER),
- #endif
- DECL(AL_EFFECT_RING_MODULATOR),
- DECL(AL_EFFECT_AUTOWAH),
- DECL(AL_EFFECT_COMPRESSOR),
- DECL(AL_EFFECT_EQUALIZER),
- DECL(AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT),
- DECL(AL_EFFECT_DEDICATED_DIALOGUE),
- DECL(AL_EAXREVERB_DENSITY),
- DECL(AL_EAXREVERB_DIFFUSION),
- DECL(AL_EAXREVERB_GAIN),
- DECL(AL_EAXREVERB_GAINHF),
- DECL(AL_EAXREVERB_GAINLF),
- DECL(AL_EAXREVERB_DECAY_TIME),
- DECL(AL_EAXREVERB_DECAY_HFRATIO),
- DECL(AL_EAXREVERB_DECAY_LFRATIO),
- DECL(AL_EAXREVERB_REFLECTIONS_GAIN),
- DECL(AL_EAXREVERB_REFLECTIONS_DELAY),
- DECL(AL_EAXREVERB_REFLECTIONS_PAN),
- DECL(AL_EAXREVERB_LATE_REVERB_GAIN),
- DECL(AL_EAXREVERB_LATE_REVERB_DELAY),
- DECL(AL_EAXREVERB_LATE_REVERB_PAN),
- DECL(AL_EAXREVERB_ECHO_TIME),
- DECL(AL_EAXREVERB_ECHO_DEPTH),
- DECL(AL_EAXREVERB_MODULATION_TIME),
- DECL(AL_EAXREVERB_MODULATION_DEPTH),
- DECL(AL_EAXREVERB_AIR_ABSORPTION_GAINHF),
- DECL(AL_EAXREVERB_HFREFERENCE),
- DECL(AL_EAXREVERB_LFREFERENCE),
- DECL(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR),
- DECL(AL_EAXREVERB_DECAY_HFLIMIT),
- DECL(AL_REVERB_DENSITY),
- DECL(AL_REVERB_DIFFUSION),
- DECL(AL_REVERB_GAIN),
- DECL(AL_REVERB_GAINHF),
- DECL(AL_REVERB_DECAY_TIME),
- DECL(AL_REVERB_DECAY_HFRATIO),
- DECL(AL_REVERB_REFLECTIONS_GAIN),
- DECL(AL_REVERB_REFLECTIONS_DELAY),
- DECL(AL_REVERB_LATE_REVERB_GAIN),
- DECL(AL_REVERB_LATE_REVERB_DELAY),
- DECL(AL_REVERB_AIR_ABSORPTION_GAINHF),
- DECL(AL_REVERB_ROOM_ROLLOFF_FACTOR),
- DECL(AL_REVERB_DECAY_HFLIMIT),
- DECL(AL_CHORUS_WAVEFORM),
- DECL(AL_CHORUS_PHASE),
- DECL(AL_CHORUS_RATE),
- DECL(AL_CHORUS_DEPTH),
- DECL(AL_CHORUS_FEEDBACK),
- DECL(AL_CHORUS_DELAY),
- DECL(AL_DISTORTION_EDGE),
- DECL(AL_DISTORTION_GAIN),
- DECL(AL_DISTORTION_LOWPASS_CUTOFF),
- DECL(AL_DISTORTION_EQCENTER),
- DECL(AL_DISTORTION_EQBANDWIDTH),
- DECL(AL_ECHO_DELAY),
- DECL(AL_ECHO_LRDELAY),
- DECL(AL_ECHO_DAMPING),
- DECL(AL_ECHO_FEEDBACK),
- DECL(AL_ECHO_SPREAD),
- DECL(AL_FLANGER_WAVEFORM),
- DECL(AL_FLANGER_PHASE),
- DECL(AL_FLANGER_RATE),
- DECL(AL_FLANGER_DEPTH),
- DECL(AL_FLANGER_FEEDBACK),
- DECL(AL_FLANGER_DELAY),
- DECL(AL_RING_MODULATOR_FREQUENCY),
- DECL(AL_RING_MODULATOR_HIGHPASS_CUTOFF),
- DECL(AL_RING_MODULATOR_WAVEFORM),
- DECL(AL_AUTOWAH_ATTACK_TIME),
- DECL(AL_AUTOWAH_PEAK_GAIN),
- DECL(AL_AUTOWAH_RELEASE_TIME),
- DECL(AL_AUTOWAH_RESONANCE),
- DECL(AL_COMPRESSOR_ONOFF),
- DECL(AL_EQUALIZER_LOW_GAIN),
- DECL(AL_EQUALIZER_LOW_CUTOFF),
- DECL(AL_EQUALIZER_MID1_GAIN),
- DECL(AL_EQUALIZER_MID1_CENTER),
- DECL(AL_EQUALIZER_MID1_WIDTH),
- DECL(AL_EQUALIZER_MID2_GAIN),
- DECL(AL_EQUALIZER_MID2_CENTER),
- DECL(AL_EQUALIZER_MID2_WIDTH),
- DECL(AL_EQUALIZER_HIGH_GAIN),
- DECL(AL_EQUALIZER_HIGH_CUTOFF),
- DECL(AL_DEDICATED_GAIN),
- { NULL, (ALCenum)0 }
- };
- #undef DECL
- static const ALCchar alcNoError[] = "No Error";
- static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
- static const ALCchar alcErrInvalidContext[] = "Invalid Context";
- static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
- static const ALCchar alcErrInvalidValue[] = "Invalid Value";
- static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
- /************************************************
- * Global variables
- ************************************************/
- /* Enumerated device names */
- static const ALCchar alcDefaultName[] = "OpenAL Soft\0";
- static ALCchar *alcAllDevicesList;
- static ALCchar *alcCaptureDeviceList;
- /* Sizes only include the first ending null character, not the second */
- static size_t alcAllDevicesListSize;
- static size_t alcCaptureDeviceListSize;
- /* Default is always the first in the list */
- static ALCchar *alcDefaultAllDevicesSpecifier;
- static ALCchar *alcCaptureDefaultDeviceSpecifier;
- /* Default context extensions */
- static const ALchar alExtList[] =
- "AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 "
- "AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW "
- "AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model "
- "AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data "
- "AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points "
- "AL_SOFT_source_latency";
- static volatile ALCenum LastNullDeviceError = ALC_NO_ERROR;
- /* Thread-local current context */
- static althread_key_t LocalContext;
- /* Process-wide current context */
- static ALCcontext *volatile GlobalContext = NULL;
- /* Mixing thread piority level */
- ALint RTPrioLevel;
- FILE *LogFile;
- #ifdef _DEBUG
- enum LogLevel LogLevel = LogWarning;
- #else
- enum LogLevel LogLevel = LogError;
- #endif
- /* Flag to trap ALC device errors */
- static ALCboolean TrapALCError = ALC_FALSE;
- /* One-time configuration init control */
- static althread_once_t alc_config_once = ALTHREAD_ONCE_INIT;
- /* Default effect that applies to sources that don't have an effect on send 0 */
- static ALeffect DefaultEffect;
- /************************************************
- * ALC information
- ************************************************/
- static const ALCchar alcNoDeviceExtList[] =
- "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
- "ALC_EXT_thread_local_context ALC_SOFT_loopback";
- static const ALCchar alcExtensionList[] =
- "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
- "ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX "
- "ALC_EXT_thread_local_context ALC_SOFTX_HRTF ALC_SOFT_loopback "
- "ALC_SOFTX_midi_interface ALC_SOFTX_pause_device";
- static const ALCint alcMajorVersion = 1;
- static const ALCint alcMinorVersion = 1;
- static const ALCint alcEFXMajorVersion = 1;
- static const ALCint alcEFXMinorVersion = 0;
- /************************************************
- * Device lists
- ************************************************/
- static ALCdevice *volatile DeviceList = NULL;
- static CRITICAL_SECTION ListLock;
- static void LockLists(void)
- {
- EnterCriticalSection(&ListLock);
- }
- static void UnlockLists(void)
- {
- LeaveCriticalSection(&ListLock);
- }
- /************************************************
- * Library initialization
- ************************************************/
- #if defined(_WIN32)
- static void alc_init(void);
- static void alc_deinit(void);
- static void alc_deinit_safe(void);
- UIntMap TlsDestructor;
- #ifndef AL_LIBTYPE_STATIC
- BOOL APIENTRY DllMain(HINSTANCE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
- {
- ALsizei i;
- // Perform actions based on the reason for calling.
- switch(ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- /* Pin the DLL so we won't get unloaded until the process terminates */
- GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
- (WCHAR*)hModule, &hModule);
- InitUIntMap(&TlsDestructor, ~0);
- alc_init();
- break;
- case DLL_THREAD_DETACH:
- LockUIntMapRead(&TlsDestructor);
- for(i = 0;i < TlsDestructor.size;i++)
- {
- void *ptr = althread_getspecific(TlsDestructor.array[i].key);
- void (*callback)(void*) = (void(*)(void*))TlsDestructor.array[i].value;
- if(ptr && callback)
- callback(ptr);
- }
- UnlockUIntMapRead(&TlsDestructor);
- break;
- case DLL_PROCESS_DETACH:
- if(!lpReserved)
- alc_deinit();
- else
- alc_deinit_safe();
- ResetUIntMap(&TlsDestructor);
- break;
- }
- return TRUE;
- }
- #elif defined(_MSC_VER)
- #pragma section(".CRT$XCU",read)
- static void alc_constructor(void);
- static void alc_destructor(void);
- __declspec(allocate(".CRT$XCU")) void (__cdecl* alc_constructor_)(void) = alc_constructor;
- static void alc_constructor(void)
- {
- atexit(alc_destructor);
- alc_init();
- }
- static void alc_destructor(void)
- {
- alc_deinit();
- }
- #elif defined(HAVE_GCC_DESTRUCTOR)
- static void alc_init(void) __attribute__((constructor));
- static void alc_deinit(void) __attribute__((destructor));
- #else
- #error "No static initialization available on this platform!"
- #endif
- #elif defined(HAVE_GCC_DESTRUCTOR)
- static void alc_init(void) __attribute__((constructor));
- static void alc_deinit(void) __attribute__((destructor));
- #else
- #error "No global initialization available on this platform!"
- #endif
- static void ReleaseThreadCtx(void *ptr);
- static void alc_init(void)
- {
- const char *str;
- LogFile = stderr;
- str = getenv("__ALSOFT_HALF_ANGLE_CONES");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
- ConeScale *= 0.5f;
- str = getenv("__ALSOFT_REVERSE_Z");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
- ZScale *= -1.0f;
- althread_key_create(&LocalContext, ReleaseThreadCtx);
- InitializeCriticalSection(&ListLock);
- ThunkInit();
- }
- static void alc_initconfig(void)
- {
- const char *devs, *str;
- ALuint capfilter;
- float valf;
- int i, n;
- str = getenv("ALSOFT_LOGLEVEL");
- if(str)
- {
- long lvl = strtol(str, NULL, 0);
- if(lvl >= NoLog && lvl <= LogRef)
- LogLevel = lvl;
- }
- str = getenv("ALSOFT_LOGFILE");
- if(str && str[0])
- {
- FILE *logfile = fopen(str, "wt");
- if(logfile) LogFile = logfile;
- else ERR("Failed to open log file '%s'\n", str);
- }
- {
- char buf[1024] = "";
- int len = snprintf(buf, sizeof(buf), "%s", BackendList[0].name);
- for(i = 1;BackendList[i].name;i++)
- len += snprintf(buf+len, sizeof(buf)-len, ", %s", BackendList[i].name);
- TRACE("Supported backends: %s\n", buf);
- }
- ReadALConfig();
- capfilter = 0;
- #ifdef HAVE_SSE
- capfilter |= CPU_CAP_SSE | CPU_CAP_SSE2;
- #endif
- #ifdef HAVE_NEON
- capfilter |= CPU_CAP_NEON;
- #endif
- if(ConfigValueStr(NULL, "disable-cpu-exts", &str))
- {
- if(strcasecmp(str, "all") == 0)
- capfilter = 0;
- else
- {
- size_t len;
- const char *next = str;
- do {
- str = next;
- while(isspace(str[0]))
- str++;
- next = strchr(str, ',');
- if(!str[0] || str[0] == ',')
- continue;
- len = (next ? ((size_t)(next-str)) : strlen(str));
- while(len > 0 && isspace(str[len-1]))
- len--;
- if(len == 3 && strncasecmp(str, "sse", len) == 0)
- capfilter &= ~CPU_CAP_SSE;
- else if(len == 4 && strncasecmp(str, "sse2", len) == 0)
- capfilter &= ~CPU_CAP_SSE2;
- else if(len == 4 && strncasecmp(str, "neon", len) == 0)
- capfilter &= ~CPU_CAP_NEON;
- else
- WARN("Invalid CPU extension \"%s\"\n", str);
- } while(next++);
- }
- }
- FillCPUCaps(capfilter);
- #ifdef _WIN32
- RTPrioLevel = 1;
- #else
- RTPrioLevel = 0;
- #endif
- ConfigValueInt(NULL, "rt-prio", &RTPrioLevel);
- if(ConfigValueStr(NULL, "resampler", &str))
- {
- if(strcasecmp(str, "point") == 0 || strcasecmp(str, "none") == 0)
- DefaultResampler = PointResampler;
- else if(strcasecmp(str, "linear") == 0)
- DefaultResampler = LinearResampler;
- else if(strcasecmp(str, "cubic") == 0)
- DefaultResampler = CubicResampler;
- else
- {
- char *end;
- n = strtol(str, &end, 0);
- if(*end == '\0' && (n == PointResampler || n == LinearResampler || n == CubicResampler))
- DefaultResampler = n;
- else
- WARN("Invalid resampler: %s\n", str);
- }
- }
- str = getenv("ALSOFT_TRAP_ERROR");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
- {
- TrapALError = AL_TRUE;
- TrapALCError = AL_TRUE;
- }
- else
- {
- str = getenv("ALSOFT_TRAP_AL_ERROR");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
- TrapALError = AL_TRUE;
- TrapALError = GetConfigValueBool(NULL, "trap-al-error", TrapALError);
- str = getenv("ALSOFT_TRAP_ALC_ERROR");
- if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
- TrapALCError = ALC_TRUE;
- TrapALCError = GetConfigValueBool(NULL, "trap-alc-error", TrapALCError);
- }
- if(ConfigValueFloat("reverb", "boost", &valf))
- ReverbBoost *= powf(10.0f, valf / 20.0f);
- EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE);
- if(((devs=getenv("ALSOFT_DRIVERS")) && devs[0]) ||
- ConfigValueStr(NULL, "drivers", &devs))
- {
- int n;
- size_t len;
- const char *next = devs;
- int endlist, delitem;
- i = 0;
- do {
- devs = next;
- while(isspace(devs[0]))
- devs++;
- next = strchr(devs, ',');
- delitem = (devs[0] == '-');
- if(devs[0] == '-') devs++;
- if(!devs[0] || devs[0] == ',')
- {
- endlist = 0;
- continue;
- }
- endlist = 1;
- len = (next ? ((size_t)(next-devs)) : strlen(devs));
- while(len > 0 && isspace(devs[len-1]))
- len--;
- for(n = i;BackendList[n].name;n++)
- {
- if(len == strlen(BackendList[n].name) &&
- strncmp(BackendList[n].name, devs, len) == 0)
- {
- if(delitem)
- {
- do {
- BackendList[n] = BackendList[n+1];
- ++n;
- } while(BackendList[n].name);
- }
- else
- {
- struct BackendInfo Bkp = BackendList[n];
- while(n > i)
- {
- BackendList[n] = BackendList[n-1];
- --n;
- }
- BackendList[n] = Bkp;
- i++;
- }
- break;
- }
- }
- } while(next++);
- if(endlist)
- {
- BackendList[i].name = NULL;
- BackendList[i].getFactory = NULL;
- BackendList[i].Init = NULL;
- BackendList[i].Deinit = NULL;
- BackendList[i].Probe = NULL;
- }
- }
- for(i = 0;(BackendList[i].Init || BackendList[i].getFactory) && (!PlaybackBackend.name || !CaptureBackend.name);i++)
- {
- if(BackendList[i].getFactory)
- {
- ALCbackendFactory *factory = BackendList[i].getFactory();
- if(!V0(factory,init)())
- {
- WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name);
- continue;
- }
- TRACE("Initialized backend \"%s\"\n", BackendList[i].name);
- if(!PlaybackBackend.name && V(factory,querySupport)(ALCbackend_Playback))
- {
- PlaybackBackend = BackendList[i];
- TRACE("Added \"%s\" for playback\n", PlaybackBackend.name);
- }
- if(!CaptureBackend.name && V(factory,querySupport)(ALCbackend_Capture))
- {
- CaptureBackend = BackendList[i];
- TRACE("Added \"%s\" for capture\n", CaptureBackend.name);
- }
- continue;
- }
- if(!BackendList[i].Init(&BackendList[i].Funcs))
- {
- WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name);
- continue;
- }
- TRACE("Initialized backend \"%s\"\n", BackendList[i].name);
- if(BackendList[i].Funcs.OpenPlayback && !PlaybackBackend.name)
- {
- PlaybackBackend = BackendList[i];
- TRACE("Added \"%s\" for playback\n", PlaybackBackend.name);
- }
- if(BackendList[i].Funcs.OpenCapture && !CaptureBackend.name)
- {
- CaptureBackend = BackendList[i];
- TRACE("Added \"%s\" for capture\n", CaptureBackend.name);
- }
- }
- {
- ALCbackendFactory *factory = ALCloopbackFactory_getFactory();
- V0(factory,init)();
- }
- if(ConfigValueStr(NULL, "excludefx", &str))
- {
- size_t len;
- const char *next = str;
- do {
- str = next;
- next = strchr(str, ',');
- if(!str[0] || next == str)
- continue;
- len = (next ? ((size_t)(next-str)) : strlen(str));
- for(n = 0;EffectList[n].name;n++)
- {
- if(len == strlen(EffectList[n].name) &&
- strncmp(EffectList[n].name, str, len) == 0)
- DisabledEffects[EffectList[n].type] = AL_TRUE;
- }
- } while(next++);
- }
- InitEffectFactoryMap();
- InitEffect(&DefaultEffect);
- str = getenv("ALSOFT_DEFAULT_REVERB");
- if((str && str[0]) || ConfigValueStr(NULL, "default-reverb", &str))
- LoadReverbPreset(str, &DefaultEffect);
- }
- #define DO_INITCONFIG() althread_once(&alc_config_once, alc_initconfig)
- /************************************************
- * Library deinitialization
- ************************************************/
- static void alc_cleanup(void)
- {
- ALCdevice *dev;
- free(alcAllDevicesList); alcAllDevicesList = NULL;
- alcAllDevicesListSize = 0;
- free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
- alcCaptureDeviceListSize = 0;
- free(alcDefaultAllDevicesSpecifier);
- alcDefaultAllDevicesSpecifier = NULL;
- free(alcCaptureDefaultDeviceSpecifier);
- alcCaptureDefaultDeviceSpecifier = NULL;
- if((dev=ExchangePtr((XchgPtr*)&DeviceList, NULL)) != NULL)
- {
- ALCuint num = 0;
- do {
- num++;
- } while((dev=dev->next) != NULL);
- ERR("%u device%s not closed\n", num, (num>1)?"s":"");
- }
- DeinitEffectFactoryMap();
- }
- static void alc_deinit_safe(void)
- {
- alc_cleanup();
- FreeHrtfs();
- FreeALConfig();
- ThunkExit();
- DeleteCriticalSection(&ListLock);
- althread_key_delete(LocalContext);
- if(LogFile != stderr)
- fclose(LogFile);
- LogFile = NULL;
- }
- static void alc_deinit(void)
- {
- int i;
- alc_cleanup();
- memset(&PlaybackBackend, 0, sizeof(PlaybackBackend));
- memset(&CaptureBackend, 0, sizeof(CaptureBackend));
- for(i = 0;BackendList[i].Deinit || BackendList[i].getFactory;i++)
- {
- if(!BackendList[i].getFactory)
- BackendList[i].Deinit();
- else
- {
- ALCbackendFactory *factory = BackendList[i].getFactory();
- V0(factory,deinit)();
- }
- }
- {
- ALCbackendFactory *factory = ALCloopbackFactory_getFactory();
- V0(factory,deinit)();
- }
- alc_deinit_safe();
- }
- /************************************************
- * Device enumeration
- ************************************************/
- static void ProbeList(ALCchar **list, size_t *listsize, enum DevProbe type)
- {
- DO_INITCONFIG();
- LockLists();
- free(*list);
- *list = NULL;
- *listsize = 0;
- if(type == ALL_DEVICE_PROBE && (PlaybackBackend.Probe || PlaybackBackend.getFactory))
- {
- if(!PlaybackBackend.getFactory)
- PlaybackBackend.Probe(type);
- else
- {
- ALCbackendFactory *factory = PlaybackBackend.getFactory();
- V(factory,probe)(type);
- }
- }
- else if(type == CAPTURE_DEVICE_PROBE && (CaptureBackend.Probe || CaptureBackend.getFactory))
- {
- if(!CaptureBackend.getFactory)
- CaptureBackend.Probe(type);
- else
- {
- ALCbackendFactory *factory = CaptureBackend.getFactory();
- V(factory,probe)(type);
- }
- }
- UnlockLists();
- }
- static void ProbeAllDevicesList(void)
- { ProbeList(&alcAllDevicesList, &alcAllDevicesListSize, ALL_DEVICE_PROBE); }
- static void ProbeCaptureDeviceList(void)
- { ProbeList(&alcCaptureDeviceList, &alcCaptureDeviceListSize, CAPTURE_DEVICE_PROBE); }
- static void AppendList(const ALCchar *name, ALCchar **List, size_t *ListSize)
- {
- size_t len = strlen(name);
- void *temp;
- if(len == 0)
- return;
- temp = realloc(*List, (*ListSize) + len + 2);
- if(!temp)
- {
- ERR("Realloc failed to add %s!\n", name);
- return;
- }
- *List = temp;
- memcpy((*List)+(*ListSize), name, len+1);
- *ListSize += len+1;
- (*List)[*ListSize] = 0;
- }
- #define DECL_APPEND_LIST_FUNC(type) \
- void Append##type##List(const ALCchar *name) \
- { AppendList(name, &alc##type##List, &alc##type##ListSize); }
- DECL_APPEND_LIST_FUNC(AllDevices)
- DECL_APPEND_LIST_FUNC(CaptureDevice)
- #undef DECL_APPEND_LIST_FUNC
- /************************************************
- * Device format information
- ************************************************/
- const ALCchar *DevFmtTypeString(enum DevFmtType type)
- {
- switch(type)
- {
- case DevFmtByte: return "Signed Byte";
- case DevFmtUByte: return "Unsigned Byte";
- case DevFmtShort: return "Signed Short";
- case DevFmtUShort: return "Unsigned Short";
- case DevFmtInt: return "Signed Int";
- case DevFmtUInt: return "Unsigned Int";
- case DevFmtFloat: return "Float";
- }
- return "(unknown type)";
- }
- const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans)
- {
- switch(chans)
- {
- case DevFmtMono: return "Mono";
- case DevFmtStereo: return "Stereo";
- case DevFmtQuad: return "Quadraphonic";
- case DevFmtX51: return "5.1 Surround";
- case DevFmtX51Side: return "5.1 Side";
- case DevFmtX61: return "6.1 Surround";
- case DevFmtX71: return "7.1 Surround";
- }
- return "(unknown channels)";
- }
- extern inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type);
- ALuint BytesFromDevFmt(enum DevFmtType type)
- {
- switch(type)
- {
- case DevFmtByte: return sizeof(ALbyte);
- case DevFmtUByte: return sizeof(ALubyte);
- case DevFmtShort: return sizeof(ALshort);
- case DevFmtUShort: return sizeof(ALushort);
- case DevFmtInt: return sizeof(ALint);
- case DevFmtUInt: return sizeof(ALuint);
- case DevFmtFloat: return sizeof(ALfloat);
- }
- return 0;
- }
- ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
- {
- switch(chans)
- {
- case DevFmtMono: return 1;
- case DevFmtStereo: return 2;
- case DevFmtQuad: return 4;
- case DevFmtX51: return 6;
- case DevFmtX51Side: return 6;
- case DevFmtX61: return 7;
- case DevFmtX71: return 8;
- }
- return 0;
- }
- static ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans,
- enum DevFmtType *type)
- {
- static const struct {
- ALenum format;
- enum DevFmtChannels channels;
- enum DevFmtType type;
- } list[] = {
- { AL_FORMAT_MONO8, DevFmtMono, DevFmtUByte },
- { AL_FORMAT_MONO16, DevFmtMono, DevFmtShort },
- { AL_FORMAT_MONO_FLOAT32, DevFmtMono, DevFmtFloat },
- { AL_FORMAT_STEREO8, DevFmtStereo, DevFmtUByte },
- { AL_FORMAT_STEREO16, DevFmtStereo, DevFmtShort },
- { AL_FORMAT_STEREO_FLOAT32, DevFmtStereo, DevFmtFloat },
- { AL_FORMAT_QUAD8, DevFmtQuad, DevFmtUByte },
- { AL_FORMAT_QUAD16, DevFmtQuad, DevFmtShort },
- { AL_FORMAT_QUAD32, DevFmtQuad, DevFmtFloat },
- { AL_FORMAT_51CHN8, DevFmtX51, DevFmtUByte },
- { AL_FORMAT_51CHN16, DevFmtX51, DevFmtShort },
- { AL_FORMAT_51CHN32, DevFmtX51, DevFmtFloat },
- { AL_FORMAT_61CHN8, DevFmtX61, DevFmtUByte },
- { AL_FORMAT_61CHN16, DevFmtX61, DevFmtShort },
- { AL_FORMAT_61CHN32, DevFmtX61, DevFmtFloat },
- { AL_FORMAT_71CHN8, DevFmtX71, DevFmtUByte },
- { AL_FORMAT_71CHN16, DevFmtX71, DevFmtShort },
- { AL_FORMAT_71CHN32, DevFmtX71, DevFmtFloat },
- };
- ALuint i;
- for(i = 0;i < COUNTOF(list);i++)
- {
- if(list[i].format == format)
- {
- *chans = list[i].channels;
- *type = list[i].type;
- return AL_TRUE;
- }
- }
- return AL_FALSE;
- }
- static ALCboolean IsValidALCType(ALCenum type)
- {
- switch(type)
- {
- case ALC_BYTE_SOFT:
- case ALC_UNSIGNED_BYTE_SOFT:
- case ALC_SHORT_SOFT:
- case ALC_UNSIGNED_SHORT_SOFT:
- case ALC_INT_SOFT:
- case ALC_UNSIGNED_INT_SOFT:
- case ALC_FLOAT_SOFT:
- return ALC_TRUE;
- }
- return ALC_FALSE;
- }
- static ALCboolean IsValidALCChannels(ALCenum channels)
- {
- switch(channels)
- {
- case ALC_MONO_SOFT:
- case ALC_STEREO_SOFT:
- case ALC_QUAD_SOFT:
- case ALC_5POINT1_SOFT:
- case ALC_6POINT1_SOFT:
- case ALC_7POINT1_SOFT:
- return ALC_TRUE;
- }
- return ALC_FALSE;
- }
- /************************************************
- * Miscellaneous ALC helpers
- ************************************************/
- extern inline void LockContext(ALCcontext *context);
- extern inline void UnlockContext(ALCcontext *context);
- ALint64 ALCdevice_GetLatencyDefault(ALCdevice *UNUSED(device))
- {
- return 0;
- }
- ALint64 ALCdevice_GetLatency(ALCdevice *device)
- {
- return V0(device->Backend,getLatency)();
- }
- void ALCdevice_Lock(ALCdevice *device)
- {
- V0(device->Backend,lock)();
- }
- void ALCdevice_Unlock(ALCdevice *device)
- {
- V0(device->Backend,unlock)();
- }
- /* SetDefaultWFXChannelOrder
- *
- * Sets the default channel order used by WaveFormatEx.
- */
- void SetDefaultWFXChannelOrder(ALCdevice *device)
- {
- ALuint i;
- for(i = 0;i < MaxChannels;i++)
- device->ChannelOffsets[i] = INVALID_OFFSET;
- switch(device->FmtChans)
- {
- case DevFmtMono: device->ChannelOffsets[FrontCenter] = 0;
- break;
- case DevFmtStereo: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- break;
- case DevFmtQuad: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[BackLeft] = 2;
- device->ChannelOffsets[BackRight] = 3;
- break;
- case DevFmtX51: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[FrontCenter] = 2;
- device->ChannelOffsets[LFE] = 3;
- device->ChannelOffsets[BackLeft] = 4;
- device->ChannelOffsets[BackRight] = 5;
- break;
- case DevFmtX51Side: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[FrontCenter] = 2;
- device->ChannelOffsets[LFE] = 3;
- device->ChannelOffsets[SideLeft] = 4;
- device->ChannelOffsets[SideRight] = 5;
- break;
- case DevFmtX61: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[FrontCenter] = 2;
- device->ChannelOffsets[LFE] = 3;
- device->ChannelOffsets[BackCenter] = 4;
- device->ChannelOffsets[SideLeft] = 5;
- device->ChannelOffsets[SideRight] = 6;
- break;
- case DevFmtX71: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[FrontCenter] = 2;
- device->ChannelOffsets[LFE] = 3;
- device->ChannelOffsets[BackLeft] = 4;
- device->ChannelOffsets[BackRight] = 5;
- device->ChannelOffsets[SideLeft] = 6;
- device->ChannelOffsets[SideRight] = 7;
- break;
- }
- }
- /* SetDefaultChannelOrder
- *
- * Sets the default channel order used by most non-WaveFormatEx-based APIs.
- */
- void SetDefaultChannelOrder(ALCdevice *device)
- {
- ALuint i;
- for(i = 0;i < MaxChannels;i++)
- device->ChannelOffsets[i] = INVALID_OFFSET;
- switch(device->FmtChans)
- {
- case DevFmtX51: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[BackLeft] = 2;
- device->ChannelOffsets[BackRight] = 3;
- device->ChannelOffsets[FrontCenter] = 4;
- device->ChannelOffsets[LFE] = 5;
- return;
- case DevFmtX71: device->ChannelOffsets[FrontLeft] = 0;
- device->ChannelOffsets[FrontRight] = 1;
- device->ChannelOffsets[BackLeft] = 2;
- device->ChannelOffsets[BackRight] = 3;
- device->ChannelOffsets[FrontCenter] = 4;
- device->ChannelOffsets[LFE] = 5;
- device->ChannelOffsets[SideLeft] = 6;
- device->ChannelOffsets[SideRight] = 7;
- return;
- /* Same as WFX order */
- case DevFmtMono:
- case DevFmtStereo:
- case DevFmtQuad:
- case DevFmtX51Side:
- case DevFmtX61:
- break;
- }
- SetDefaultWFXChannelOrder(device);
- }
- /* alcSetError
- *
- * Stores the latest ALC device error
- */
- static void alcSetError(ALCdevice *device, ALCenum errorCode)
- {
- if(TrapALCError)
- {
- #ifdef _WIN32
- /* DebugBreak() will cause an exception if there is no debugger */
- if(IsDebuggerPresent())
- DebugBreak();
- #elif defined(SIGTRAP)
- raise(SIGTRAP);
- #endif
- }
- if(device)
- device->LastError = errorCode;
- else
- LastNullDeviceError = errorCode;
- }
- /* UpdateDeviceParams
- *
- * Updates device parameters according to the attribute list (caller is
- * responsible for holding the list lock).
- */
- static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
- {
- ALCcontext *context;
- enum DevFmtChannels oldChans;
- enum DevFmtType oldType;
- ALCuint oldFreq;
- FPUCtl oldMode;
- ALuint i;
- // Check for attributes
- if(device->Type == Loopback)
- {
- enum {
- GotFreq = 1<<0,
- GotChans = 1<<1,
- GotType = 1<<2,
- GotAll = GotFreq|GotChans|GotType
- };
- ALCuint freq, numMono, numStereo, numSends;
- enum DevFmtChannels schans;
- enum DevFmtType stype;
- ALCuint attrIdx = 0;
- ALCint gotFmt = 0;
- if(!attrList)
- {
- WARN("Missing attributes for loopback device\n");
- return ALC_INVALID_VALUE;
- }
- numMono = device->NumMonoSources;
- numStereo = device->NumStereoSources;
- numSends = device->NumAuxSends;
- schans = device->FmtChans;
- stype = device->FmtType;
- freq = device->Frequency;
- while(attrList[attrIdx])
- {
- if(attrList[attrIdx] == ALC_FORMAT_CHANNELS_SOFT)
- {
- ALCint val = attrList[attrIdx + 1];
- if(!IsValidALCChannels(val) || !ChannelsFromDevFmt(val))
- return ALC_INVALID_VALUE;
- schans = val;
- gotFmt |= GotChans;
- }
- if(attrList[attrIdx] == ALC_FORMAT_TYPE_SOFT)
- {
- ALCint val = attrList[attrIdx + 1];
- if(!IsValidALCType(val) || !BytesFromDevFmt(val))
- return ALC_INVALID_VALUE;
- stype = val;
- gotFmt |= GotType;
- }
- if(attrList[attrIdx] == ALC_FREQUENCY)
- {
- freq = attrList[attrIdx + 1];
- if(freq < MIN_OUTPUT_RATE)
- return ALC_INVALID_VALUE;
- gotFmt |= GotFreq;
- }
- if(attrList[attrIdx] == ALC_STEREO_SOURCES)
- {
- numStereo = attrList[attrIdx + 1];
- if(numStereo > device->MaxNoOfSources)
- numStereo = device->MaxNoOfSources;
- numMono = device->MaxNoOfSources - numStereo;
- }
- if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
- numSends = attrList[attrIdx + 1];
- if(attrList[attrIdx] == ALC_HRTF_SOFT)
- {
- if(attrList[attrIdx + 1] != ALC_FALSE)
- device->Flags |= DEVICE_HRTF_REQUEST;
- else
- device->Flags &= ~DEVICE_HRTF_REQUEST;
- }
- attrIdx += 2;
- }
- if(gotFmt != GotAll)
- {
- WARN("Missing format for loopback device\n");
- return ALC_INVALID_VALUE;
- }
- ConfigValueUInt(NULL, "sends", &numSends);
- numSends = minu(MAX_SENDS, numSends);
- if((device->Flags&DEVICE_RUNNING))
- V0(device->Backend,stop)();
- device->Flags &= ~DEVICE_RUNNING;
- device->Frequency = freq;
- device->FmtChans = schans;
- device->FmtType = stype;
- device->NumMonoSources = numMono;
- device->NumStereoSources = numStereo;
- device->NumAuxSends = numSends;
- }
- else if(attrList && attrList[0])
- {
- ALCuint freq, numMono, numStereo, numSends;
- ALCuint attrIdx = 0;
- /* If a context is already running on the device, stop playback so the
- * device attributes can be updated. */
- if((device->Flags&DEVICE_RUNNING))
- V0(device->Backend,stop)();
- device->Flags &= ~DEVICE_RUNNING;
- freq = device->Frequency;
- numMono = device->NumMonoSources;
- numStereo = device->NumStereoSources;
- numSends = device->NumAuxSends;
- while(attrList[attrIdx])
- {
- if(attrList[attrIdx] == ALC_FREQUENCY)
- {
- freq = attrList[attrIdx + 1];
- device->Flags |= DEVICE_FREQUENCY_REQUEST;
- }
- if(attrList[attrIdx] == ALC_STEREO_SOURCES)
- {
- numStereo = attrList[attrIdx + 1];
- if(numStereo > device->MaxNoOfSources)
- numStereo = device->MaxNoOfSources;
- numMono = device->MaxNoOfSources - numStereo;
- }
- if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
- numSends = attrList[attrIdx + 1];
- if(attrList[attrIdx] == ALC_HRTF_SOFT)
- {
- if(attrList[attrIdx + 1] != ALC_FALSE)
- device->Flags |= DEVICE_HRTF_REQUEST;
- else
- device->Flags &= ~DEVICE_HRTF_REQUEST;
- }
- attrIdx += 2;
- }
- ConfigValueUInt(NULL, "frequency", &freq);
- freq = maxu(freq, MIN_OUTPUT_RATE);
- ConfigValueUInt(NULL, "sends", &numSends);
- numSends = minu(MAX_SENDS, numSends);
- device->UpdateSize = (ALuint64)device->UpdateSize * freq /
- device->Frequency;
- /* SSE and Neon do best with the update size being a multiple of 4 */
- if((CPUCapFlags&(CPU_CAP_SSE|CPU_CAP_NEON)) != 0)
- device->UpdateSize = (device->UpdateSize+3)&~3;
- device->Frequency = freq;
- device->NumMonoSources = numMono;
- device->NumStereoSources = numStereo;
- device->NumAuxSends = numSends;
- }
- if((device->Flags&DEVICE_RUNNING))
- return ALC_NO_ERROR;
- oldFreq = device->Frequency;
- oldChans = device->FmtChans;
- oldType = device->FmtType;
- TRACE("Pre-reset: %s%s, %s%s, %s%uhz, %u update size x%d\n",
- (device->Flags&DEVICE_CHANNELS_REQUEST)?"*":"",
- DevFmtChannelsString(device->FmtChans),
- (device->Flags&DEVICE_SAMPLE_TYPE_REQUEST)?"*":"",
- DevFmtTypeString(device->FmtType),
- (device->Flags&DEVICE_FREQUENCY_REQUEST)?"*":"",
- device->Frequency,
- device->UpdateSize, device->NumUpdates);
- if((device->Flags&DEVICE_HRTF_REQUEST))
- {
- enum DevFmtChannels chans;
- ALCuint freq;
- FindHrtfFormat(device, &chans, &freq);
- device->Frequency = freq;
- device->FmtChans = chans;
- device->Flags |= DEVICE_CHANNELS_REQUEST |
- DEVICE_FREQUENCY_REQUEST;
- }
- if(V0(device->Backend,reset)() == ALC_FALSE)
- return ALC_INVALID_DEVICE;
- if(device->FmtChans != oldChans && (device->Flags&DEVICE_CHANNELS_REQUEST))
- {
- ERR("Failed to set %s, got %s instead\n", DevFmtChannelsString(oldChans),
- DevFmtChannelsString(device->FmtChans));
- device->Flags &= ~DEVICE_CHANNELS_REQUEST;
- }
- if(device->FmtType != oldType && (device->Flags&DEVICE_SAMPLE_TYPE_REQUEST))
- {
- ERR("Failed to set %s, got %s instead\n", DevFmtTypeString(oldType),
- DevFmtTypeString(device->FmtType));
- device->Flags &= ~DEVICE_SAMPLE_TYPE_REQUEST;
- }
- if(device->Frequency != oldFreq && (device->Flags&DEVICE_FREQUENCY_REQUEST))
- {
- ERR("Failed to set %uhz, got %uhz instead\n", oldFreq, device->Frequency);
- device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
- }
- TRACE("Post-reset: %s, %s, %uhz, %u update size x%d\n",
- DevFmtChannelsString(device->FmtChans),
- DevFmtTypeString(device->FmtType), device->Frequency,
- device->UpdateSize, device->NumUpdates);
- aluInitPanning(device);
- for(i = 0;i < MaxChannels;i++)
- {
- device->ClickRemoval[i] = 0.0f;
- device->PendingClicks[i] = 0.0f;
- }
- V(device->Synth,update)(device);
- device->Hrtf = NULL;
- if(device->Type != Loopback && ConfigValueExists(NULL, "hrtf"))
- {
- if(GetConfigValueBool(NULL, "hrtf", AL_FALSE))
- device->Flags |= DEVICE_HRTF_REQUEST;
- else
- device->Flags &= ~DEVICE_HRTF_REQUEST;
- }
- if((device->Flags&DEVICE_HRTF_REQUEST))
- {
- device->Hrtf = GetHrtf(device);
- if(!device->Hrtf)
- device->Flags &= ~DEVICE_HRTF_REQUEST;
- }
- TRACE("HRTF %s\n", device->Hrtf?"enabled":"disabled");
- if(!device->Hrtf && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
- {
- if(!device->Bs2b)
- {
- device->Bs2b = calloc(1, sizeof(*device->Bs2b));
- bs2b_clear(device->Bs2b);
- }
- bs2b_set_srate(device->Bs2b, device->Frequency);
- bs2b_set_level(device->Bs2b, device->Bs2bLevel);
- TRACE("BS2B level %d\n", device->Bs2bLevel);
- }
- else
- {
- free(device->Bs2b);
- device->Bs2b = NULL;
- TRACE("BS2B disabled\n");
- }
- device->Flags &= ~DEVICE_WIDE_STEREO;
- if(device->Type != Loopback && !device->Hrtf && GetConfigValueBool(NULL, "wide-stereo", AL_FALSE))
- device->Flags |= DEVICE_WIDE_STEREO;
- if(!device->Hrtf && (device->UpdateSize&3))
- {
- if((CPUCapFlags&CPU_CAP_SSE))
- WARN("SSE performs best with multiple of 4 update sizes (%u)\n", device->UpdateSize);
- if((CPUCapFlags&CPU_CAP_NEON))
- WARN("NEON performs best with multiple of 4 update sizes (%u)\n", device->UpdateSize);
- }
- SetMixerFPUMode(&oldMode);
- ALCdevice_Lock(device);
- context = device->ContextList;
- while(context)
- {
- ALsizei pos;
- context->UpdateSources = AL_FALSE;
- LockUIntMapRead(&context->EffectSlotMap);
- for(pos = 0;pos < context->EffectSlotMap.size;pos++)
- {
- ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
- if(V(slot->EffectState,deviceUpdate)(device) == AL_FALSE)
- {
- UnlockUIntMapRead(&context->EffectSlotMap);
- ALCdevice_Unlock(device);
- RestoreFPUMode(&oldMode);
- return ALC_INVALID_DEVICE;
- }
- slot->NeedsUpdate = AL_FALSE;
- V(slot->EffectState,update)(device, slot);
- }
- UnlockUIntMapRead(&context->EffectSlotMap);
- LockUIntMapRead(&context->SourceMap);
- for(pos = 0;pos < context->SourceMap.size;pos++)
- {
- ALsource *source = context->SourceMap.array[pos].value;
- ALuint s = device->NumAuxSends;
- while(s < MAX_SENDS)
- {
- if(source->Send[s].Slot)
- DecrementRef(&source->Send[s].Slot->ref);
- source->Send[s].Slot = NULL;
- source->Send[s].Gain = 1.0f;
- source->Send[s].GainHF = 1.0f;
- s++;
- }
- source->NeedsUpdate = AL_FALSE;
- ALsource_Update(source, context);
- }
- UnlockUIntMapRead(&context->SourceMap);
- context = context->next;
- }
- if(device->DefaultSlot)
- {
- ALeffectslot *slot = device->DefaultSlot;
- if(V(slot->EffectState,deviceUpdate)(device) == AL_FALSE)
- {
- ALCdevice_Unlock(device);
- RestoreFPUMode(&oldMode);
- return ALC_INVALID_DEVICE;
- }
- slot->NeedsUpdate = AL_FALSE;
- V(slot->EffectState,update)(device, slot);
- }
- ALCdevice_Unlock(device);
- RestoreFPUMode(&oldMode);
- if(!(device->Flags&DEVICE_PAUSED))
- {
- if(V0(device->Backend,start)() == ALC_FALSE)
- return ALC_INVALID_DEVICE;
- device->Flags |= DEVICE_RUNNING;
- }
- return ALC_NO_ERROR;
- }
- /* FreeDevice
- *
- * Frees the device structure, and destroys any objects the app failed to
- * delete. Called once there's no more references on the device.
- */
- static ALCvoid FreeDevice(ALCdevice *device)
- {
- TRACE("%p\n", device);
- V0(device->Backend,close)();
- DELETE_OBJ(device->Backend);
- device->Backend = NULL;
- DELETE_OBJ(device->Synth);
- device->Synth = NULL;
- if(device->DefaultSlot)
- {
- ALeffectState *state = device->DefaultSlot->EffectState;
- device->DefaultSlot = NULL;
- DELETE_OBJ(state);
- }
- if(device->DefaultSfont)
- ALsoundfont_deleteSoundfont(device->DefaultSfont, device);
- device->DefaultSfont = NULL;
- if(device->BufferMap.size > 0)
- {
- WARN("(%p) Deleting %d Buffer(s)\n", device, device->BufferMap.size);
- ReleaseALBuffers(device);
- }
- ResetUIntMap(&device->BufferMap);
- if(device->EffectMap.size > 0)
- {
- WARN("(%p) Deleting %d Effect(s)\n", device, device->EffectMap.size);
- ReleaseALEffects(device);
- }
- ResetUIntMap(&device->EffectMap);
- if(device->FilterMap.size > 0)
- {
- WARN("(%p) Deleting %d Filter(s)\n", device, device->FilterMap.size);
- ReleaseALFilters(device);
- }
- ResetUIntMap(&device->FilterMap);
- if(device->SfontMap.size > 0)
- {
- WARN("(%p) Deleting %d Soundfont(s)\n", device, device->SfontMap.size);
- ReleaseALSoundfonts(device);
- }
- ResetUIntMap(&device->SfontMap);
- if(device->PresetMap.size > 0)
- {
- WARN("(%p) Deleting %d Preset(s)\n", device, device->PresetMap.size);
- ReleaseALPresets(device);
- }
- ResetUIntMap(&device->PresetMap);
- if(device->FontsoundMap.size > 0)
- {
- WARN("(%p) Deleting %d Fontsound(s)\n", device, device->FontsoundMap.size);
- ReleaseALFontsounds(device);
- }
- ResetUIntMap(&device->FontsoundMap);
- free(device->Bs2b);
- device->Bs2b = NULL;
- free(device->DeviceName);
- device->DeviceName = NULL;
- al_free(device);
- }
- void ALCdevice_IncRef(ALCdevice *device)
- {
- RefCount ref;
- ref = IncrementRef(&device->ref);
- TRACEREF("%p increasing refcount to %u\n", device, ref);
- }
- void ALCdevice_DecRef(ALCdevice *device)
- {
- RefCount ref;
- ref = DecrementRef(&device->ref);
- TRACEREF("%p decreasing refcount to %u\n", device, ref);
- if(ref == 0) FreeDevice(device);
- }
- /* VerifyDevice
- *
- * Checks if the device handle is valid, and increments its ref count if so.
- */
- static ALCdevice *VerifyDevice(ALCdevice *device)
- {
- ALCdevice *tmpDevice;
- if(!device)
- return NULL;
- LockLists();
- tmpDevice = DeviceList;
- while(tmpDevice && tmpDevice != device)
- tmpDevice = tmpDevice->next;
- if(tmpDevice)
- ALCdevice_IncRef(tmpDevice);
- UnlockLists();
- return tmpDevice;
- }
- /* InitContext
- *
- * Initializes context fields
- */
- static ALvoid InitContext(ALCcontext *Context)
- {
- ALint i, j;
- //Initialise listener
- Context->Listener->Gain = 1.0f;
- Context->Listener->MetersPerUnit = 1.0f;
- Context->Listener->Position[0] = 0.0f;
- Context->Listener->Position[1] = 0.0f;
- Context->Listener->Position[2] = 0.0f;
- Context->Listener->Velocity[0] = 0.0f;
- Context->Listener->Velocity[1] = 0.0f;
- Context->Listener->Velocity[2] = 0.0f;
- Context->Listener->Forward[0] = 0.0f;
- Context->Listener->Forward[1] = 0.0f;
- Context->Listener->Forward[2] = -1.0f;
- Context->Listener->Up[0] = 0.0f;
- Context->Listener->Up[1] = 1.0f;
- Context->Listener->Up[2] = 0.0f;
- for(i = 0;i < 4;i++)
- {
- for(j = 0;j < 4;j++)
- Context->Listener->Params.Matrix[i][j] = ((i==j) ? 1.0f : 0.0f);
- }
- for(i = 0;i < 3;i++)
- Context->Listener->Params.Velocity[i] = 0.0f;
- //Validate Context
- Context->LastError = AL_NO_ERROR;
- Context->UpdateSources = AL_FALSE;
- Context->ActiveSourceCount = 0;
- InitUIntMap(&Context->SourceMap, Context->Device->MaxNoOfSources);
- InitUIntMap(&Context->EffectSlotMap, Context->Device->AuxiliaryEffectSlotMax);
- //Set globals
- Context->DistanceModel = DefaultDistanceModel;
- Context->SourceDistanceModel = AL_FALSE;
- Context->DopplerFactor = 1.0f;
- Context->DopplerVelocity = 1.0f;
- Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
- Context->DeferUpdates = AL_FALSE;
- Context->ExtensionList = alExtList;
- }
- /* FreeContext
- *
- * Cleans up the context, and destroys any remaining objects the app failed to
- * delete. Called once there's no more references on the context.
- */
- static ALCvoid FreeContext(ALCcontext *context)
- {
- TRACE("%p\n", context);
- if(context->SourceMap.size > 0)
- {
- WARN("(%p) Deleting %d Source(s)\n", context, context->SourceMap.size);
- ReleaseALSources(context);
- }
- ResetUIntMap(&context->SourceMap);
- if(context->EffectSlotMap.size > 0)
- {
- WARN("(%p) Deleting %d AuxiliaryEffectSlot(s)\n", context, context->EffectSlotMap.size);
- ReleaseALAuxiliaryEffectSlots(context);
- }
- ResetUIntMap(&context->EffectSlotMap);
- context->ActiveSourceCount = 0;
- free(context->ActiveSources);
- context->ActiveSources = NULL;
- context->MaxActiveSources = 0;
- context->ActiveEffectSlotCount = 0;
- free(context->ActiveEffectSlots);
- context->ActiveEffectSlots = NULL;
- context->MaxActiveEffectSlots = 0;
- ALCdevice_DecRef(context->Device);
- context->Device = NULL;
- //Invalidate context
- memset(context, 0, sizeof(ALCcontext));
- free(context);
- }
- /* ReleaseContext
- *
- * Removes the context reference from the given device and removes it from
- * being current on the running thread or globally.
- */
- static void ReleaseContext(ALCcontext *context, ALCdevice *device)
- {
- ALCcontext *volatile*tmp_ctx;
- if(althread_getspecific(LocalContext) == context)
- {
- WARN("%p released while current on thread\n", context);
- althread_setspecific(LocalContext, NULL);
- ALCcontext_DecRef(context);
- }
- if(CompExchangePtr((XchgPtr*)&GlobalContext, context, NULL))
- ALCcontext_DecRef(context);
- ALCdevice_Lock(device);
- tmp_ctx = &device->ContextList;
- while(*tmp_ctx)
- {
- if(CompExchangePtr((XchgPtr*)tmp_ctx, context, context->next))
- break;
- tmp_ctx = &(*tmp_ctx)->next;
- }
- ALCdevice_Unlock(device);
- ALCcontext_DecRef(context);
- }
- void ALCcontext_IncRef(ALCcontext *context)
- {
- RefCount ref;
- ref = IncrementRef(&context->ref);
- TRACEREF("%p increasing refcount to %u\n", context, ref);
- }
- void ALCcontext_DecRef(ALCcontext *context)
- {
- RefCount ref;
- ref = DecrementRef(&context->ref);
- TRACEREF("%p decreasing refcount to %u\n", context, ref);
- if(ref == 0) FreeContext(context);
- }
- static void ReleaseThreadCtx(void *ptr)
- {
- WARN("%p current for thread being destroyed\n", ptr);
- ALCcontext_DecRef(ptr);
- }
- /* VerifyContext
- *
- * Checks that the given context is valid, and increments its reference count.
- */
- static ALCcontext *VerifyContext(ALCcontext *context)
- {
- ALCdevice *dev;
- LockLists();
- dev = DeviceList;
- while(dev)
- {
- ALCcontext *tmp_ctx = dev->ContextList;
- while(tmp_ctx)
- {
- if(tmp_ctx == context)
- {
- ALCcontext_IncRef(tmp_ctx);
- UnlockLists();
- return tmp_ctx;
- }
- tmp_ctx = tmp_ctx->next;
- }
- dev = dev->next;
- }
- UnlockLists();
- return NULL;
- }
- /* GetContextRef
- *
- * Returns the currently active context for this thread, and adds a reference
- * without locking it.
- */
- ALCcontext *GetContextRef(void)
- {
- ALCcontext *context;
- context = althread_getspecific(LocalContext);
- if(context)
- ALCcontext_IncRef(context);
- else
- {
- LockLists();
- context = GlobalContext;
- if(context)
- ALCcontext_IncRef(context);
- UnlockLists();
- }
- return context;
- }
- /************************************************
- * Standard ALC functions
- ************************************************/
- /* alcGetError
- *
- * Return last ALC generated error code for the given device
- */
- ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
- {
- ALCenum errorCode;
- if(VerifyDevice(device))
- {
- errorCode = ExchangeInt(&device->LastError, ALC_NO_ERROR);
- ALCdevice_DecRef(device);
- }
- else
- errorCode = ExchangeInt(&LastNullDeviceError, ALC_NO_ERROR);
- return errorCode;
- }
- /* alcSuspendContext
- *
- * Not functional
- */
- ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *UNUSED(context))
- {
- }
- /* alcProcessContext
- *
- * Not functional
- */
- ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *UNUSED(context))
- {
- }
- /* alcGetString
- *
- * Returns information about the device, and error strings
- */
- ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum param)
- {
- const ALCchar *value = NULL;
- switch(param)
- {
- case ALC_NO_ERROR:
- value = alcNoError;
- break;
- case ALC_INVALID_ENUM:
- value = alcErrInvalidEnum;
- break;
- case ALC_INVALID_VALUE:
- value = alcErrInvalidValue;
- break;
- case ALC_INVALID_DEVICE:
- value = alcErrInvalidDevice;
- break;
- case ALC_INVALID_CONTEXT:
- value = alcErrInvalidContext;
- break;
- case ALC_OUT_OF_MEMORY:
- value = alcErrOutOfMemory;
- break;
- case ALC_DEVICE_SPECIFIER:
- value = alcDefaultName;
- break;
- case ALC_ALL_DEVICES_SPECIFIER:
- if(VerifyDevice(Device))
- {
- value = Device->DeviceName;
- ALCdevice_DecRef(Device);
- }
- else
- {
- ProbeAllDevicesList();
- value = alcAllDevicesList;
- }
- break;
- case ALC_CAPTURE_DEVICE_SPECIFIER:
- if(VerifyDevice(Device))
- {
- value = Device->DeviceName;
- ALCdevice_DecRef(Device);
- }
- else
- {
- ProbeCaptureDeviceList();
- value = alcCaptureDeviceList;
- }
- break;
- /* Default devices are always first in the list */
- case ALC_DEFAULT_DEVICE_SPECIFIER:
- value = alcDefaultName;
- break;
- case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
- if(!alcAllDevicesList)
- ProbeAllDevicesList();
- Device = VerifyDevice(Device);
- free(alcDefaultAllDevicesSpecifier);
- alcDefaultAllDevicesSpecifier = strdup(alcAllDevicesList ?
- alcAllDevicesList : "");
- if(!alcDefaultAllDevicesSpecifier)
- alcSetError(Device, ALC_OUT_OF_MEMORY);
- value = alcDefaultAllDevicesSpecifier;
- if(Device) ALCdevice_DecRef(Device);
- break;
- case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
- if(!alcCaptureDeviceList)
- ProbeCaptureDeviceList();
- Device = VerifyDevice(Device);
- free(alcCaptureDefaultDeviceSpecifier);
- alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
- alcCaptureDeviceList : "");
- if(!alcCaptureDefaultDeviceSpecifier)
- alcSetError(Device, ALC_OUT_OF_MEMORY);
- value = alcCaptureDefaultDeviceSpecifier;
- if(Device) ALCdevice_DecRef(Device);
- break;
- case ALC_EXTENSIONS:
- if(!VerifyDevice(Device))
- value = alcNoDeviceExtList;
- else
- {
- value = alcExtensionList;
- ALCdevice_DecRef(Device);
- }
- break;
- default:
- Device = VerifyDevice(Device);
- alcSetError(Device, ALC_INVALID_ENUM);
- if(Device) ALCdevice_DecRef(Device);
- break;
- }
- return value;
- }
- /* alcGetIntegerv
- *
- * Returns information about the device and the version of OpenAL
- */
- ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
- {
- device = VerifyDevice(device);
- if(size == 0 || data == NULL)
- {
- alcSetError(device, ALC_INVALID_VALUE);
- if(device) ALCdevice_DecRef(device);
- return;
- }
- if(!device)
- {
- switch(param)
- {
- case ALC_MAJOR_VERSION:
- *data = alcMajorVersion;
- break;
- case ALC_MINOR_VERSION:
- *data = alcMinorVersion;
- break;
- case ALC_ATTRIBUTES_SIZE:
- case ALC_ALL_ATTRIBUTES:
- case ALC_FREQUENCY:
- case ALC_REFRESH:
- case ALC_SYNC:
- case ALC_MONO_SOURCES:
- case ALC_STEREO_SOURCES:
- case ALC_CAPTURE_SAMPLES:
- case ALC_FORMAT_CHANNELS_SOFT:
- case ALC_FORMAT_TYPE_SOFT:
- alcSetError(NULL, ALC_INVALID_DEVICE);
- break;
- default:
- alcSetError(NULL, ALC_INVALID_ENUM);
- break;
- }
- }
- else if(device->Type == Capture)
- {
- switch(param)
- {
- case ALC_CAPTURE_SAMPLES:
- ALCdevice_Lock(device);
- *data = V0(device->Backend,availableSamples)();
- ALCdevice_Unlock(device);
- break;
- case ALC_CONNECTED:
- *data = device->Connected;
- break;
- default:
- alcSetError(device, ALC_INVALID_ENUM);
- break;
- }
- }
- else /* render device */
- {
- switch(param)
- {
- case ALC_MAJOR_VERSION:
- *data = alcMajorVersion;
- break;
- case ALC_MINOR_VERSION:
- *data = alcMinorVersion;
- break;
- case ALC_EFX_MAJOR_VERSION:
- *data = alcEFXMajorVersion;
- break;
- case ALC_EFX_MINOR_VERSION:
- *data = alcEFXMinorVersion;
- break;
- case ALC_ATTRIBUTES_SIZE:
- *data = 15;
- break;
- case ALC_ALL_ATTRIBUTES:
- if(size < 15)
- alcSetError(device, ALC_INVALID_VALUE);
- else
- {
- int i = 0;
- data[i++] = ALC_FREQUENCY;
- data[i++] = device->Frequency;
- if(device->Type != Loopback)
- {
- data[i++] = ALC_REFRESH;
- data[i++] = device->Frequency / device->UpdateSize;
- data[i++] = ALC_SYNC;
- data[i++] = ALC_FALSE;
- }
- else
- {
- data[i++] = ALC_FORMAT_CHANNELS_SOFT;
- data[i++] = device->FmtChans;
- data[i++] = ALC_FORMAT_TYPE_SOFT;
- data[i++] = device->FmtType;
- }
- data[i++] = ALC_MONO_SOURCES;
- data[i++] = device->NumMonoSources;
- data[i++] = ALC_STEREO_SOURCES;
- data[i++] = device->NumStereoSources;
- data[i++] = ALC_MAX_AUXILIARY_SENDS;
- data[i++] = device->NumAuxSends;
- data[i++] = ALC_HRTF_SOFT;
- data[i++] = (device->Hrtf ? ALC_TRUE : ALC_FALSE);
- data[i++] = 0;
- }
- break;
- case ALC_FREQUENCY:
- *data = device->Frequency;
- break;
- case ALC_REFRESH:
- if(device->Type == Loopback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- *data = device->Frequency / device->UpdateSize;
- break;
- case ALC_SYNC:
- if(device->Type == Loopback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- *data = ALC_FALSE;
- break;
- case ALC_FORMAT_CHANNELS_SOFT:
- if(device->Type != Loopback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- *data = device->FmtChans;
- break;
- case ALC_FORMAT_TYPE_SOFT:
- if(device->Type != Loopback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- *data = device->FmtType;
- break;
- case ALC_MONO_SOURCES:
- *data = device->NumMonoSources;
- break;
- case ALC_STEREO_SOURCES:
- *data = device->NumStereoSources;
- break;
- case ALC_MAX_AUXILIARY_SENDS:
- *data = device->NumAuxSends;
- break;
- case ALC_CONNECTED:
- *data = device->Connected;
- break;
- case ALC_HRTF_SOFT:
- *data = (device->Hrtf ? ALC_TRUE : ALC_FALSE);
- break;
- default:
- alcSetError(device, ALC_INVALID_ENUM);
- break;
- }
- }
- if(device)
- ALCdevice_DecRef(device);
- }
- /* alcIsExtensionPresent
- *
- * Determines if there is support for a particular extension
- */
- ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
- {
- ALCboolean bResult = ALC_FALSE;
- device = VerifyDevice(device);
- if(!extName)
- alcSetError(device, ALC_INVALID_VALUE);
- else
- {
- size_t len = strlen(extName);
- const char *ptr = (device ? alcExtensionList : alcNoDeviceExtList);
- while(ptr && *ptr)
- {
- if(strncasecmp(ptr, extName, len) == 0 &&
- (ptr[len] == '\0' || isspace(ptr[len])))
- {
- bResult = ALC_TRUE;
- break;
- }
- if((ptr=strchr(ptr, ' ')) != NULL)
- {
- do {
- ++ptr;
- } while(isspace(*ptr));
- }
- }
- }
- if(device)
- ALCdevice_DecRef(device);
- return bResult;
- }
- /* alcGetProcAddress
- *
- * Retrieves the function address for a particular extension function
- */
- ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
- {
- ALCvoid *ptr = NULL;
- if(!funcName)
- {
- device = VerifyDevice(device);
- alcSetError(device, ALC_INVALID_VALUE);
- if(device) ALCdevice_DecRef(device);
- }
- else
- {
- ALsizei i = 0;
- while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName, funcName) != 0)
- i++;
- ptr = alcFunctions[i].address;
- }
- return ptr;
- }
- /* alcGetEnumValue
- *
- * Get the value for a particular ALC enumeration name
- */
- ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
- {
- ALCenum val = 0;
- if(!enumName)
- {
- device = VerifyDevice(device);
- alcSetError(device, ALC_INVALID_VALUE);
- if(device) ALCdevice_DecRef(device);
- }
- else
- {
- ALsizei i = 0;
- while(enumeration[i].enumName && strcmp(enumeration[i].enumName, enumName) != 0)
- i++;
- val = enumeration[i].value;
- }
- return val;
- }
- /* alcCreateContext
- *
- * Create and attach a context to the given device.
- */
- ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
- {
- ALCcontext *ALContext;
- ALCenum err;
- LockLists();
- if(!(device=VerifyDevice(device)) || device->Type == Capture || !device->Connected)
- {
- UnlockLists();
- alcSetError(device, ALC_INVALID_DEVICE);
- if(device) ALCdevice_DecRef(device);
- return NULL;
- }
- device->LastError = ALC_NO_ERROR;
- if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR)
- {
- UnlockLists();
- alcSetError(device, err);
- if(err == ALC_INVALID_DEVICE)
- {
- ALCdevice_Lock(device);
- aluHandleDisconnect(device);
- ALCdevice_Unlock(device);
- }
- ALCdevice_DecRef(device);
- return NULL;
- }
- ALContext = calloc(1, sizeof(ALCcontext)+15+sizeof(ALlistener));
- if(ALContext)
- {
- ALContext->ref = 1;
- ALContext->Listener = (ALlistener*)(((ALintptrEXT)(ALContext+1)+15)&~15);
- ALContext->MaxActiveSources = 256;
- ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) *
- ALContext->MaxActiveSources);
- }
- if(!ALContext || !ALContext->ActiveSources)
- {
- if(!device->ContextList)
- {
- V0(device->Backend,stop)();
- device->Flags &= ~DEVICE_RUNNING;
- }
- UnlockLists();
- free(ALContext);
- ALContext = NULL;
- alcSetError(device, ALC_OUT_OF_MEMORY);
- ALCdevice_DecRef(device);
- return NULL;
- }
- ALContext->Device = device;
- ALCdevice_IncRef(device);
- InitContext(ALContext);
- do {
- ALContext->next = device->ContextList;
- } while(!CompExchangePtr((XchgPtr*)&device->ContextList, ALContext->next, ALContext));
- UnlockLists();
- ALCdevice_DecRef(device);
- TRACE("Created context %p\n", ALContext);
- return ALContext;
- }
- /* alcDestroyContext
- *
- * Remove a context from its device
- */
- ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
- {
- ALCdevice *Device;
- LockLists();
- /* alcGetContextsDevice sets an error for invalid contexts */
- Device = alcGetContextsDevice(context);
- if(Device)
- {
- ReleaseContext(context, Device);
- if(!Device->ContextList)
- {
- V0(Device->Backend,stop)();
- Device->Flags &= ~DEVICE_RUNNING;
- }
- }
- UnlockLists();
- }
- /* alcGetCurrentContext
- *
- * Returns the currently active context on the calling thread
- */
- ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
- {
- ALCcontext *Context;
- Context = althread_getspecific(LocalContext);
- if(!Context) Context = GlobalContext;
- return Context;
- }
- /* alcGetThreadContext
- *
- * Returns the currently active thread-local context
- */
- ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
- {
- ALCcontext *Context;
- Context = althread_getspecific(LocalContext);
- return Context;
- }
- /* alcMakeContextCurrent
- *
- * Makes the given context the active process-wide context, and removes the
- * thread-local context for the calling thread.
- */
- ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
- {
- /* context must be valid or NULL */
- if(context && !(context=VerifyContext(context)))
- {
- alcSetError(NULL, ALC_INVALID_CONTEXT);
- return ALC_FALSE;
- }
- /* context's reference count is already incremented */
- context = ExchangePtr((XchgPtr*)&GlobalContext, context);
- if(context) ALCcontext_DecRef(context);
- if((context=althread_getspecific(LocalContext)) != NULL)
- {
- althread_setspecific(LocalContext, NULL);
- ALCcontext_DecRef(context);
- }
- return ALC_TRUE;
- }
- /* alcSetThreadContext
- *
- * Makes the given context the active context for the current thread
- */
- ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
- {
- ALCcontext *old;
- /* context must be valid or NULL */
- if(context && !(context=VerifyContext(context)))
- {
- alcSetError(NULL, ALC_INVALID_CONTEXT);
- return ALC_FALSE;
- }
- /* context's reference count is already incremented */
- old = althread_getspecific(LocalContext);
- althread_setspecific(LocalContext, context);
- if(old) ALCcontext_DecRef(old);
- return ALC_TRUE;
- }
- /* alcGetContextsDevice
- *
- * Returns the device that a particular context is attached to
- */
- ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *Context)
- {
- ALCdevice *Device;
- if(!(Context=VerifyContext(Context)))
- {
- alcSetError(NULL, ALC_INVALID_CONTEXT);
- return NULL;
- }
- Device = Context->Device;
- ALCcontext_DecRef(Context);
- return Device;
- }
- /* alcOpenDevice
- *
- * Opens the named device.
- */
- ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
- {
- const ALCchar *fmt;
- ALCdevice *device;
- ALCenum err;
- DO_INITCONFIG();
- if(!PlaybackBackend.name)
- {
- alcSetError(NULL, ALC_INVALID_VALUE);
- return NULL;
- }
- if(deviceName && (!deviceName[0] || strcasecmp(deviceName, alcDefaultName) == 0 || strcasecmp(deviceName, "openal-soft") == 0))
- deviceName = NULL;
- device = al_calloc(16, sizeof(ALCdevice)+15+sizeof(ALeffectslot));
- if(!device)
- {
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- //Validate device
- device->ref = 1;
- device->Connected = ALC_TRUE;
- device->Type = Playback;
- device->LastError = ALC_NO_ERROR;
- device->Flags = 0;
- device->Bs2b = NULL;
- device->Bs2bLevel = 0;
- device->DeviceName = NULL;
- device->ContextList = NULL;
- device->MaxNoOfSources = 256;
- device->AuxiliaryEffectSlotMax = 4;
- device->NumAuxSends = MAX_SENDS;
- InitUIntMap(&device->BufferMap, ~0);
- InitUIntMap(&device->EffectMap, ~0);
- InitUIntMap(&device->FilterMap, ~0);
- InitUIntMap(&device->SfontMap, ~0);
- InitUIntMap(&device->PresetMap, ~0);
- InitUIntMap(&device->FontsoundMap, ~0);
- //Set output format
- device->FmtChans = DevFmtChannelsDefault;
- device->FmtType = DevFmtTypeDefault;
- device->Frequency = DEFAULT_OUTPUT_RATE;
- device->NumUpdates = 4;
- device->UpdateSize = 1024;
- if(!PlaybackBackend.getFactory)
- {
- device->Funcs = &PlaybackBackend.Funcs;
- device->Backend = create_backend_wrapper(device, ALCbackend_Playback);
- }
- else
- {
- ALCbackendFactory *factory = PlaybackBackend.getFactory();
- device->Backend = V(factory,createBackend)(device, ALCbackend_Playback);
- }
- if(!device->Backend)
- {
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- if(ConfigValueStr(NULL, "channels", &fmt))
- {
- static const struct {
- const char name[16];
- enum DevFmtChannels chans;
- } chanlist[] = {
- { "mono", DevFmtMono },
- { "stereo", DevFmtStereo },
- { "quad", DevFmtQuad },
- { "surround51", DevFmtX51 },
- { "surround61", DevFmtX61 },
- { "surround71", DevFmtX71 },
- };
- size_t i;
- for(i = 0;i < COUNTOF(chanlist);i++)
- {
- if(strcasecmp(chanlist[i].name, fmt) == 0)
- {
- device->FmtChans = chanlist[i].chans;
- device->Flags |= DEVICE_CHANNELS_REQUEST;
- break;
- }
- }
- if(i == COUNTOF(chanlist))
- ERR("Unsupported channels: %s\n", fmt);
- }
- if(ConfigValueStr(NULL, "sample-type", &fmt))
- {
- static const struct {
- const char name[16];
- enum DevFmtType type;
- } typelist[] = {
- { "int8", DevFmtByte },
- { "uint8", DevFmtUByte },
- { "int16", DevFmtShort },
- { "uint16", DevFmtUShort },
- { "int32", DevFmtInt },
- { "uint32", DevFmtUInt },
- { "float32", DevFmtFloat },
- };
- size_t i;
- for(i = 0;i < COUNTOF(typelist);i++)
- {
- if(strcasecmp(typelist[i].name, fmt) == 0)
- {
- device->FmtType = typelist[i].type;
- device->Flags |= DEVICE_SAMPLE_TYPE_REQUEST;
- break;
- }
- }
- if(i == COUNTOF(typelist))
- ERR("Unsupported sample-type: %s\n", fmt);
- }
- #define DEVICE_FORMAT_REQUEST (DEVICE_CHANNELS_REQUEST|DEVICE_SAMPLE_TYPE_REQUEST)
- if((device->Flags&DEVICE_FORMAT_REQUEST) != DEVICE_FORMAT_REQUEST &&
- ConfigValueStr(NULL, "format", &fmt))
- {
- static const struct {
- const char name[32];
- enum DevFmtChannels channels;
- enum DevFmtType type;
- } formats[] = {
- { "AL_FORMAT_MONO32", DevFmtMono, DevFmtFloat },
- { "AL_FORMAT_STEREO32", DevFmtStereo, DevFmtFloat },
- { "AL_FORMAT_QUAD32", DevFmtQuad, DevFmtFloat },
- { "AL_FORMAT_51CHN32", DevFmtX51, DevFmtFloat },
- { "AL_FORMAT_61CHN32", DevFmtX61, DevFmtFloat },
- { "AL_FORMAT_71CHN32", DevFmtX71, DevFmtFloat },
- { "AL_FORMAT_MONO16", DevFmtMono, DevFmtShort },
- { "AL_FORMAT_STEREO16", DevFmtStereo, DevFmtShort },
- { "AL_FORMAT_QUAD16", DevFmtQuad, DevFmtShort },
- { "AL_FORMAT_51CHN16", DevFmtX51, DevFmtShort },
- { "AL_FORMAT_61CHN16", DevFmtX61, DevFmtShort },
- { "AL_FORMAT_71CHN16", DevFmtX71, DevFmtShort },
- { "AL_FORMAT_MONO8", DevFmtMono, DevFmtByte },
- { "AL_FORMAT_STEREO8", DevFmtStereo, DevFmtByte },
- { "AL_FORMAT_QUAD8", DevFmtQuad, DevFmtByte },
- { "AL_FORMAT_51CHN8", DevFmtX51, DevFmtByte },
- { "AL_FORMAT_61CHN8", DevFmtX61, DevFmtByte },
- { "AL_FORMAT_71CHN8", DevFmtX71, DevFmtByte }
- };
- size_t i;
- ERR("Option 'format' is deprecated, please use 'channels' and 'sample-type'\n");
- for(i = 0;i < COUNTOF(formats);i++)
- {
- if(strcasecmp(fmt, formats[i].name) == 0)
- {
- if(!(device->Flags&DEVICE_CHANNELS_REQUEST))
- device->FmtChans = formats[i].channels;
- if(!(device->Flags&DEVICE_SAMPLE_TYPE_REQUEST))
- device->FmtType = formats[i].type;
- device->Flags |= DEVICE_FORMAT_REQUEST;
- break;
- }
- }
- if(i == COUNTOF(formats))
- ERR("Unsupported format: %s\n", fmt);
- }
- #undef DEVICE_FORMAT_REQUEST
- if(ConfigValueUInt(NULL, "frequency", &device->Frequency))
- {
- device->Flags |= DEVICE_FREQUENCY_REQUEST;
- if(device->Frequency < MIN_OUTPUT_RATE)
- ERR("%uhz request clamped to %uhz minimum\n", device->Frequency, MIN_OUTPUT_RATE);
- device->Frequency = maxu(device->Frequency, MIN_OUTPUT_RATE);
- }
- ConfigValueUInt(NULL, "periods", &device->NumUpdates);
- device->NumUpdates = clampu(device->NumUpdates, 2, 16);
- ConfigValueUInt(NULL, "period_size", &device->UpdateSize);
- device->UpdateSize = clampu(device->UpdateSize, 64, 8192);
- if((CPUCapFlags&CPU_CAP_SSE))
- device->UpdateSize = (device->UpdateSize+3)&~3;
- ConfigValueUInt(NULL, "sources", &device->MaxNoOfSources);
- if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
- ConfigValueUInt(NULL, "slots", &device->AuxiliaryEffectSlotMax);
- if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
- ConfigValueUInt(NULL, "sends", &device->NumAuxSends);
- if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
- ConfigValueInt(NULL, "cf_level", &device->Bs2bLevel);
- device->NumStereoSources = 1;
- device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
- device->Synth = SynthCreate(device);
- if(!device->Synth)
- {
- DELETE_OBJ(device->Backend);
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- // Find a playback device to open
- if((err=V(device->Backend,open)(deviceName)) != ALC_NO_ERROR)
- {
- DELETE_OBJ(device->Synth);
- DELETE_OBJ(device->Backend);
- al_free(device);
- alcSetError(NULL, err);
- return NULL;
- }
- if(DefaultEffect.type != AL_EFFECT_NULL)
- {
- device->DefaultSlot = (ALeffectslot*)(((ALintptrEXT)(device+1)+15)&~15);
- if(InitEffectSlot(device->DefaultSlot) != AL_NO_ERROR)
- {
- device->DefaultSlot = NULL;
- ERR("Failed to initialize the default effect slot\n");
- }
- else if(InitializeEffect(device, device->DefaultSlot, &DefaultEffect) != AL_NO_ERROR)
- {
- ALeffectState *state = device->DefaultSlot->EffectState;
- device->DefaultSlot = NULL;
- DELETE_OBJ(state);
- ERR("Failed to initialize the default effect\n");
- }
- }
- do {
- device->next = DeviceList;
- } while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
- TRACE("Created device %p, \"%s\"\n", device, device->DeviceName);
- return device;
- }
- /* alcCloseDevice
- *
- * Closes the given device.
- */
- ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *Device)
- {
- ALCdevice *volatile*list;
- ALCcontext *ctx;
- LockLists();
- list = &DeviceList;
- while(*list && *list != Device)
- list = &(*list)->next;
- if(!*list || (*list)->Type == Capture)
- {
- alcSetError(*list, ALC_INVALID_DEVICE);
- UnlockLists();
- return ALC_FALSE;
- }
- *list = (*list)->next;
- UnlockLists();
- while((ctx=Device->ContextList) != NULL)
- {
- WARN("Releasing context %p\n", ctx);
- ReleaseContext(ctx, Device);
- }
- if((Device->Flags&DEVICE_RUNNING))
- V0(Device->Backend,stop)();
- Device->Flags &= ~DEVICE_RUNNING;
- ALCdevice_DecRef(Device);
- return ALC_TRUE;
- }
- /************************************************
- * ALC capture functions
- ************************************************/
- ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei samples)
- {
- ALCdevice *device = NULL;
- ALCenum err;
- DO_INITCONFIG();
- if(!CaptureBackend.name)
- {
- alcSetError(NULL, ALC_INVALID_VALUE);
- return NULL;
- }
- if(samples <= 0)
- {
- alcSetError(NULL, ALC_INVALID_VALUE);
- return NULL;
- }
- if(deviceName && (!deviceName[0] || strcasecmp(deviceName, alcDefaultName) == 0 || strcasecmp(deviceName, "openal-soft") == 0))
- deviceName = NULL;
- device = al_calloc(16, sizeof(ALCdevice));
- if(!device)
- {
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- //Validate device
- device->ref = 1;
- device->Connected = ALC_TRUE;
- device->Type = Capture;
- InitUIntMap(&device->BufferMap, ~0);
- InitUIntMap(&device->EffectMap, ~0);
- InitUIntMap(&device->FilterMap, ~0);
- InitUIntMap(&device->SfontMap, ~0);
- InitUIntMap(&device->PresetMap, ~0);
- InitUIntMap(&device->FontsoundMap, ~0);
- device->DeviceName = NULL;
- if(!CaptureBackend.getFactory)
- {
- device->Funcs = &CaptureBackend.Funcs;
- device->Backend = create_backend_wrapper(device, ALCbackend_Capture);
- }
- else
- {
- ALCbackendFactory *factory = CaptureBackend.getFactory();
- device->Backend = V(factory,createBackend)(device, ALCbackend_Capture);
- }
- if(!device->Backend)
- {
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- device->Flags |= DEVICE_FREQUENCY_REQUEST;
- device->Frequency = frequency;
- device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_SAMPLE_TYPE_REQUEST;
- if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
- {
- al_free(device);
- alcSetError(NULL, ALC_INVALID_ENUM);
- return NULL;
- }
- device->UpdateSize = samples;
- device->NumUpdates = 1;
- if((err=V(device->Backend,open)(deviceName)) != ALC_NO_ERROR)
- {
- al_free(device);
- alcSetError(NULL, err);
- return NULL;
- }
- do {
- device->next = DeviceList;
- } while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
- TRACE("Created device %p, \"%s\"\n", device, device->DeviceName);
- return device;
- }
- ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *Device)
- {
- ALCdevice *volatile*list;
- LockLists();
- list = &DeviceList;
- while(*list && *list != Device)
- list = &(*list)->next;
- if(!*list || (*list)->Type != Capture)
- {
- alcSetError(*list, ALC_INVALID_DEVICE);
- UnlockLists();
- return ALC_FALSE;
- }
- *list = (*list)->next;
- UnlockLists();
- ALCdevice_DecRef(Device);
- return ALC_TRUE;
- }
- ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
- {
- if(!(device=VerifyDevice(device)) || device->Type != Capture)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- {
- ALCdevice_Lock(device);
- if(device->Connected)
- {
- if(!(device->Flags&DEVICE_RUNNING))
- V0(device->Backend,start)();
- device->Flags |= DEVICE_RUNNING;
- }
- ALCdevice_Unlock(device);
- }
- if(device) ALCdevice_DecRef(device);
- }
- ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
- {
- if(!(device=VerifyDevice(device)) || device->Type != Capture)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- {
- ALCdevice_Lock(device);
- if((device->Flags&DEVICE_RUNNING))
- V0(device->Backend,stop)();
- device->Flags &= ~DEVICE_RUNNING;
- ALCdevice_Unlock(device);
- }
- if(device) ALCdevice_DecRef(device);
- }
- ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
- {
- if(!(device=VerifyDevice(device)) || device->Type != Capture)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- {
- ALCenum err = ALC_INVALID_VALUE;
- ALCdevice_Lock(device);
- if(samples >= 0 && V0(device->Backend,availableSamples)() >= (ALCuint)samples)
- err = V(device->Backend,captureSamples)(buffer, samples);
- ALCdevice_Unlock(device);
- if(err != ALC_NO_ERROR)
- alcSetError(device, err);
- }
- if(device) ALCdevice_DecRef(device);
- }
- /************************************************
- * ALC loopback functions
- ************************************************/
- /* alcLoopbackOpenDeviceSOFT
- *
- * Open a loopback device, for manual rendering.
- */
- ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceName)
- {
- ALCbackendFactory *factory;
- ALCdevice *device;
- DO_INITCONFIG();
- /* Make sure the device name, if specified, is us. */
- if(deviceName && strcmp(deviceName, alcDefaultName) != 0)
- {
- alcSetError(NULL, ALC_INVALID_VALUE);
- return NULL;
- }
- device = al_calloc(16, sizeof(ALCdevice));
- if(!device)
- {
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- //Validate device
- device->ref = 1;
- device->Connected = ALC_TRUE;
- device->Type = Loopback;
- device->LastError = ALC_NO_ERROR;
- device->Flags = 0;
- device->Bs2b = NULL;
- device->Bs2bLevel = 0;
- device->DeviceName = NULL;
- device->ContextList = NULL;
- device->MaxNoOfSources = 256;
- device->AuxiliaryEffectSlotMax = 4;
- device->NumAuxSends = MAX_SENDS;
- InitUIntMap(&device->BufferMap, ~0);
- InitUIntMap(&device->EffectMap, ~0);
- InitUIntMap(&device->FilterMap, ~0);
- InitUIntMap(&device->SfontMap, ~0);
- InitUIntMap(&device->PresetMap, ~0);
- InitUIntMap(&device->FontsoundMap, ~0);
- factory = ALCloopbackFactory_getFactory();
- device->Backend = V(factory,createBackend)(device, ALCbackend_Loopback);
- if(!device->Backend)
- {
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- //Set output format
- device->NumUpdates = 0;
- device->UpdateSize = 0;
- device->Frequency = DEFAULT_OUTPUT_RATE;
- device->FmtChans = DevFmtChannelsDefault;
- device->FmtType = DevFmtTypeDefault;
- ConfigValueUInt(NULL, "sources", &device->MaxNoOfSources);
- if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
- ConfigValueUInt(NULL, "slots", &device->AuxiliaryEffectSlotMax);
- if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
- ConfigValueUInt(NULL, "sends", &device->NumAuxSends);
- if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
- device->NumStereoSources = 1;
- device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
- device->Synth = SynthCreate(device);
- if(!device->Synth)
- {
- DELETE_OBJ(device->Backend);
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
- // Open the "backend"
- V(device->Backend,open)("Loopback");
- do {
- device->next = DeviceList;
- } while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
- TRACE("Created device %p\n", device);
- return device;
- }
- /* alcIsRenderFormatSupportedSOFT
- *
- * Determines if the loopback device supports the given format for rendering.
- */
- ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type)
- {
- ALCboolean ret = ALC_FALSE;
- if(!(device=VerifyDevice(device)) || device->Type != Loopback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else if(freq <= 0)
- alcSetError(device, ALC_INVALID_VALUE);
- else
- {
- if(IsValidALCType(type) && BytesFromDevFmt(type) > 0 &&
- IsValidALCChannels(channels) && ChannelsFromDevFmt(channels) > 0 &&
- freq >= MIN_OUTPUT_RATE)
- ret = ALC_TRUE;
- }
- if(device) ALCdevice_DecRef(device);
- return ret;
- }
- /* alcRenderSamplesSOFT
- *
- * Renders some samples into a buffer, using the format last set by the
- * attributes given to alcCreateContext.
- */
- FORCE_ALIGN ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
- {
- if(!(device=VerifyDevice(device)) || device->Type != Loopback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else if(samples < 0 || (samples > 0 && buffer == NULL))
- alcSetError(device, ALC_INVALID_VALUE);
- else
- aluMixData(device, buffer, samples);
- if(device) ALCdevice_DecRef(device);
- }
- /************************************************
- * ALC DSP pause/resume functions
- ************************************************/
- /* alcDevicePauseSOFT
- *
- * Pause the DSP to stop audio processing.
- */
- ALC_API void ALC_APIENTRY alcDevicePauseSOFT(ALCdevice *device)
- {
- if(!(device=VerifyDevice(device)) || device->Type != Playback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- {
- LockLists();
- if((device->Flags&DEVICE_RUNNING))
- V0(device->Backend,stop)();
- device->Flags &= ~DEVICE_RUNNING;
- device->Flags |= DEVICE_PAUSED;
- UnlockLists();
- }
- if(device) ALCdevice_DecRef(device);
- }
- /* alcDeviceResumeSOFT
- *
- * Resume the DSP to restart audio processing.
- */
- ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device)
- {
- if(!(device=VerifyDevice(device)) || device->Type != Playback)
- alcSetError(device, ALC_INVALID_DEVICE);
- else
- {
- LockLists();
- if((device->Flags&DEVICE_PAUSED))
- {
- if(V0(device->Backend,start)() != ALC_FALSE)
- {
- device->Flags |= DEVICE_RUNNING;
- device->Flags &= ~DEVICE_PAUSED;
- }
- else
- {
- alcSetError(device, ALC_INVALID_DEVICE);
- ALCdevice_Lock(device);
- aluHandleDisconnect(device);
- ALCdevice_Unlock(device);
- }
- }
- UnlockLists();
- }
- if(device) ALCdevice_DecRef(device);
- }
|