/* ===================  Acoustetron General Header  =================== */
/* ===            Copyright (c) 1991-2000  by AuSIM, Inc.           === */
/* ===                     All rights reserved.                     === */
/* ==================================================================== */

/* ==+--------------------------------------------------------------+== */
/* ==| This header contains enumerations, definitions, and macros   |== */
/* ==| that are common to all CRE 3D audio software products.  It   |== */
/* ==| is included by the BTRON.H, CTRON.H, and CRE_TRON.H library  |== */
/* ==| header files which contain mutually independent information. |== */
/* ==+--------------------------------------------------------------+== */

#ifndef ATRON_H
 #define ATRON_H

 #define ATRON_VERSION  1.310f     /* CRE client/server protocol */
 /* new for 1.300 = event handling, backwards compatible */

/* ==  ATRON driver ID's:                                            == */
/* ==  These integers are registered and embedded in the respective  == */
/* ==  DSP binaries to ensure driver compatibility.  The CRE_TRON    == */
/* ==  functions cre_init() and cre_close() use these enumerations   == */
/* ==  to initialize or terminate a selected driver.                 == */
/* ==  ---  Enumerated in chronological order ... DO NOT DISRUPT     == */
enum ATRNdriver {
     Atrn_CLOS,     /* special close all drivers indicator           */
     Atrn_ARS1,     /* Acoustic Room Simulator release 1, outdated.  */
     Atrn_DPL1,     /* Doppler Processor 1, 1 source per Spectrum.   */
     Atrn_CMP1,     /* Convolvotron Minimum Phase release 1.         */
     Atrn_BMP1,     /* Alpha/Beachtron Minimum Phase release 1.      */
     Atrn_BMP2,     /* Alpha/Beachtron Minimum Phase 22kHz.          */
     Atrn_BMP3,     /* Alpha/Beachtron Minimum Phase Doppler.        */
     Atrn_BMP4,     /* Alpha/Beachtron Transmission Loss Filter.     */
     Atrn_ARS2,     /* Acoustic Room Simulator release 2.            */
     Atrn_SAB1,     /* Replaced with Atron_HOLD below                */
     Atrn_SAD1,     /* Replaced with Atron_RESET below               */
     Atrn_ARS3,     /* Acoustic Room Simulator release 3 (July 1995) */
     Atrn_ASM1,     /* for AuSIM Engineering server auto sample rate */
     Atrn_AS48,     /* for AuSIM Engineering server 48kHz driver     */
     Atrn_AS88,     /* for AuSIM Engineering server 88kHz driver     */
     Atrn_AS96,     /* for AuSIM Engineering server 96kHz driver     */
     Atrn_AS44,     /* for AuSIM Engineering server 44kHz driver     */
     AtrnLASTdriver,
     Atrn_HOLD = Atrn_SAD1,  /* used for hold audio                  */
     Atrn_RESET = Atrn_SAB1  /* signals a server reset in cre_close  */
  };

/* ==  BOOTtime: relative boot times per source requested.           == */
#define AtrnBOOTtime { 1,  1,  1,  2,  2,  1,  2,  2,  1,  1,  1,  1, 2 }
/*   reference symbols -   -   -  C1  B1   -  B3  B4   -   -   -   -    */

 #define MAX_HEADS   16      /*     ListenerHeads:  Theoretically 15  */
 #define MAX_ASRCS   64      /*      AudioSources:  Theoretically 46  */
 #define MAX_DPRFL   32      /*  DirectionProfile:  Arbitrary / reasonable */

/* ==  Directional Radiation Profile coefficient limit  == */
 #define MAX_RADPROFILE  (MAX_DPRFL-1)  /* reserves storage */

 #define ALL_SOURCES          -1
 #define ALL_HEADS            -1
 #define ALL_PROPVOLMS        -1
 #define ALL_DRIVERS          -1

 #define JSACOUNTS            0x3F
 #define JSACNTSTR       "Jsabbies"    /* smallest units of AuSIM3D */

/* ==  EulerSpace-Definition enumeration  ------------------------ == */
/* ==  6D coordinate standard for all float lists                  == */
enum ATRNspaceDef { AtrnX, AtrnY, AtrnZ, AtrnYAW, AtrnPTC, AtrnROL, AtrnDOF };

/* ==  Units-Definitions enumeration  ---------------------------- == */
enum  ATRNunitsDef {
    AtrnINCHES, Atrn_FEET_,
    AtrnMMETER, AtrnCMETER, Atrn_METER,
    AtrnUNITSlast
  };

/* ==  Initialization HEAD bits maybe OR'd with head ID  == */
 #define _ORATOR_         0x0040     /* creates a voice for the listener */
 #define AtrnHeadID      (0x007F&~_ORATOR_)   /* listener ID bit-stripper */
 #define AtrnLASTheadID   16
 /* without AtrnHeadDevice specified, the system selects based on WAVOUTDEV */
 #define AtrnHeadDevShift  8
 #define AtrnHeadDevice  (0x3F<<AtrnHeadDevShift)   /* listener output device selector */

/* ==  Initialization MODE bits maybe OR'd together      == */
 #define _CONSOLE_    0x10000     /* tells client to use stdout and stderr */
 #define _VERBOSE_     0x8000
 #define _SHOWSET_     0x4000     /* reports TRON setup  */
 #define _NOREPLY_     0x2000     /* makes quiet, uni-directional server */
 #define AtrnLINKhead  0x0800     /* links the head ID with source ID */
/*  AtrnLINKhead declares a listener as an orator AND links the source
    of the same ID.  _ORATOR_ only forces the listener to not hear
    the source of the same ID, allowing the source to be independently
    controled.
*/
 #define MODE_HiByteShft    7               /* only 14 bits usable of mode */
 #define AtrnModeAHMShift  MODE_HiByteShft  /* Built-in AHM selector 4-bits */    
 #define AtrnModeAHMSelect(iAHM)  ((iAHM&0xF)<<AtrnModeAHMShift)

 /* Additional MODE bits for RS-232 client/server */
 /*  the second nibble defines the resolution of fixed points  */
 #define AtrnRESOLV_DFLT  0.01f                 /* default fixed point resolution */
 #define RESOLV_0p01   0x0000                   /* default: 2 decimal fix  */
 #define RESOLV_x0p1   0x0010                   /* multiply by   0.10      */
 #define RESOLV_x100   0x0020                   /* multiply by 100         */
 #define AtrnFIX0    (RESOLV_0p01|RESOLV_x100)  /* clip float to fixed     */
 #define AtrnFIX1    (RESOLV_x0p1|RESOLV_x100)  /* shift float 10^1 to fix */
 #define AtrnFIX2    (RESOLV_0p01)              /* shift float 10^2 to fix */
 #define AtrnFIX3    (RESOLV_0p01|RESOLV_x0p1)  /* shift float 10^3 to fix */
 #define AtrnTENTHS   AtrnFIX1              /* fixed point tenths of units */
 #define Atrn100THS   AtrnFIX2              /* fixed point 100ths of units */
 #define _EOT_         0x0004               /* _End_Of_Transmission_  */
 #define _HI_BYTE_     0x0040               /* 2nd mode byte to come   */

/* ====================================================================== */
/* ==  PINNAE OFFSETS:                                                 == */
/* ==  The 'TRON library receives 6 DOF positions for the listener's   == */
/* ==    head and must transform this information into two 6D pinnae   == */
/* ==    locations.  The given position on the listener's head may be  == */
/* ==    arbitrary, but specified via a call to X_DEFINE_HEAD().       == */
/* ==    The ear_offset parameter is a pointer to three floats,        == */
/* ==    which are interpretted via the enum ATRNheadDef               == */

/* ==  Head-Tracking is often achieved with a 6D tracking sensor       == */
/* ==    attached to the top (crown) of the listener's head.           == */
/* ==  Alternately, another part of the simulation may be handling     == */
/* ==    listener location in terms of eye position.                   == */
/* ==  With the proper specifications, the 'TRON library can           == */
/* ==    transform any head position properly to pinnae locations.     == */

/* ==  The initial state of these offset transform parameters are:     == */
/* ==    INTERAURAL = INTERAURAL        Assumes average head size.     == */
/* ==    AURAL-ocular = 0.0             Assumes head centered coords.  == */
/* ==    AURAL-pinnae = INTERAURAL/2.0     Measured from head center.  == */
/* ==    AURAL-crown  = 0.0             Assumes head centered coords.  == */

/* ==  Caveat:  The boresight of the given listener coordinates MUST   == */
/* ==    be COINCIDENT with the listener's local head coordinate axes. == */

/* ==  Head-Definition parameter enumeration  ------------------------ == */
enum ATRNheadDef {       /*  _AXIS_ : _typical_non-zero_application_    */
    AtrnAURALocular,     /*     X:     from ocular to aural axis        */
    AtrnAURALpinnae,     /*     Y:     from head center to pinnae       */
    AtrnAURALcrown,      /*     Z:     from head crown to aural axis    */
    AtrnAURALoffsets,    /*  may be 1-6 data points of (x,y,z,yw,pt,rl) */
    AtrnINTERAURAL,      /*  2*AURALpinnae, pts=-1 scales delay table   */
    AtrnHRTFfile,        /* pts=-1 loads default, else data = filename  */
    AtrnAHMname,         /* searches directory/library for named AHM    */
    AtrnDELAYtable,      /* must be properly formated delay table       */
    AtrnDELAYscale,      /* scales the entire existing delay table      */
    AtrnHRTFresolve,     /* sets filter order trim                      */
    AtrnHRTFmodel,       /* selects NearField, FarField, or MixedField  */
    AtrnHEADgain,        /* sets final output gain for listener         */
    AtrnDISPLAYtype,     /* specifies HEADPHONES, NEARPHONES types      */
    AtrnEQleft,          /* downloads display type left EQ coefs        */
    AtrnEQright,         /* downloads display type right EQ coefs       */
    AtrnSHADOWscale,     /* scales filter ratio (0=contra; 10=ipsi)     */
    AtrnNEARDISTscale,   /* scales AHM dist for near-field model        */
    AtrnHEADshape,       /* 3 factors relative to interaural: Z,X,X'    */
    AtrnPATHgain,        /* sets gain for a source/listener pair        */
    AtrnLoadHeadModelDeprecated,    /* No longer supported.  Use LoadModel          */
    AtrnSetHeadModelAttrDeprecated, /* No longer supported.  Use SetAttributeDouble */
    AtrnHeadModelEnableDeprecated,  /* No longer supported.  Use EnableModel        */
    AtrnDISPLAYeqf,       /* specifies EQF file to load, overrides last DISPLAYtype call */
    AtrnHEADtrackid,      /* Tracker id for server side tracking   */
    AtrnHEADtrackrate,    /* Tracker max rate: float in Hz   */
    AtrnHEADtrackblock,   /* Track at block interval: int in blocks  */
    AtrnHEADnumsinks,     /* Number of sinks for the given head and all paths to that head */
    AtrnHEADblocksize,    /* Size of the engine block size */
    AtrnHEADmaxinterp,    /* Maximum total samples to do filter tracking interpolation */
    AtrnHEADproctype,     /* Head processing type.  */ 
    AtrnHEADEFlast
  };

 #define INTERAURAL        6.0f
 #define AURALOFFSET    (INTERAURAL*0.5f)
 /*  CROWN OFFSET: dist from crown of head to interaural axis in inches.  */
 #define CROWN_OFFSET     -5.8f
 enum HeadOffsets { OFST_AO, OFST_IA, OFST_AC };  /* obsolete */

/* Standard EQUALIZATIONS for AtrnDISPLAYtype */
enum ATRNeqDef {
    AtrnEQgenericHeadphone,
    AtrnEQgenericNearphone,
    AtrnEQsennheiserHD250,
    AtrnEQsennheiserHD540,
    AtrnEQsennheiserHD560,
    AtrnEQsennheiserHD580,
    AtrnEQsennheiserHD570,
    AtrnEQsennheiserHD500,
    AtrnEQsennheiserEH2200,
    AtrnEQsennheiserEH2270,
    AtrnEQsennheiserHD25,
    AtrnEQsennheiserHDC25,
    AtrnEQsennheiserHD205,
    AtrnEQsennheiserHD280,
    AtrnEQsennheiserPXC250,
    AtrnEQsennheiserMX500,   /* earbuds */
    AtrnEQgenericEarbuds,
    AtrnEQdefault,           /* use environment/registry setting */
    AtrnEQnone,              /* disable EQ completely */
    AtrnEQuser1,             /* specified on the GoldServ UI  */
    AtrnEQuser2,             /* specified on the GoldServ UI  */
    AtrnEQuser3,             /* specified on the GoldServ UI  */
    AtrnEQuser4,             /* specified on the GoldServ UI  */
    AtrnEQuser5,             /* specified on the GoldServ UI  */
    AtrnEQuser6,             /* specified on the GoldServ UI  */
    AtrnEQuser7,             /* specified on the GoldServ UI  */
    AtrnEQuser8,             /* specified on the GoldServ UI  */
    AtrnEQDEFlast
  };

/* HRTF model types for AtrnHRTFmodel  */
enum ATRNmodelDef {
    AtrnMODELfar,     /* assumes all sounds are far-field */
    AtrnMODELnear,    /* assumes all sounds are near-field */
    AtrnMODELmixed,   /* assumes all direct paths near, reflections far */
    AtrnMODELsphere,  /* uses spherical head model to generate HRTF's */
    AtrnMODELsynth,   /* AuSIM synthetic HRTF */
    AtrnMODELlast
  };

/* ==  CRE_DEFINE_SOURCE()  ----------------------------------------------- == */
/* ==  Source-Definition parameter enumeration  ---------------------- == */
/* --   Note that only those marked with '+' are needed in API            */
/* --   Complimentary enumerations are used in client/server protocol.    */
enum ATRNsrcDef {
    AtrnRADfields,      /*   same as x_direct_source()            */
    AtrnRADprofile,     /* + controls source radiation profile    */
    AtrnPROFILEpts,     /*   sets number of profile points to use */
    AtrnSPATIALoff,     /* + disables source spatialization       */
    AtrnSPATIALon,      /*    enables source spatialization  <default> */
    AtrnHEADlink,       /* +  enables source to head linkage      */
    AtrnHEADunlink,     /*   disables source to head linkage <default> */
    AtrnSPRDrolloff,    /* + sets the rolloff factor <1.0>        */
    AtrnGAINdist,       /*   distance at which gain is specified  */
    AtrnCHNLinput,      /* + selects live input channel           */
    AtrnCHNLmidi,       /* + selects midi input channel           */
    AtrnDPLRfactor,     /*   pts = listener ID, data = factor     */
    AtrnTIMEdelay,      /*   selects: None, Relative, Absolute    */
    AtrnLoadSrcModelDeprecated,    /* No longer supported.  Use LoadModel          */
    AtrnSetSrcModelAttrDeprecated, /* No longer supported.  Use SetAttributeDouble */
    AtrnSrcModelEnableDeprecated,  /* No longer supported.  Use EnableModel        */
    AtrnSRCgroundReflectionGain, /* pts = 1, data = one float */
    AtrnSRCinterpolator,         /*  pts = 1, data = one unsigned int */
    AtrnPATHgainForSrc,          /* sets gain for a source/listener pair        */
    AtrnSRCtrackid,              /* Tracker id for server side tracking   */
    AtrnSRCtrackrate,            /* Tracker max rate: float in Hz   */
    AtrnSRCtrackblock,           /* Track at block interval: int in blocks  */
    AtrnABSORBfactor,            /* Per source absorption factor */
    AtrnSRCDEFlast
  };

#define SPATIAL_OFF_AUTO_GAIN  800 /* magic number to signal using automatic gain */
#define PATH_GAIN_DISABLE_PATH 800 /* magic number to signal complete disabling of a path*/

struct IdAndGain { /* for use in the data field for AtrnPATHgain */
    int   id;
    float dB;
};

enum ATRNmodelEnableDef {
    AtrnEnableGain,
    AtrnDisableGain,
    AtrnEnableFilter,
    AtrnDisableFilter,
    AtrnEnableDelay,
    AtrnDisableDelay,
    AtrnModelEnableDeflast
};

/* ====================================================================== */
/* ==  GAIN CLIP DISTANCE relationship:                                == */
/* ==                                                                  == */
/* ==                                            /        1        \   == */
/* ==              /                 /dB_gain\ \ |-----------------|   == */
/* ==              |                 |-------| | \SPREADING_ROLLOFF/   == */
/* ==              |                 \  20.0 / |                       == */
/* ==  clip_dist = | GAIN_RATIO * 10           |                       == */
/* ==              \                           /                       == */
/* ==                                                                  == */
/* ==    A nominal linear gain is set to correspond to 0.0 dB          == */
/* ==  amplification of the system dynamic range as set by             == */
/* ==  X_amplfy_source().  The distance model applies a relative       == */
/* ==  attenuation to the source's signal level based on the dynamic   == */
/* ==  range gain (GAIN_RATIO scaled by dB) multiplied by the          == */
/* ==  inverse of the ear to source distance raised to the power of    == */
/* ==  the spreading rolloff exponent.  The result of this             == */
/* ==  relationship is that, at some small distance (the clip          == */
/* ==  distance), the distance model attenuation goes to zero (the     == */
/* ==  DSP filters the source signal at full input level) and shorter  == */
/* ==  distances have no gain amplification distance cue.  The         == */
/* ==  GAIN_RATIO is set at a value that optimizes dynamic range       == */
/* ==  versus near-field effects.                                      == */
/* ==    Given GAIN_RATIO = 2.1 and SPREADING_ROLLOFF = 0.80,          == */
/* ==  the following table gives clip distances in terms of dB,        == */
/* ==  as set in X_amplfy_source():                                    == */
/* ==                                                                  == */
/* ==         _Gain_in_dB_    _Clip_Distance_ (in current units)       == */
/* ==            -20.0 dB           0.1                                == */
/* ==            -10.0 dB           0.6                                == */
/* ==             -5.0 dB           1.3                                == */
/* ==              0.0 dB           2.5                                == */
/* ==              5.0 dB           5.3                                == */
/* ==             10.0 dB          10.9                                == */
/* ==             15.0 dB          22.4                                == */
/* ==             20.0 dB          45.9                                == */
/* ==             30.0 dB         193.7                                == */
/* ==             40.0 dB         816.7                                == */
/* ====================================================================== */
 #define GAIN_dB_ON            0.0f
 #define GAIN_dB_OFF        -120.0f
 /* GAIN_LIMIT & GAIN_NOMINAL are implementation dependent */
 #define GAIN_RATIO            2.1f
 #define ZERO_dB_DIST_INCHES   2.5f    /* inches */

/* Interpolators
   Interpolators are used on input, output, and extract from delay-line.
   The delay-line extraction is done once for a path, concatenating all of the delays.
   The interpolators interpolate both the proper delay at each sample time and the sample value at that time.
   Note that the Linear and polyphase will quantize to whole samples when the delay stops changing. 
   This is because the linear has audible artifacts, and the polyphase is expensive. */
enum ATRNsrcInterpTypes {
     AtrnSrcINTERPnone,   /* quantize=yes  */
     AtrnSrcINTERPlinear,   /* quantize=yes  */
     AtrnSrcINTERPpolyphase,  /* quantize=yes, fixed-rate only if input/output-interpolator  */
     AtrnSrcINTERPlagrange3,  /* quantize=no  */
     AtrnSrcINTERPlagrange7,    /* quantize=no  */
     AtrnSrcINTERPlagrange15,   /* quantize=no  */
     AtrnSrcINTERPlagrange31,    /* quantize=no  */
     AtrnSrcINTERPdt2linear,     /* quantize=no, equivalent to Lagrange1  */
     AtrnSrcINTERPdt2lagrange3,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange5,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange7,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange11,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange15,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange23,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange31,  /* quantize=no  */
     AtrnSrcINTERPdt2lagrange63,  /* quantize=no  */
     AtrnSrcINTERPskipxfade, /* quantize=yes, cross-fades */
     AtrnSrcINTERPlast
};

/* ==  Enumeration of values for cre_define_source(AtrnTIMEdelay)  == */
 enum ATRNtimedelayDef {
      AtrnTDNone,         /* No environment delay to direct path or reflections           */
      AtrnTDRelative,     /* No delay for direct path, reflections relative to direct     */
      AtrnTDAbsolute,     /* All paths have absolute delay relative to ZeroDelayDist      */
      AtrnTDCorrected,    /* Delay correct to smaller of ZeroDelayDist and system latency */
      AtrnTDLast
    };


/* ==  CRE_DEFINE_MEDIUM()  ----------------------------------------------- == */
/* ==  Enumeration of parameter ids for cre_define_medium()  == */
 enum ATRNmedDef {
     AtrnROLLOFF,       /* float exponent, nominally 1.0, typically 0.7 */
     AtrnABSORBdist,    /* float in current units  */
     AtrnHUMIDpercent,  /* float 0 to 100  */
     AtrnTEMPcelcius,   /* float of degrees celcius  */
     AtrnPRESSbar,      /* 1.0 is one atmosphere of air pressure  */
     AtrnABSORBcoef,    /* 0.0 to 1.0  */
     AtrnSOUNDspeed,    /* float specified in units per second  */
     AtrnMEDmaterial,   /* preset of SOS and ABSORBcoef */
     AtrnLoadEnvModelDeprecated,      /* No longer supported.  Use LoadModel          */
     AtrnSetEnvModelAttrDeprecated,   /* No longer supported.  Use SetAttributeDouble */
     AtrnEnvModelEnableDeprecated,    /* No longer supported.  Use EnableModel        */
     AtrnMEDgroundReflection,   /* pts = sizeof {IdAndGaind}, data = IdAndGain, id = reflection model type, Gain = gain or parameter to model */
     AtrnNUMwalls,      /* pts gives the number of walls (surfaces) to have in the world */
     AtrnMEDDEFlast
   };

 #define SPREADING_ROLLOFF     0.8f  /* rolloff exponent for distance model */
 #define ABSORPTION_DISTANCE  60.0f  /* dist (in INCHES) past which absorb filt effects */
 #define EXPONENT_LIMIT      100.0f  /* highest exponent accepted */

/* ==  Enumeration of values for cre_define_medium(AtrnMEDmaterial)  == */
 enum ATRNmedmatlDef {
     AtrnMDMTLair,
     AtrnMDMTLwater,
     AtrnMDMTLlast
   };

/* ==  RESPONSE DISTANCE: radius of HRTF measurements                == */
#define RESPONSE_DISTANCE     55.12f         /*  1.4 meters  */

/* == For AuSIM-internal debugging purposes only == */
#define AtrnDUMPdebug    0x2D

/* ==  CRE_DEFINE_ROUTER()  ----------------------------------------------- == */
/* ==  Router-Definition parameter enumeration  ---------------------- == */
/* --   These parameters control the routing of audio channels            */
/* --     Each input to output routing is called a "patch".               */
/* --   The router has no effect on audio localization.                   */
enum ATRNrouteDef {     /* __id__ | __pts______ | __data___  */
    AtrnDELpatch,       /* input,   output chnl,  null       */
    AtrnADDpatch,       /* input,   output chnl,  null       */
    AtrnDELpatches,     /* input,   num outputs,  array of outputs */
    AtrnADDpatches,     /* input,   num outputs,  array of outputs */
    AtrnSETrouting,     /* input,   num outputs,  array of outputs */
    AtrnCHNLactive,     /* input,   0 or non-zero, null      */
    AtrnRTRaddress,     /* router,  num chars,    string     */
    AtrnCHNLalias,      /* virtual, physical,     null       */
    AtrnRTRDEFlast
  };

/* ==  Special-Router channel modifiers ------------------------------ == */
#define AtrnROUTEcircuit 0x0100  /* ninth bit */
#define AtrnROUTEbuffer  0x0200  /* tenth bit */
#define AtrnROUTEfltrchnl 0x0400  /* eleventh bit ON, twelveth bit OFF */
#define AtrnROUTEshmchnl 0x0800  /* eleventh bit OFF, twelveth bit ON */
#define AtrnROUTEnetchnl 0x0C00  /* eleventh and twelveth bits both SET */
#define AtrnROUTEparent  0x2000  /* fourteenth (formerly thirteenth bit) */
#define AtrnROUTEchannel 0x00FF  /* bottom eight bits */
#define AtrnROUTEspecial 0xFF00  /* top eight bits of bottom word */

#define CKTM_EnvVar  "CKTMGRIP"


/* ==  CRE_FETCH_XXXX()  ---------------------------------------------- == */
/*   By convention, all cre_fetch_xxx functions were to be local (client) only. */
/*   For getting information from the server, use cre_query_xxx() functions. */
/*   Current cre_fetch_xxx() are local for CRE_TRON, but reach server for CreTronUni */

/* ==  Enumeration of parameter msg for cre_fetch_message()  == */
/*   The special msg AtrnMSGHostName will be deprecated, 
     use cre_query_system(AtrnQRYSYSname) for all new calls. */
enum ATRNfetchMessage {
    AtrnMSGRemote = 0x0300,  /* add this to the msg ID to get remote msg */
    AtrnMSGHostName = 1000   /* to be deprecated, do not use */
};

/* ==  Enumeration of parameter ids for cre_fetch_value()  == */
/*   Historically, this was called cre_detect() */
/*   The following parameters are valid only for CRE_TRON calls
         AtrnLSTNRinit : number of listeners initialized  
         AtrnASRCinit  : number of aural sources initialized  
         AtrnSYSunits  : current system units, see ATRNunitsDef enum above 
     */
/*   The following parameters are deprecated, use cre_query_xxx 
     AtrnFRAMErate    >> query_system(AtrnQRYSYSsmplrate)/query_head(AtrnQRYHDblocksize)
     AtrnWAVBUFavail  >> query_system(AtrnQRYSYSphysmem)
     AtrnJSABBIES     -- no replacement yet
     */
 enum ATRNdetectDef {
     AtrnLSTNRinit,     /* number of listeners initialized  */
     AtrnASRCinit,      /* number of aural sources initialized  */
     AtrnFRAMErate,     /* rate system updates localization parameters  */
     AtrnSYSunits,      /* current system units, see ATRNunitsDef enum above */
     AtrnWAVBUFavail,   /* seconds of free wavefile buffers available  */
     AtrnDTCDEFlast,
     AtrnJSABBIES = JSACOUNTS
   };

/* ==  Auto-Detection Board-Types  ---------------------------- == */
/*   Enumeration of return values from deprecated cre_detect() function.  */
enum  ATRNcardTypes {
    ALPHATRON, BEACHTRON
  };

/* ==  CRE_QUERY_XXXX()  ---------------------------------------------- == */
/* All queries requesting a single integral type,  */
/*   return the value in the return code,          */
/*   without requiring a valid data pointer.       */
enum ATRNquerySystem {
    AtrnQRYSYSsmplrate,   /* Default or current sample rate of audio output system (32-bit float) */
    AtrnQRYSYSversion,    /* Engine version number (32-bit float) */
    AtrnQRYSYScores,      /* DAPU cores available (32-bit int) */
    AtrnQRYSYSthreads,    /* Threads allocated to AuSIM3D (32-bit int) */
    AtrnQRYSYSconsumption,    /* Core usage 0-1 (Nx 32-bit float) */
    AtrnQRYSYSname,       /* GoldServer name (string) */
    AtrnQRYSYSphysmem,    /* Physical memory free (64-bit int, use 2 32-bit ints) */
    AtrnQRYSYSwavemode,   /* Wave Mode 1-based (32-bit int & string) */
    AtrnQRYSYSwavedev,    /* Wave Device (string) */
    AtrnQRYSYSinterface,  /* connection to engine  (32-bit int) */
    AtrnQRYSYSremote,     /* boolean for local/remote connection to engine  (32-bit int) */
    AtrnQRYSYSconnect,    /* connection description to engine  (string upto 64 chars) */
    AtrnQRYSYSheadinit,   /* total listeners initialized  (32-bit int) */
    AtrnQRYSYSasrcinit,   /* total sound sources initialized  (32-bit int) */
    AtrnQRYSYSpathsgen,   /* total sound paths generated  (32-bit int) */
    AtrnQRYSYSdistunits,  /* distance units of the system  (32-bit int) */

    AtrnQRYSYSlast
  };

enum ATRNqueryHead {
    AtrnQRYHDpos,     /* head-center XYZYwPtRl position (32-bit floats) */
    AtrnQRYHDleft,    /* pinnae XYZ location (32-bit floats) */
    AtrnQRYHDright,   /* pinnae XYZ location (32-bit floats) */
    AtrnQRYHDorient,  /* current Euler angles (32-bit floats) */
    AtrnQRYHDsize,    /* (-) geometric interaural size in current units (32-bit float) */
    AtrnQRYHDahm,     /* current AHM identifier (character string) */
    AtrnQRYHDresolve, /* (-) filter order trim (integer) */
    AtrnQRYHDmodel,   /* (-) near, far, mixed (integer) */
    AtrnQRYHDgain,    /* (-) final output gain (32-bit float) */
    AtrnQRYHDdisplay, /* (-) final display equalization type (integer) */
    AtrnQRYHDaxis1,   /* (-) axis detail: min, start, interval, stop, max (32-bit floats) */
    AtrnQRYHDaxis2,   /* (-) axis detail: min, start, interval, stop, max (32-bit floats) */
    AtrnQRYHDaxis3,   /* (-) axis detail: min, start, interval, stop, max (32-bit floats) */
    AtrnQRYHDtrack,   /* head-center XYZYwPtRl tracker data (32-bit floats) */
    AtrnQRYHDeqf,     /* current EQF identifier (character string) */
    AtrnQRYHDskipped,      /* Number of output buffers that have been skipped */
    AtrnQRYHDskippedreset, /* Number skipped and then resets the count */
    AtrnQRYHDblocksize,    /* Size in samples of of the engine block size */
    AtrnQRYHDproctype,     /* Head processing type */
    AtrnQRYHDnumbuffers,   /* Number of IO Audio buffers available */
    AtrnQRYHDcurrbufdepth, /* Current buffer depth showing how many buffers are used */
    AtrnQRYHDmaxbufdepth,  /* Maximum number of buffers used */
    AtrnQRYHDnumsinks,     /* Number of sinks for the indicated listener */
    AtrnQRYHDlevel,   /* Instantaneous decibel level (32-bit float) for each sink */
    AtrnQRYHDbufferstats,   /* Buffers available, current depth, and max depth (3x 32-bit integers) */
    AtrnQRYHDlast
  };

enum ATRNquerySource {
    AtrnQRYSRCradpts,   /* (-) radiation profile points in use (integer) */
    AtrnQRYSRCradpfl,   /* (-) radiation profile data (32-bit floats) */
    AtrnQRYSRCspatial,  /* (-) spatialization enabled: 0 or 1 (integer)  */
    AtrnQRYSRChdlink,   /* (-) listener identifier, -1 == UNLINKED (integer) */
    AtrnQRYSRCrolloff,  /* (-) spreading rolloff exponent (32-bit float) */
    AtrnQRYSRCgndist,   /* (-) 0dB distance in current units (32-bit float) */
    AtrnQRYSRCchnl,     /* (-) input channel for source (integer) */
    AtrnQRYSRCdoppler,  /* (-) Doppler factor for this source (32-bit float) */
    AtrnQRYSRCpos,      /* source-center XYZYwPtRl final position (32-bit floats) */
    AtrnQRYSRCtrack,    /* source-center XYZYwPtRl tracker data (32-bit floats) */
    AtrnQRYSRClevel,    /* instantaneous source signal level at time of query (32-bit float) */
    AtrnQRYSRClast
  };

enum ATRNqueryMedium {
    AtrnQRYMEDrolloff,  /* spreading rolloff exponent (32-bit float) */
    AtrnQRYMEDabsorb,   /* absorption distance (32-bit float) */
    AtrnQRYMEDhumid,    /* humidity percent (32-bit float) */
    AtrnQRYMEDtemp,     /* temperature celcius (32-bit float) */
    AtrnQRYMEDpress,    /* pressure in bar (100,000 Pascals) (32-bit float) */
    AtrnQRYMEDmatl,     /* material coefficient (32-bit float) */
    AtrnQRYMEDlast
};

enum ATRNqueryRouter {                                                                      /* __id___ | __pts_________ | __data___  */
    AtrnQRYRTRaddress,          /* router address (4 integers) */
    AtrnQRYRTRpatches,          /* all patches for given input (integers) */                /* input   | array size     | int array of outpus */
    AtrnQRYRTRinputs,           /* all inputs patched to given output (integers) */         /* output  | array size     | int array of inputs */
    AtrnQRYRTRactive,           /* all active outputs for given input (integers) */
    AtrnQRYRTRalias,            /* physical alias for given virtual channel (integer) */
    AtrnQRYRTRnumpatches,       /* number of patches for given input */                     /* input   | array size = 1 | int array for number */
    AtrnQRYRTRnumoutputpatches, /* number of patches to given output */                     /* output  | array size = 1 | int array for number */
    AtrnQRYRTRnuminputs,        /* number of input channels */                              /* ignored | array size = 1 | int array for number */
    AtrnQRYRTRinputlist,        /* list of input channels (integers) */                     /* ignored | array size     | int array of inputs */
    AtrnQRYRTRnumoutputs,       /* number of output channels */                             /* ignored | array size = 1 | int array for number */
    AtrnQRYRTRoutputlist,       /* list of output channels (integers) */                    /* ignored | array size     | int array of inputs */
    AtrnQRYRTRinputname,        /* string name of an input channel */                       /* input   | num chars      | string */
    AtrnQRYRTRoutputname,       /* string name of an output channel */                      /* output  | num chars      | string */
    AtrnQRYRTRlast
};


/* ==  Overriding ENVironment VARiables                 == */
/* ==    Defaults:                                      == */
/* ==      TRONBIN  == HRTF == "." (current directory)  == */
/* ==      TRONAHM  == DFT_AHM_MAP                      == */
#define TRON_EnvVar    "TRONBIN"     /* directory for all DSP binaries  */
#define ACOM_EnvVar    "TRONCOM"     /* ATRON client I/O configuration  */
#define HRTF_EnvVar    "HRTF"        /* directory for all HRTFs  */
#define AHMN_EnvVar    "TRONAHM"     /* name of head  */
#define ADEV_EnvVar    "TRONDEV"     /* device file */
#define EQFN_EnvVar    "TRONEQF"     /* path to default EQF */
#define EQFP_EnvVar    "EQFDIR"      /* path to EQF root, filename ignored */
#define AFMP_EnvVar    "AFMDIR"      /* path to AFM root, filename ignored */
#define EVLP_EnvVar    "EVLDIR"      /* path to EVL root, filename ignored */
#define MPIP_EnvVar    "MPIDIR"      /* path to PlugIn root, filename ignored */

/* The following 4 letter string is the prefix for the HRTF name.  */
/* The 4 letter suffix is defined by the macros xxx_MAPTYPE,       */
/* defined in xTRON.H and where "xxx" is the driver name.          */
#define DFT_AHM_MAP     "SLV"       /* default HRTF name prefix    */
#define DFT_AHM_EXT     ".AHM"      /* default HRTF file extension */
#define DFT_EQF_EXT     ".EQF"      /* default EQF file extension */
#define DFT_AFM_EXT     ".AFM"      /* default AFM file extension */
#define DFT_EVL_EXT     ".EVL"      /* default EVL file extension */
#define DFT_EQF_FILTER  "Default"   /* default EQF filename without extension */

/* ==  Indices of the _tron_error[] array.  == */
enum TronErrorId {
    ErrorCODE,     /*  error summary  */
    ErrorLodVAL,   /*  DSP load fail  */
    ErrorTnmVAL,   /*  TRON malloc  */
    ErrorCtmVAL,   /*  CTRL malloc  */
    ErrorDrmVAL,   /*  DRVR malloc  */
    ErrorAsmVAL,   /*  ASRC malloc  */
    ErrorHdmVAL,   /*  HEAD malloc  */
    ErrorDpmVAL,   /*  DPLR malloc  */
    ErrorMtmVAL,   /*  MATL malloc  */
    ErrorPcmVAL,   /*  PATC malloc  */
    ErrorSfmVAL,   /*  SURF malloc  */
    ErrorLAST
  };

/* ==  Bit markers of the _tron_error[ErrorCODE] value.  == */
enum TronERROR   {
    TE_NO_ERROR    =    0,
    TE_INIT_OFLO   =    1,
    TE_LOAD_FAIL   = 1<<ErrorLodVAL,
    TE_TRON_MALC   = 1<<ErrorTnmVAL,
    TE_CTRL_MALC   = 1<<ErrorCtmVAL,
    TE_DRVR_MALC   = 1<<ErrorDrmVAL,
    TE_ASRC_MALC   = 1<<ErrorAsmVAL,
    TE_HEAD_MALC   = 1<<ErrorHdmVAL,
    TE_DPLR_MALC   = 1<<ErrorDpmVAL,
    TE_MATL_MALC   = 1<<ErrorMtmVAL,
    TE_PTCH_MALC   = 1<<ErrorPcmVAL,
    TE_SURF_MALC   = 1<<ErrorSfmVAL,
    TE_INIT_ZERO   = 1<<ErrorLAST,
    TE_BAD_UNITS   = 1<<(ErrorLAST+1),
    TE_NEW_UNITS   = 1<<(ErrorLAST+2)
  };

 #define TronErrorHdngs    "Code","Load",                             \
                           "Tron","Ctrl","Drvr","Asrc","Head","Dplr", \
                           "Matl","Patc","Surf",                      \
                           "Zero","BadU","NewU"

/* ==  ATRON client commands (packet ID's)                           == */
/* ==    These are only needed by those programming custom client    == */
/* ==    driver to communicate with CRE servers.                     == */
enum ATRNcmd {
    _AUDIO_,             /* audio syncronization                          */
    LISTENR,             /* listener data                                 */
    USOURCE,             /*     uniform (3D) audio source data            */
    DSOURCE,             /* directional (6D) audio source data            */
    SRCGAIN,             /* source dynamic range (gain)                   */
    RFILTER,             /* reflection filter                             */
    TFILTER,             /* transmission filter                           */
    ARTSURF,             /* acoustic Reflect/Transmit surface data        */
    M_PATCH,             /* material patch (2D) area description          */
    APRPVOL,             /* acoustic propagation volume description       */
    SRFGAIN,             /* surface dynamic range (gain)                  */
    PTCGAIN,             /* patch dynamic range (gain)                    */
    APP_MAT,             /* application of material to surface and patch  */
    DOPPLER,             /* doppler control                               */
    APRPMED,             /* acoustic propagation medium control           */
    MIDISTR,             /* Musical Instrument Digital Interface strings  */
    WAVEFRM,             /* Waveform (RIFF) control                       */
    SNDLEVL,             /* sound level (power meter) monitor             */
    USER001,             /* User definable function 1                     */
    USER002,             /* User definable function 2                     */
    USER003,             /* User definable function 3                     */
    USER004,             /* User definable function 4                     */
    USER005,             /* User definable function 5                     */
    USER006,             /* User definable function 6                     */
    ARSBOX,              /* acoustic reflection box size/position         */
    LOCKBOX,             /* lock the box to the movement of the listener  */
    SENDPKT,             /* end of an IP packet sent to the server        */
    RECVPKT,             /* packet received and executed                  */
    GETPLAY,             /* get sources playing                           */
    SETOUTP,             /* set output display type (headphone, speakers) */
    GETOUTP,             /* get output display type                       */
    DRYGAIN,             /* set dry output gain (Eagle only)              */
    CHNLRTG,             /* patches for channel routing                   */
    QUERYLH,             /* query for listener head properties            */
    QUERYSS,             /* query for sound source properties             */
    QUERYPM,             /* query for propagation medium properties       */
    QUERYRT,             /* query for router properties                   */
    SETCLCK,             /* cre_set_clock                                 */
    GETCLCK,             /* cre_get_clock                                 */
    SYNCCLK,             /* cre_sync_clock                                */
    QEVENTS,             /* cre_queue_events                              */
    SETEVTS,             /* cre_set_events                                */
    CLREVTS,             /* cre_clear_events                              */
    QUERYSY,             /* query for system properties            */
    LASTPKT,             /* Note: up to 44 (0x2C) as of 2009 */
    SRVRESP = 0x30,      /* server response (3 LSbits = client signature) */
    COMXXON = 0x77,      /* com port flow control X_ON                    */
    COMXOFF = 0x78,      /* com port flow control X_OFF                   */
    COMTEST = 0x79,      /* com port test reflector                       */
    ATRNDEL = 0x7A,      /* ATRON delete file on Atron                    */
    ATRNLST = 0x7B,      /* ATRON list files on Atron                     */
    ATRNLOD = 0x7C,      /* ATRON load file, writes file to Atron         */
    ATRNTST = 0x7D,      /* ATRON test packet; server returns packet      */
    ATRNDSP = 0x7E,      /* DSP binary download packet                    */
    _TSYNC_ = 0x7F
  };

 /* 7th bit OR'd with an ATRON command enables init mode */
 #define __INIT__    0x0040          /* combines with AtrnCMD */

 /* ==  ATRON server return codes (when bi-directional enabled)  == */
 #define Atrn_Ok          1
 #define Atrn_NULL        0
 #define AtrnDrvrERROR   -1
 #define AtrnInitERROR   -2
 #define AtrnBOOTED      -3

#ifdef INIT_NO_FILTERING
 #define AtrnINITSTATE        0
 #define AtrnINITFLAGVECTOR   0
#else
 #define AtrnINITSTATE        1
 #define AtrnINITFLAGVECTOR  ((unsigned)-1)
#endif


/* ---------------------------------------------------------------------------- *
   The following function prototypes are kept in this module for compatibility
   purposes.  They are not intended for application use and thus undocumented.
 * ---------------------------------------------------------------------------- */

/* ==  Server process functions  == */
#ifdef __cplusplus
 extern "C" {
#endif

/* -- High-level ATRON server functions ---- */
int  atron_setup       (int argc, char *argv[]);
void atron_main_loop   (int display);
void atron_control     (int msg);
void atron_close       (void);

/* -- Low-level ATRON server functions -- */
/* --   these are encapsulated in the high level functions -- */
void atron_init        (int port, int status);
void atron_proc_packet (void);

#ifdef __cplusplus
 }
#endif

#ifdef WIN32
#pragma comment (lib, "Rpcrt4.lib")
#pragma comment (lib, "ws2_32.lib")
#pragma comment (lib, "setupapi.lib")
#endif

#endif  /*  ATRON_H  */

/* ==  Useful HELPER macros used within the libraries  == */
#ifndef TRIG
 #define TRIG
 #ifndef __MATH_H
  #ifndef _IRIX_
   #include <math.h>
  #endif
 #endif
 #define Pi       3.1415926535897932384626433832795
 #define Pi2      6.283185307179586476925286766559
 #ifndef  M_PI
  #define  M_PI   Pi
  #define  M_PI_2 (Pi*0.5)
  #define  M_1_PI   (1/Pi)
  #define  M_2_PI   (2/Pi)
 #endif
 /* small round-off error definitions */
 #define EPSILON    0.01
 #define _EPSILON   0.0001
 #define _epsilon    0.00000001
 #define f_epsilon  1.192092896e-07F  /* precision of a float */
 /* radian defs */
 #define QUADRANT   M_PI_2
 #define RADS2DGRS (180/M_PI)
 #define RADS2DEGS (180/M_PI)
 #define DEGS2RADS (M_PI/180.0)
 #define DGRS2RADS (M_PI/180.0)
 /* axis defs */
 #define XAXIS 0
 #define YAXIS 1
 #define ZAXIS 2
#endif

/* ==  Integer status return values  == */
#ifndef Ok
 #define Ok       1
 #define Error0   0
 #define Error1  -1
 #define Error2  -2
 #define Error3  -3
 #define Error4  -4
 #define Error5  -5
 #define Error6  -6
 #define Error7  -7
 #define Error8  -8
 #define Error9  -9
 #define Error10   10
 #define Error11  -11
 #define Error12  -12
 #define Error13  -13
 #define Error14  -14
 #define Error15  -15
 #define Error16  -16
 #define Error17  -17
 #define Error18  -18
 #define Error19  -19
 #define Error20  -20
 #define Error21  -21
 #define Error22  -22
 #define Error23  -23
#endif

#ifndef TRUE
 #define FALSE 0
 #define TRUE  (!FALSE)
#endif

#ifndef ON
 #define OFF   0
 #define ON   (~OFF)
#endif





#ifdef   WE_REALLY_NEED_THESE_OLD_CRE_HARDWARE_DEFS
/* ==  Hardware/Driver limitations  == */
#define MAX_CTRONS  8
#define MAX_BTRONS  8
#define MAX_TRONS  15   /*  8 CTRONS + 7 BTRONS  */

#define MAXI_SRCS   4
#define ARS2_SRCS   1
#define ARS3_SRCS   1

#define BMP1_SRCS   2
#define BMP2_SRCS   6

#define BMP3_SRCS   2
#define BMP4_SRCS   4
#define CMP1_SRCS   4
#define DPL1_SRCS   1
#define CTRON_SRCS  4
#define CTRON_BEST_CHNL  2      /* cleanest Convolvotron ADC */

 /* ==  CRE_TRON imposed resource limits  == */
 #define MAX_SURFS    6      /*  AcousticSurfaces:  Hardware limited  */
 #define MAX_PTCHS    1      /*   MaterialPatches:  One patch / surf now. */
 #define MAX_MATLS    8      /* AcousticMaterials:  No limit  */
 #define MAX_PMATS    3      /*  PaletteMaterials:  Hardware limited  */
 #define MAX_DRVRS  AtrnLASTdriver               /* DSP Drivers  */
 #define MAX_DPLRS   22      /* Doppler:  8 Spectrum C25's + 7 MultiSounds */
 #define ALL_TRONS            -1

#ifndef FILTERENUM
 #define FILTERENUM
/* ==  Atron Finite Impulse Response filter ID's                 == */
/* ==    these are used to label the type of individual filter   == */
/* ==    or label a block of filters.                            == */
/* ==  see tron_filter().                                        == */
enum ATRNfilter {
    AFIR_HRTF, AFIR_LPOL, AFIR_RPOL,
    AFIR_LEFT, AFIR_RGHT,
    AFIR_RFLT, AFIR_TRAN,
    AFIR_LAST
  };
#endif

#endif   /*  WE_REALLY_NEED_THESE_OLD_CRE_HARDWARE_DEFS */



