File: client\snd_loc.h

    1 /*
    2 Copyright (C) 1997-2001 Id Software, Inc.
    3 
    4 This program is free software; you can redistribute it and/or
    5 modify it under the terms of the GNU General Public License
    6 as published by the Free Software Foundation; either version 2
    7 of the License, or (at your option) any later version.
    8 
    9 This program is distributed in the hope that it will be useful,
   10 but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
   12 
   13 See the GNU General Public License for more details.
   14 
   15 You should have received a copy of the GNU General Public License
   16 along with this program; if not, write to the Free Software
   17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   18 
   19 */
   20 // snd_loc.h -- private sound functions
   21 
   22 // !!! if this is changed, the asm code must change !!!
   23 typedef struct
   24 {
   25         int                     left;
   26         int                     right;
   27 } portable_samplepair_t;
   28 
   29 typedef struct
   30 {
   31         int             length;
   32         int             loopstart;
   33         int             speed;                  // not needed, because converted on load?
   34         int             width;
   35         int             stereo;
   36         byte            data[1];                // variable sized
   37 } sfxcache_t;
   38 
   39 typedef struct sfx_s
   40 {
   41         char            name[MAX_QPATH];
   42         int                     registration_sequence;
   43         sfxcache_t      *cache;
   44         char            *truename;
   45 } sfx_t;
   46 
   47 // a playsound_t will be generated by each call to S_StartSound,
   48 // when the mixer reaches playsound->begin, the playsound will
   49 // be assigned to a channel
   50 typedef struct playsound_s
   51 {
   52         struct playsound_s      *prev, *next;
   53         sfx_t           *sfx;
   54         float           volume;
   55         float           attenuation;
   56         int                     entnum;
   57         int                     entchannel;
   58         qboolean        fixed_origin;   // use origin field instead of entnum's origin
   59         vec3_t          origin;
   60         unsigned        begin;                  // begin on this sample
   61 } playsound_t;
   62 
   63 typedef struct
   64 {
   65         int                     channels;
   66         int                     samples;                                // mono samples in buffer
   67         int                     submission_chunk;               // don't mix less than this #
   68         int                     samplepos;                              // in mono samples
   69         int                     samplebits;
   70         int                     speed;
   71         byte            *buffer;
   72 } dma_t;
   73 
   74 // !!! if this is changed, the asm code must change !!!
   75 typedef struct
   76 {
   77         sfx_t           *sfx;                   // sfx number
   78         int                     leftvol;                // 0-255 volume
   79         int                     rightvol;               // 0-255 volume
   80         int                     end;                    // end time in global paintsamples
   81         int             pos;                    // sample position in sfx
   82         int                     looping;                // where to loop, -1 = no looping OBSOLETE?
   83         int                     entnum;                 // to allow overriding a specific sound
   84         int                     entchannel;             //
   85         vec3_t          origin;                 // only use if fixed_origin is set
   86         vec_t           dist_mult;              // distance multiplier (attenuation/clipK)
   87         int                     master_vol;             // 0-255 master volume
   88         qboolean        fixed_origin;   // use origin instead of fetching entnum's origin
   89         qboolean        autosound;              // from an entity->sound, cleared each frame
   90 } channel_t;
   91 
   92 typedef struct
   93 {
   94         int                     rate;
   95         int                     width;
   96         int                     channels;
   97         int                     loopstart;
   98         int                     samples;
   99         int                     dataofs;                // chunk starts this many bytes from file start
  100 } wavinfo_t;
  101 
  102 
  103 /*
  104 ====================================================================
  105 
  106   SYSTEM SPECIFIC FUNCTIONS
  107 
  108 ====================================================================
  109 */
  110 
  111 // initializes cycling through a DMA buffer and returns information on it
  112 qboolean SNDDMA_Init(void);
  113 
  114 // gets the current DMA position
  115 int             SNDDMA_GetDMAPos(void);
  116 
  117 // shutdown the DMA xfer.
  118 void    SNDDMA_Shutdown(void);
  119 
  120 void    SNDDMA_BeginPainting (void);
  121 
  122 void    SNDDMA_Submit(void);
  123 
  124 //====================================================================
  125 
  126 #define MAX_CHANNELS                    32
  127 extern  channel_t   channels[MAX_CHANNELS];
  128 
  129 extern  int             paintedtime;
  130 extern  int             s_rawend;
  131 extern  vec3_t  listener_origin;
  132 extern  vec3_t  listener_forward;
  133 extern  vec3_t  listener_right;
  134 extern  vec3_t  listener_up;
  135 extern  dma_t   dma;
  136 extern  playsound_t     s_pendingplays;
  137 
  138 #define MAX_RAW_SAMPLES 8192
  139 extern  portable_samplepair_t   s_rawsamples[MAX_RAW_SAMPLES];
  140 
  141 extern cvar_t   *s_volume;
  142 extern cvar_t   *s_nosound;
  143 extern cvar_t   *s_loadas8bit;
  144 extern cvar_t   *s_khz;
  145 extern cvar_t   *s_show;
  146 extern cvar_t   *s_mixahead;
  147 extern cvar_t   *s_testsound;
  148 extern cvar_t   *s_primary;
  149 
  150 wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength);
  151 
  152 void S_InitScaletable (void);
  153 
  154 sfxcache_t *S_LoadSound (sfx_t *s);
  155 
  156 void S_IssuePlaysound (playsound_t *ps);
  157 
  158 void S_PaintChannels(int endtime);
  159 
  160 // picks a channel based on priorities, empty slots, number of channels
  161 channel_t *S_PickChannel(int entnum, int entchannel);
  162 
  163 // spatializes a channel
  164 void S_Spatialize(channel_t *ch);
  165