| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program 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 General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /*****************************************************************************
- ** **
- ** Westwood Studios Pacific. **
- ** **
- ** Confidential Information **
- ** Copyright (C) 2000 - All Rights Reserved **
- ** **
- ******************************************************************************
- ** **
- ** Project: Dune Emperor **
- ** **
- ** Module: <module> (<prefix>_) **
- ** **
- ** Version: $ID$ **
- ** **
- ** File name: auddev.cpp **
- ** **
- ** Created by: 11/16/95 - TR **
- ** **
- ** Description: <description> **
- ** **
- *****************************************************************************/
- /*****************************************************************************
- ** Includes **
- *****************************************************************************/
- #include <wpaudio/altypes.h>
- #include <stdio.h>
- #include <string.h>
- #include <wpaudio/memory.h>
- #include <wpaudio/list.h>
- #include <wpaudio/lock.h>
- #include <wpaudio/time.h>
- #include <wpaudio/attributes.h>
- #include <wpaudio/device.h>
- #include <wpaudio/channel.h>
- // 'assignment within condition expression'.
- #pragma warning(disable : 4706)
- DBG_DECLARE_TYPE ( AudioDevice )
- DBG_DECLARE_TYPE ( AudioSystem )
- DBG_DECLARE_TYPE ( AudioSearchStruct )
- DBG_DECLARE_TYPE ( AudioServiceInfoStruct )
- /*****************************************************************************
- ** Externals **
- *****************************************************************************/
- /*****************************************************************************
- ** Defines **
- *****************************************************************************/
- #define AUDIO_DEFAULT_SERVICE_INTERVAL (SECONDS(1)/30)
- #define VOLUME_SLACK (AUDIO_LEVEL_MAX/10)
- /*****************************************************************************
- ** Private Types **
- *****************************************************************************/
- // AudioDataStruct:
- // data that interrupt driven code needs to access is place in the struct
- typedef struct
- {
- ListHead systemList;
- ListHead devList;
- Lock devListAccess;
- AudioAttribs stdChannelAttribs;
- } AudioData;
- typedef struct
- {
- ListNode nd;
- AudioAttribs *attribs;
- DBG_TYPE()
- } AudioAttribsNode;
- DBG_DECLARE_TYPE ( AudioAttribsNode )
- /*****************************************************************************
- ** Private Data **
- *****************************************************************************/
- static AudioData audioDataStruct;
- static AudioData *audioData = &audioDataStruct;
- static int audioExclusiveSystemLoaded = FALSE;
- int audioInitialized = FALSE;
- /*****************************************************************************
- ** Public Data **
- *****************************************************************************/
- AudioAttribs *audioStdChannelAttribs = NULL;
- /*****************************************************************************
- ** Private Prototypes **
- *****************************************************************************/
- static AudioDevice* audioCreateDevice ( AudioSystem *system, int unit, AudioFormat *format );
- static void audioDestroyDevice ( AudioDevice *idev );
- static void audioDeviceAttribsListUpdate ( AudioDevice *idev );
- static void audioDeviceAttribsListUsed ( AudioDevice *idev );
- static AudioAttribsNode* audioDeviceAttribsListFind ( AudioDevice *idev, AudioAttribs * attribs);
- static void audioAddDevice ( AudioDevice *dev );
- static void audioRemoveDevice ( AudioDevice *dev );
- static AudioSystem* audioCreateSystem ( AudioSystemMaster *master );
- static void audioDestroySystem ( AudioSystem *system );
- static void audioAddSystem ( AudioSystem *system );
- static void audioRemoveSystem ( AudioSystem *system );
- static void audioMapDeviceUnit ( int unit, AudioSystem **system, int *systemUnit );
- static AudioDeviceCB audioDeviceHandler;
- /*****************************************************************************
- ** Private Functions **
- *****************************************************************************/
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioDeviceAttribsListUpdate ( AudioDevice *idev )
- {
- AudioAttribsNode *node = ( AudioAttribsNode *) ListFirstItem ( &idev->attribsList );
- while ( node )
- {
- DBG_ASSERT_TYPE ( node, AudioAttribsNode );
- AudioAttribsUpdate ( node->attribs );
- node = (AudioAttribsNode *) ListNodeNext ( &node->nd );
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioDeviceAttribsListUsed ( AudioDevice *idev )
- {
- AudioAttribsNode *node = ( AudioAttribsNode *) ListFirstItem ( &idev->attribsList );
- while ( node )
- {
- DBG_ASSERT_TYPE ( node, AudioAttribsNode );
- AudioAttribsUsed ( node->attribs );
- node = (AudioAttribsNode *) ListNodeNext ( &node->nd );
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static AudioAttribsNode* audioDeviceAttribsListFind ( AudioDevice *idev, AudioAttribs * attribs)
- {
- AudioAttribsNode *node = ( AudioAttribsNode *) ListFirstItem ( &idev->attribsList );
- while ( node )
- {
- DBG_ASSERT_TYPE ( node, AudioAttribsNode );
- if ( node->attribs == attribs )
- {
- return node;
- }
- node = (AudioAttribsNode *) ListNodeNext ( &node->nd );
- }
- return NULL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static AudioDevice* audioCreateDevice ( AudioSystem *system, int unit, AudioFormat *format )
- {
- AudioDevice *dev = NULL;
- AudioSystemMaster *master = system->master;
- // create and initialise dev struct
- ALLOC_STRUCT ( dev, AudioDevice );
- // initialise driver structure
- DBG_SET_TYPE ( dev, AudioDevice );
- ListNodeInit ( &dev->nd );
- dev->systemUnit = unit;
- dev->system = system;
- LockInit ( &dev->lock );
- LockAcquire ( &system->lock ); // mark system as being used
- system->unit[unit] = dev;
- dev->driver = master->driver;
- ListInit ( &dev->channelList);
- ListInit ( &dev->attribsList);
- AudioAttribsInit ( &dev->Attribs );
- LockInit ( &dev->channelAccess );
- dev->deviceHandler = audioDeviceHandler ;
- AudioServiceInfoInit ( & dev->attribsUpdate );
- AudioServiceSetInterval ( &dev->attribsUpdate, AUDIO_DEFAULT_SERVICE_INTERVAL );
- AudioServiceSetMustServiceInterval ( &dev->attribsUpdate, AUDIO_DEFAULT_SERVICE_INTERVAL*5 );
- AudioServiceSetResetInterval ( &dev->attribsUpdate, AUDIO_DEFAULT_SERVICE_INTERVAL*5 );
- AudioServiceInfoInit ( & dev->mixerUpdate );
- AudioServiceSetInterval ( &dev->mixerUpdate, AUDIO_DEFAULT_SERVICE_INTERVAL );
- AudioFormatInit ( &dev->DefaultFormat ); // default sample sormat
- AudioFormatInit ( &dev->Format );
- if ( format )
- {
- AudioDeviceSetDefaultFormat ( dev, format );
- }
- // initialise device driver
- if ( master->open ( dev ) != vNO_ERROR )
- {
- goto error;
- }
- return dev;
- error:
- if (dev)
- {
- audioDestroyDevice ( dev );
- }
- return NULL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioDestroyDevice ( AudioDevice *dev )
- {
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- AudioDeviceAttribsRemoveAll ( dev );
- AudioDeviceDestroyAllChannels ( dev, AUDIO_CHANNEL_TYPE_ALL );
- dev->system->master->close ( dev );
- dev->system->unit[dev->systemUnit] = NULL;
- LockRelease ( &dev->system->lock );
- AudioMemFree ( dev );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioAddDevice ( AudioDevice *dev )
- {
- LockAcquire ( &audioData->devListAccess );
- ListAddToTail ( &audioData->devList, &dev->nd );
- LockRelease ( &audioData->devListAccess );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioRemoveDevice ( AudioDevice *dev )
- {
- LockAcquire ( &audioData->devListAccess );
- ListNodeRemove ( &dev->nd );
- LockRelease ( &audioData->devListAccess );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static AudioSystem* audioCreateSystem ( AudioSystemMaster *master )
- {
- AudioSystem *system = NULL;
- ALLOC_STRUCT ( system, AudioSystem );
- DBG_SET_TYPE ( system, AudioSystem );
- ListNodeInit ( &system->nd );
- LockInit ( &system->lock );
- system->master = master;
- if ( master->load ( system ) != vNO_ERROR )
- {
- goto error;
- }
- return system;
- error:
- if ( system )
- {
- audioDestroySystem ( system );
- }
- return NULL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioDestroySystem ( AudioSystem *system )
- {
- system->master->unload ( system );
- FLAGS_CLEAR (system->master->flags, mAUDIO_SYSTEM_MASTER_LOADED);
- AudioMemFree ( system );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioAddSystem ( AudioSystem *system )
- {
- ListAddToTail ( &audioData->systemList, &system->nd );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioRemoveSystem ( AudioSystem *system )
- {
- ListNodeRemove ( &system->nd );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void audioAddChannel ( AudioDevice *dev, AudioChannel *chan )
- {
- chan->Device = dev;
- dev->channels++;
- LockAcquire ( &dev->channelAccess );
- ListAddToTail ( &dev->channelList, &chan->nd );
- LockRelease ( &dev->channelAccess );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void audioRemoveChannel ( AudioChannel *chan )
- {
- AudioDevice *dev = (AudioDevice *) chan->Device;
- ListNodeRemove ( &chan->nd );
- dev->channels--;
- LockAcquire ( &dev->channelAccess );
- ListNodeRemove ( &chan->nd );
- LockRelease ( &dev->channelAccess );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static void audioMapDeviceUnit ( int unit, AudioSystem **pSystem, int *pUnit )
- {
- AudioSystem *system;
- AudioSearch sh;
- system = AudioFirstSystem ( &sh );
- while ( system )
- {
- if ( unit < system->numUnits )
- {
- break;
- }
- unit -= system->numUnits;
- system = AudioNextSystem ( &sh );
- }
- if ( (*pSystem = system) )
- {
- *pUnit = unit; // we found it
- }
- else
- {
- *pUnit = -1; // no such unit
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- static int audioDeviceHandler ( AudioDevice *dev )
- {
- AudioChannel *chan,
- *next,
- *head;
- int change = FALSE;
- TimeStamp now;
- if (!NotLocked(&dev->channelAccess ))
- {
- // channel lists are being accessed so we can do nothing at this time
- return ERROR_CODE_IN_USE;
- }
- now = AudioGetTime ();
- if ( !AudioServiceNeeded ( &dev->attribsUpdate, now ) )
- {
- return vNO_ERROR;
- }
- AudioServicePerform ( &dev->attribsUpdate, now );
- audioDeviceAttribsListUpdate ( dev );
- AudioAttribsUpdate ( &dev->Attribs );
- if ( !dev->GroupAttribs || !(change = AudioAttribsChanged( dev->GroupAttribs )))
- {
- change = AudioAttribsChanged( &dev->Attribs ) ;
- }
- chan = head = (AudioChannel *) &dev->channelList;
- next = (AudioChannel *) chan->nd.next;
- while ( (chan = next) != head )
- {
- next = (AudioChannel *) chan->nd.next;
- if ( ( chan->Control.Status & mAUDIO_CTRL_PLAYING ))
- {
- // update channel attributes
- if ( chan->sample )
- {
- AudioAttribsUpdate ( &chan->ChannelAttribs );
- if ( change || AudioAttribsChanged (&chan->ChannelAttribs) ||
- (chan->GroupAttribs && AudioAttribsChanged ( chan->GroupAttribs )) ||
- (chan->CompAttribs && AudioAttribsChanged ( chan->CompAttribs )) ||
- (chan->FadeAttribs && AudioAttribsChanged ( chan->FadeAttribs )) ||
- (chan->SfxAttribs && AudioAttribsChanged ( chan->SfxAttribs )) )
- {
- audioChannelRecalcAttribs ( chan );
- chan->driver->update ( chan );
- }
- }
- }
- }
- AudioAttribsUsed ( &dev->Attribs );
- audioDeviceAttribsListUsed ( dev );
- return vNO_ERROR;
- }
- /*****************************************************************************
- ** Public Functions **
- *****************************************************************************/
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioSetUp ( void )
- {
- DBG_ASSERT ( !audioInitialized ); // audio system was already initialized
- DBGPRINTF (("Initializing audio module\n"));
- DBG_ASSERT ( audioData != NULL );
- InitAudioTimer();
- // Initialize lists
- ListInit ( &audioData->systemList );
- ListInit ( &audioData->devList );
- LockInit ( &audioData->devListAccess );
- audioStdChannelAttribs = &audioData->stdChannelAttribs;
- AudioAttribsInit ( audioStdChannelAttribs );
- // Process tags
- audioInitialized = TRUE;
- return vNO_ERROR;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioCloseDown ( void)
- {
- if (!audioInitialized)
- {
- return;
- }
- AudioDestroyAllDevices ();
- AudioUnloadAllSystems ();
- DBGPRINTF (("WPAudio system has been shut down\n"));
- audioInitialized = FALSE;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServiceAllDevices ( void )
- {
- AudioDevice *dev,*head;
- AudioData *data = audioData;
- if ( !audioInitialized || !NotLocked ( &data->devListAccess ))
- {
- return;
- }
- dev = head = (AudioDevice *) &data->devList;
- while ( (dev = (AudioDevice *) dev->nd.next) != head )
- {
- DBG_ASSERT ( dev->deviceHandler != NULL );
- if ( !(dev->flags & mAUDIO_DEV_DONT_SERVICE ))
- {
- dev->deviceHandler ( dev );
- }
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioSystem* AudioLoadSystem ( AudioSystemMaster *master )
- {
- AudioSystem *system;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT ( master != NULL );
- DBG_ASSERT ( master->stamp == AUDIO_STAMP_SYSTEM_MASTER );
- DBG_ASSERT ( ! (master->flags & mAUDIO_SYSTEM_MASTER_LOADED )); // master was already loaded
- DBG_ASSERT ( !audioExclusiveSystemLoaded);
- DBGPRINTF (("Loading driver system for %s\n", master->Name));
- if ( ! (system = audioCreateSystem ( master )))
- {
- goto error;
- }
- master->flags |= mAUDIO_SYSTEM_MASTER_LOADED;
- audioAddSystem ( system );
- if ( master->Properties & mAUDIO_SYS_PROP_EXCLUSIVE )
- {
- audioExclusiveSystemLoaded = TRUE;
- }
- return system;
- error:
- if ( system)
- {
- audioDestroySystem ( system );
- }
- return NULL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioUnloadSystem ( AudioSystem *system )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( system, AudioSystem );
- DBG_ASSERT ( !Locked ( &system->lock )); // trying to unload a system while it is still being used
- audioRemoveSystem ( system );
- audioDestroySystem ( system );
- audioExclusiveSystemLoaded = FALSE;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioUnloadAllSystems ( void )
- {
- AudioSystem *sys,*next;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- sys = AudioFirstSystem ( &sh );
- while (sys)
- {
- next = AudioNextSystem( &sh );
- AudioUnloadSystem ( sys );
- sys = next;
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioSystem* AudioFirstSystem ( AudioSearch *sh )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_SET_TYPE ( sh, AudioSearchStruct );
- sh->item = ListFirstItem ( &audioData->systemList );
- DBG_CODE
- (
- if ( sh->item )
- {
- DBG_ASSERT_TYPE ( (AudioSystem *) sh->item, AudioSystem );
- }
- )
- return (AudioSystem *) sh->item;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioSystem* AudioNextSystem ( AudioSearch *sh )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( sh, AudioSearchStruct );
- if ( sh->item )
- {
- sh->item = ListNextItem ( (ListNode*) sh->item );
- }
- DBG_CODE
- (
- if ( sh->item )
- {
- DBG_ASSERT_TYPE ( (AudioSystem *) sh->item, AudioSystem );
- }
- )
- return (AudioSystem *) sh->item;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioNumberOfDevices ( void )
- {
- int devices = 0;
- AudioSystem *system;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- system = AudioFirstSystem ( &sh );
- while ( system )
- {
- devices += system->numUnits;
- system = AudioNextSystem ( &sh );
- }
- return devices;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioDevice* AudioOpenDevice ( int unit, AudioFormat *format )
- {
- AudioDevice *dev = NULL;
- AudioSystem *system;
- int systemUnit;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- if ( unit == AUDIO_DEVICE_DEFAULT )
- {
- unit = 0;
- }
- // map unit number to system and system unit number
- audioMapDeviceUnit ( unit, &system, &systemUnit );
- if ( !system ) // there is no such unit
- {
- DBGPRINTF (("No such unit\n"));
- goto error;
- }
- if ( !( dev = system->unit[systemUnit]))
- {
- // first time opening this device
- if ( ! (dev = audioCreateDevice ( system, systemUnit, format )))
- {
- DBGPRINTF (("Unable to create device\n"));
- goto error; // failed to open the device driver
- }
- dev->Unit = unit;
- audioAddDevice ( dev ); // add it to the device list
- }
- LockAcquire (&dev->lock); // mark as being used
- return dev;
- error:
- if ( dev )
- {
- AudioDeviceClose ( dev );
- }
- return NULL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceSetDefaultFormat ( AudioDevice *dev, AudioFormat *format )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- DBG_ASSERT ( format != NULL );
- memcpy ( &dev->DefaultFormat, format, sizeof ( AudioFormat ) );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioDevice* AudioFirstDevice ( AudioSearch *sh )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_SET_TYPE ( sh, AudioSearchStruct );
- sh->item = ListFirstItem ( &audioData->devList );
- DBG_CODE
- (
- if ( sh->item )
- {
- DBG_ASSERT_TYPE ( (AudioDevice *) sh->item, AudioDevice );
- }
- )
- return (AudioDevice *) sh->item;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioDevice* AudioNextDevice ( AudioSearch *sh )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( sh, AudioSearchStruct );
- if ( sh->item )
- {
- sh->item = ListNextItem ( (ListNode*) sh->item );
- }
- DBG_CODE
- (
- if ( sh->item )
- {
- DBG_ASSERT_TYPE ( (AudioDevice *) sh->item, AudioDevice );
- }
- )
- return (AudioDevice *) sh->item;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDestroyAllDevices ( void )
- {
- AudioDevice *dev,*next;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- LockAcquire ( &audioData->devListAccess);
- dev = AudioFirstDevice ( &sh );
- while (dev)
- {
- next = AudioNextDevice( &sh );
- AudioDeviceDestroy ( dev );
- dev = next;
- }
- LockRelease ( &audioData->devListAccess);
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceClose ( AudioDevice *dev )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- LockRelease ( &dev->lock );
- if ( !Locked ( &dev->lock ))
- {
- AudioDeviceDestroy ( dev );
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceDestroy ( AudioDevice *dev )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- audioRemoveDevice ( dev );
- audioDestroyDevice ( dev );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioDeviceSetFormat ( AudioDevice *dev, AudioFormat *format)
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- DBG_ASSERT ( format );
- return ERROR_CODE_FAIL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceSetVolume ( AudioDevice *dev, int newVolume )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- AudioAttribsSetVolume ( &dev->Attribs, newVolume );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceAdjustVolume ( AudioDevice *dev, int newVolume )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- AudioAttribsAdjustVolume ( &dev->Attribs, newVolume );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioDeviceMaxChannels ( AudioDevice *dev )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- return dev->maxChannels;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioDeviceChannels ( AudioDevice *dev )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- return dev->channels;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioChannel* AudioDeviceCreateChannel ( AudioDevice *dev )
- {
- AudioChannel *channel = NULL;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- if ( dev->channels >= dev->maxChannels )
- {
- DBGPRINTF (("Maximum of %d channels already open\n", dev->maxChannels));
- goto error;
- }
- if ( !( channel = audioChannelCreate ( dev )) )
- {
- goto error;
- }
- audioAddChannel ( dev, channel );
- return channel;
- error:
- if ( channel )
- {
- audioChannelDestroy ( channel );
- }
- return NULL;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioDeviceCreateChannels ( AudioDevice *dev, int num )
- {
- int count = 0;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- DBG_ASSERT ( num != 0);
- do
- {
- if ( !AudioDeviceCreateChannel ( dev ))
- {
- break;
- }
- count ++;
- } while (--num);
- return count;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioChannel* AudioDeviceFirstChannel ( AudioDevice *dev, AudioSearch *sh )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- DBG_ASSERT ( sh != NULL );
- DBG_SET_TYPE ( sh, AudioSearchStruct );
- sh->item = ListFirstItem ( &dev->channelList );
- if ( sh->item )
- {
- DBG_ASSERT_TYPE ( (AudioChannel *) sh->item, AudioChannel );
- }
- return (AudioChannel *) sh->item;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioChannel* AudioDeviceNextChannel ( AudioSearch *sh )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( sh, AudioSearchStruct );
- if ( sh->item )
- {
- sh->item = ListNextItem ( (ListNode *) sh->item );
- }
- if ( sh->item )
- {
- DBG_ASSERT_TYPE ( (AudioChannel *) sh->item, AudioChannel );
- }
- return (AudioChannel *) sh->item;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioChannel* AudioDeviceGetChannel ( AudioDevice *dev, AudioChannelType type )
- {
- AudioChannel *channel;
- AudioSearch sh;
- int lowestPriorityPlaying,
- lowestPriorityPaused;
- AudioChannel *lowestPlaying,
- *lowestPaused;
- uint lowestPlayingVolume;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- if ( type == AUDIO_CHANNEL_TYPE_ANY)
- {
- // you must know what type of channel you want so AUDIO_CHANNEL_ANY is taken
- // to mean a standard channel
- type = AUDIO_CHANNEL_TYPE_STD;
- }
- // search through the channel list.
- // First try to get a non active channel
- // Then settle on getting the lowest priority paused channel.
- // Then settle on getting the lowest priority playing channel.
- // ...and among the channels with lowest priority, get the one
- // with lowest volume.
- lowestPriorityPlaying = AUD_HIGHEST_PRIORITY;
- lowestPriorityPaused = AUD_HIGHEST_PRIORITY;
- lowestPlaying = NULL;
- lowestPaused = NULL;
- lowestPlayingVolume = 0xFFFFFFFF;
- channel = AudioDeviceFirstChannel ( dev, &sh );
- while ( channel )
- {
- if ( channel->Type == type )
- {
- if ( !(FLAGS_CHECK (channel->Control.Status, mAUDIO_CTRL_ACTIVE | mAUDIO_CTRL_INUSE )))
- {
- break; // we found a free channel
- }
- if ( (FLAGS_CHECK (channel->Control.Status, mAUDIO_CTRL_PLAYING )))
- {
- if ( channel->Control.Priority < lowestPriorityPlaying )
- {
- lowestPriorityPlaying = channel->Control.Priority;
- lowestPlaying = channel;
- lowestPlayingVolume = channel->attribs.VolumeLevel.level;
- }
- else if ( channel->Control.Priority == lowestPriorityPlaying )
- {
- // If priorities are equal, choose the channel whose volume
- // is lowest -- but only award lowest status if this one is
- // quieter than the previous best by a significant amount.
- if ( channel->attribs.VolumeLevel.level < lowestPlayingVolume
- && ( lowestPlayingVolume - channel->attribs.VolumeLevel.level >= VOLUME_SLACK ) )
- {
- lowestPriorityPlaying = channel->Control.Priority;
- lowestPlaying = channel;
- lowestPlayingVolume = channel->attribs.VolumeLevel.level;
- }
- }
- }
- else
- {
- if ( channel->Control.Priority < lowestPriorityPaused )
- {
- lowestPriorityPaused = channel->Control.Priority;
- lowestPaused = channel;
- }
- }
- }
- channel = AudioDeviceNextChannel ( &sh );
- }
- if ( !channel ) // we did not find a free channel
- {
- if ( !( channel = lowestPaused) || (lowestPriorityPaused > lowestPriorityPlaying) )
- {
- // we did not find a paused channel of lower priority
- channel = lowestPlaying;
- }
- }
- return channel;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- AudioChannel* AudioDeviceReserveChannel ( AudioDevice *dev, AudioChannelType newType )
- {
- AudioChannel *chan;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- DBG_ASSERT ( newType != AUDIO_CHANNEL_TYPE_ALL ); // this does not make sense, think about it
- DBG_ASSERT ( newType != AUDIO_CHANNEL_TYPE_STD ); // illegal value
- chan = AudioDeviceGetChannel ( dev, AUDIO_CHANNEL_TYPE_STD );
- if ( chan )
- {
- AudioChannelReserve ( chan, newType );
- }
- return chan;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioDeviceDestroyAllChannels ( AudioDevice *dev, AudioChannelType type )
- {
- AudioChannel *channel,*next;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- channel = AudioDeviceFirstChannel ( dev, &sh );
- while (channel)
- {
- next = AudioDeviceNextChannel( &sh );
- if ( type == AUDIO_CHANNEL_TYPE_ALL || channel->Type == type )
- {
- AudioChannelDestroy ( channel );
- }
- channel = next;
- }
- return vNO_ERROR;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceStopAllChannels ( AudioDevice *dev, AudioChannelType type)
- {
- AudioChannel *channel,*next;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- channel = AudioDeviceFirstChannel ( dev, &sh );
- while (channel)
- {
- next = AudioDeviceNextChannel( &sh );
- if ( type == AUDIO_CHANNEL_TYPE_ALL || channel->Type == type )
- {
- AudioChannelStop ( channel );
- }
- channel = next;
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDevicePauseAllChannels ( AudioDevice *dev, AudioChannelType type )
- {
- AudioChannel *channel;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- channel = AudioDeviceFirstChannel ( dev, &sh );
- while (channel)
- {
- if ( FLAGS_CHECK ( channel->Control.Status, mAUDIO_CTRL_PLAYING ) )
- {
- if ( type == AUDIO_CHANNEL_TYPE_ALL || channel->Type == type )
- {
- AudioChannelPause ( channel );
- }
- }
- channel = AudioDeviceNextChannel( &sh );
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceResumeAllChannels ( AudioDevice *dev, AudioChannelType type )
- {
- AudioChannel *channel;
- AudioSearch sh;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- channel = AudioDeviceFirstChannel ( dev, &sh );
- while (channel)
- {
- if ( FLAGS_CHECK ( channel->Control.Status, mAUDIO_CTRL_PAUSED ) )
- {
- if ( type == AUDIO_CHANNEL_TYPE_ALL || channel->Type == type )
- {
- AudioChannelResume ( channel );
- }
- }
- channel = AudioDeviceNextChannel( &sh );
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioDeviceService ( AudioDevice *dev)
- {
- int result;
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- result = dev->deviceHandler ( dev );
- return result;
- }
- void AudioDeviceAttribsAdd ( AudioDevice *dev, AudioAttribs *attribs )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- if ( !attribs )
- {
- return;
- }
- if ( audioDeviceAttribsListFind ( dev, attribs ))
- {
- return;
- }
- AudioAttribsNode *node;
- ALLOC_STRUCT ( node, AudioAttribsNode );
- DBG_SET_TYPE ( node, AudioAttribsNode );
- ListNodeInit ( &node->nd );
- node->attribs = attribs;
- LockAcquire ( &dev->channelAccess );
- ListAddToTail ( &dev->attribsList, &node->nd );
- LockRelease ( &dev->channelAccess );
- }
- void AudioDeviceAttribsRemove ( AudioDevice *dev, AudioAttribs *attribs )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- AudioAttribsNode *node = audioDeviceAttribsListFind ( dev, attribs );
- if ( node )
- {
- DBG_ASSERT_TYPE ( node, AudioAttribsNode );
- LockAcquire ( &dev->channelAccess );
- ListNodeRemove ( &node->nd );
- LockRelease ( &dev->channelAccess );
- DBG_INVALIDATE_TYPE ( node );
- AudioMemFree ( node );
- }
- }
- void AudioDeviceAttribsRemoveAll ( AudioDevice *dev )
- {
- DBG_ASSERT ( audioInitialized ); // AudioSetUp() was not called
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- AudioAttribsNode *node;
- while ( (node = (AudioAttribsNode *) ListFirstItem ( &dev->attribsList )) )
- {
- DBG_ASSERT_TYPE ( node, AudioAttribsNode );
- ListNodeRemove ( &node->nd );
- DBG_INVALIDATE_TYPE ( node );
- AudioMemFree ( node );
- }
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServiceInfoInit ( AudioServiceInfo *asi )
- {
- DBG_ASSERT_PTR ( asi );
- DBG_SET_TYPE ( asi, AudioServiceInfoStruct );
- asi->serviceInterval = 0;
- asi->mustServiceInterval = 0;
- asi->lastInterval = 0;
- asi->longestInterval = 0;
- asi->lastServiceTime = 0;
- asi->count = 0;
- asi->lastcount = 0;
- asi->periodInterval = SECONDS(5);
- asi->longestIntervalforPeriod = 0;
- asi->periodStart = 0;
- asi->animPos = 0;
- asi->missCount = 0;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServiceSetInterval ( AudioServiceInfo *asi, TimeStamp interval )
- {
- DBG_ASSERT_TYPE ( asi, AudioServiceInfoStruct );
- asi->serviceInterval = interval;
- asi->mustServiceInterval = interval;
- asi->longestReset = asi->serviceInterval*10;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServiceSetMustServiceInterval ( AudioServiceInfo *asi, TimeStamp interval )
- {
- DBG_ASSERT_TYPE ( asi, AudioServiceInfoStruct );
- asi->mustServiceInterval = interval;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServiceSetResetInterval ( AudioServiceInfo *asi, TimeStamp interval )
- {
- DBG_ASSERT_TYPE ( asi, AudioServiceInfoStruct );
- asi->longestReset = interval;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- int AudioServiceNeeded ( AudioServiceInfo *asi, TimeStamp now )
- {
- TimeStamp interval;
- DBG_ASSERT_TYPE ( asi, AudioServiceInfoStruct );
- interval = now - asi->lastServiceTime;
- if ( interval < asi->serviceInterval )
- {
- return FALSE;
- }
- return TRUE;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServicePerform ( AudioServiceInfo *asi, TimeStamp now )
- {
- TimeStamp interval;
- DBG_ASSERT_TYPE ( asi, AudioServiceInfoStruct );
- interval = now - asi->lastServiceTime;
- asi->lastInterval = interval;
- asi->count++;
- if ( asi->longestInterval > asi->longestReset )
- {
- asi->longestInterval = 0; // reset the longest count if it is extremely long
- }
- if ( interval > asi->longestInterval )
- {
- asi->longestInterval = interval;
- }
- if ( interval > asi->mustServiceInterval )
- {
- asi->missCount++;
- }
- if ( interval > asi->longestIntervalforPeriod )
- {
- asi->longestIntervalforPeriod = interval;
- }
- asi->lastServiceTime = now;
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioServiceInfoDump ( AudioServiceInfo *asi, char *string )
- {
- static char *anim = "|/-\\";
- TimeStamp now = AudioGetTime();
- if ( asi->count != asi->lastcount )
- {
- asi->animPos++;
- if ( asi->animPos >= strlen (anim ))
- {
- asi->animPos = 0;
- }
- asi->lastcount = asi->count;
- }
- if ( asi->periodStart + asi->periodInterval < now )
- {
- asi->longestIntervalforPeriod = asi->serviceInterval;
- asi->periodStart = now;
- }
- sprintf ( string, "%05dms (%04d,%04d,%04d,~%2d) %c \n",
- (int) asi->serviceInterval,
- (int) asi->lastInterval,
- (int) asi->longestIntervalforPeriod,
- (int) asi->longestInterval,
- (int) asi->missCount,
- anim[asi->animPos] );
- }
- /******************************************************************/
- /* */
- /* */
- /******************************************************************/
- void AudioDeviceDump ( AudioDevice *dev, void (*print) ( char *), int names )
- {
- char string[200];
- char temp[100];
- AudioChannel *chan;
- AudioSearch sh;
- char *state;
- char *type;
- int count;
- DBG_ASSERT_TYPE ( dev, AudioDevice );
- print ( "Audio Device Dump ---------------------\n");
- sprintf ( string, "%s (%d)\n",
- dev->system->master->Name,
- dev->Unit);
- print ( string );
- AudioServiceInfoDump ( &dev->mixerUpdate, temp );
- sprintf ( string, "mixer:%s", temp );
- print ( string );
- AudioServiceInfoDump ( &dev->attribsUpdate, temp );
- sprintf ( string, "level:%s", temp );
- print ( string );
- sprintf (string, "Frames: %d Oversamp: %d Lag: %d\n", dev->frames, dev->over_sample, dev->frame_lag );
- print ( string );
- if ( names )
- {
- sprintf ( string, "Chan:TYPE: STATE : FORMAT :PRI :VOL: NAME\n");
- }
- else
- {
- sprintf ( string, "Chan:TYPE: STATE : FORMAT :PRI :VOL:\n");
- }
- print ( string );
- chan = AudioDeviceFirstChannel ( dev, &sh );
- count = 0;
- while (chan)
- {
- if ( FLAGS_CHECK ( chan->Control.Status, mAUDIO_CTRL_PLAYING) )
- {
- state = "PLAYING";
- }
- else if ( FLAGS_CHECK ( chan->Control.Status, mAUDIO_CTRL_PAUSED))
- {
- state = "PAUSED ";
- }
- else
- {
- state = "FREE ";
- }
- if ( chan->Type >= AUDIO_CHANNEL_TYPE_USER )
- {
- type = "USER";
- }
- else if ( chan->Type == AUDIO_CHANNEL_TYPE_STD )
- {
- type = "STD ";
- }
- else
- {
- type = "??? ";
- }
- AudioFormat *format;
- char fstr[200];
- char name[200];
- name[0] = 0;
- if ( names )
- {
- #ifndef IG_FINAL_RELEASE
- strcpy ( name, chan->sample_name );
- #endif
- }
- format = &chan->current_format;
- char temp[3];
- if ( format->Compression == AUDIO_COMPRESS_MP3 )
- {
- strcpy ( temp, "mp" );
- }
- else
- {
- sprintf ( temp, "%2d", format->Compression == AUDIO_COMPRESS_NONE ? format->SampleWidth *8 : 4 );
- }
- sprintf ( fstr, "%02d-%s-%c%c%c",
- format->Rate / 1000,
- temp,
- format->Channels == 1 ? 'm' : 's',
- chan->format_changed ? '*' : ' ',
- chan->drv_format_changed ? '+' : ' ' );
- //sprintf ( string, "Chan:TYPE: STATE : FORMAT :PRI :VOL:\n");
- sprintf ( string, "#%2d :%s:%s:%s:%4d:%3d:%.31s\n",
- count,
- type,
- state,
- fstr,
- chan->Control.Priority,
- AudioLevelApply ( &chan->attribs.VolumeLevel, 100 ),
- name);
- print ( string );
- count++;
- chan = AudioDeviceNextChannel( &sh );
- }
- print ( "--------------------------------------\n");
- }
|