Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

snd_local.h

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 // snd_local.h -- private sound definations
00023 
00024 
00025 #include "../game/q_shared.h"
00026 #include "../qcommon/qcommon.h"
00027 #include "snd_public.h"
00028 
00029 #define PAINTBUFFER_SIZE        4096                    // this is in samples
00030 
00031 #define SND_CHUNK_SIZE          1024                    // samples
00032 #define SND_CHUNK_SIZE_FLOAT    (SND_CHUNK_SIZE/2)      // floats
00033 #define SND_CHUNK_SIZE_BYTE     (SND_CHUNK_SIZE*2)      // floats
00034 
00035 typedef struct {
00036     int         left;   // the final values will be clamped to +/- 0x00ffff00 and shifted down
00037     int         right;
00038 } portable_samplepair_t;
00039 
00040 typedef struct adpcm_state {
00041     short   sample;     /* Previous output value */
00042     char    index;      /* Index into stepsize table */
00043 } adpcm_state_t;
00044 
00045 typedef struct sndBuffer_s {
00046     short                   sndChunk[SND_CHUNK_SIZE];
00047     struct sndBuffer_s      *next;
00048     int                     size;
00049     adpcm_state_t           adpcm;
00050 } sndBuffer;
00051 
00052 typedef struct sfx_s {
00053     sndBuffer       *soundData;
00054     qboolean        defaultSound;           // couldn't be loaded, so use buzz
00055     qboolean        inMemory;               // not in Memory
00056     qboolean        soundCompressed;        // not in Memory
00057     int             soundCompressionMethod; 
00058     int             soundLength;
00059     char            soundName[MAX_QPATH];
00060     int             lastTimeUsed;
00061     struct sfx_s    *next;
00062 } sfx_t;
00063 
00064 typedef struct {
00065     int         channels;
00066     int         samples;                // mono samples in buffer
00067     int         submission_chunk;       // don't mix less than this #
00068     int         samplebits;
00069     int         speed;
00070     byte        *buffer;
00071 } dma_t;
00072 
00073 #define START_SAMPLE_IMMEDIATE  0x7fffffff
00074 
00075 typedef struct loopSound_s {
00076     vec3_t      origin;
00077     vec3_t      velocity;
00078     sfx_t       *sfx;
00079     int         mergeFrame;
00080     qboolean    active;
00081     qboolean    kill;
00082     qboolean    doppler;
00083     float       dopplerScale;
00084     float       oldDopplerScale;
00085     int         framenum;
00086 } loopSound_t;
00087 
00088 typedef struct
00089 {
00090     int         allocTime;
00091     int         startSample;    // START_SAMPLE_IMMEDIATE = set immediately on next mix
00092     int         entnum;         // to allow overriding a specific sound
00093     int         entchannel;     // to allow overriding a specific sound
00094     int         leftvol;        // 0-255 volume after spatialization
00095     int         rightvol;       // 0-255 volume after spatialization
00096     int         master_vol;     // 0-255 volume before spatialization
00097     float       dopplerScale;
00098     float       oldDopplerScale;
00099     vec3_t      origin;         // only use if fixed_origin is set
00100     qboolean    fixed_origin;   // use origin instead of fetching entnum's origin
00101     sfx_t       *thesfx;        // sfx structure
00102     qboolean    doppler;
00103 } channel_t;
00104 
00105 
00106 #define WAV_FORMAT_PCM      1
00107 
00108 
00109 typedef struct {
00110     int         format;
00111     int         rate;
00112     int         width;
00113     int         channels;
00114     int         samples;
00115     int         dataofs;        // chunk starts this many bytes from file start
00116 } wavinfo_t;
00117 
00118 
00119 /*
00120 ====================================================================
00121 
00122   SYSTEM SPECIFIC FUNCTIONS
00123 
00124 ====================================================================
00125 */
00126 
00127 // initializes cycling through a DMA buffer and returns information on it
00128 qboolean SNDDMA_Init(void);
00129 
00130 // gets the current DMA position
00131 int     SNDDMA_GetDMAPos(void);
00132 
00133 // shutdown the DMA xfer.
00134 void    SNDDMA_Shutdown(void);
00135 
00136 void    SNDDMA_BeginPainting (void);
00137 
00138 void    SNDDMA_Submit(void);
00139 
00140 //====================================================================
00141 
00142 #define MAX_CHANNELS            96
00143 
00144 extern  channel_t   s_channels[MAX_CHANNELS];
00145 extern  channel_t   loop_channels[MAX_CHANNELS];
00146 extern  int     numLoopChannels;
00147 
00148 extern  int     s_paintedtime;
00149 extern  int     s_rawend;
00150 extern  vec3_t  listener_forward;
00151 extern  vec3_t  listener_right;
00152 extern  vec3_t  listener_up;
00153 extern  dma_t   dma;
00154 
00155 #define MAX_RAW_SAMPLES 16384
00156 extern  portable_samplepair_t   s_rawsamples[MAX_RAW_SAMPLES];
00157 
00158 extern cvar_t   *s_volume;
00159 extern cvar_t   *s_nosound;
00160 extern cvar_t   *s_khz;
00161 extern cvar_t   *s_show;
00162 extern cvar_t   *s_mixahead;
00163 
00164 extern cvar_t   *s_testsound;
00165 extern cvar_t   *s_separation;
00166 
00167 qboolean S_LoadSound( sfx_t *sfx );
00168 
00169 void        SND_free(sndBuffer *v);
00170 sndBuffer*  SND_malloc();
00171 void        SND_setup();
00172 
00173 void S_PaintChannels(int endtime);
00174 
00175 void S_memoryLoad(sfx_t *sfx);
00176 portable_samplepair_t *S_GetRawSamplePointer();
00177 
00178 // spatializes a channel
00179 void S_Spatialize(channel_t *ch);
00180 
00181 // adpcm functions
00182 int  S_AdpcmMemoryNeeded( const wavinfo_t *info );
00183 void S_AdpcmEncodeSound( sfx_t *sfx, short *samples );
00184 void S_AdpcmGetSamples(sndBuffer *chunk, short *to);
00185 
00186 // wavelet function
00187 
00188 #define SENTINEL_MULAW_ZERO_RUN 127
00189 #define SENTINEL_MULAW_FOUR_BIT_RUN 126
00190 
00191 void S_FreeOldestSound();
00192 
00193 #define NXStream byte
00194 
00195 void encodeWavelet(sfx_t *sfx, short *packets);
00196 void decodeWavelet( sndBuffer *stream, short *packets);
00197 
00198 void encodeMuLaw( sfx_t *sfx, short *packets);
00199 extern short mulawToShort[256];
00200 
00201 extern short *sfxScratchBuffer;
00202 extern sfx_t *sfxScratchPointer;
00203 extern int     sfxScratchIndex;
00204 

Generated on Thu Aug 25 12:37:28 2005 for Quake III Arena by  doxygen 1.3.9.1