2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
31 qbyte data[4]; // variable sized
38 unsigned int channels;
42 #define SFXFLAG_NONE 0
43 #define SFXFLAG_FILEMISSING (1 << 0) // wasn't able to load the associated sound file
44 #define SFXFLAG_SERVERSOUND (1 << 1) // the sfx is part of the server precache list
45 #define SFXFLAG_STREAMED (1 << 2) // informative only. You shouldn't need to know that
46 #define SFXFLAG_PERMANENTLOCK (1 << 3) // can never be freed (ex: used by the client code)
48 typedef struct snd_fetcher_s snd_fetcher_t;
54 int locks; // One lock is automatically granted while the sfx is
55 // playing (and removed when stopped). Locks can also be
56 // added by S_PrecacheSound and S_ServerSounds.
57 // A SFX with no lock and no SFXFLAG_PERMANENTLOCK is
58 // freed at level change by S_ServerSounds.
59 unsigned int flags; // cf SFXFLAG_* defines
63 const snd_fetcher_t *fetcher;
64 void *fetcher_data; // Per-sfx data for the sound fetching functions
70 int samples; // mono samples in buffer
71 int samplepos; // in mono samples
72 unsigned char *buffer;
73 int bufferlength; // used only by certain drivers
78 sfx_t *sfx; // sfx number
79 unsigned int flags; // cf CHANNELFLAG_* defines
80 int master_vol; // 0-255 master volume
81 int leftvol; // 0-255 volume
82 int rightvol; // 0-255 volume
83 int end; // end time in global paintsamples
84 int lastptime; // last time this channel was painted
85 int pos; // sample position in sfx
86 int entnum; // to allow overriding a specific sound
88 vec3_t origin; // origin of sound effect
89 vec_t dist_mult; // distance multiplier (attenuation/clipK)
90 void *fetcher_data; // Per-channel data for the sound fetching function
93 typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples);
94 typedef void (*snd_fetcher_end_t) (channel_t* ch);
97 snd_fetcher_getsb_t getsb;
98 snd_fetcher_end_t end;
101 void S_PaintChannels(int endtime);
103 // initializes cycling through a DMA buffer and returns information on it
104 qboolean SNDDMA_Init(void);
106 // gets the current DMA position
107 int SNDDMA_GetDMAPos(void);
109 void SNDDMA_Submit(void);
111 // shutdown the DMA xfer.
112 void SNDDMA_Shutdown(void);
114 qboolean S_LoadSound (sfx_t *s, qboolean complain);
115 void S_UnloadSound(sfx_t *s);
117 void S_LockSfx (sfx_t *sfx);
118 void S_UnlockSfx (sfx_t *sfx);
120 void *S_LockBuffer(void);
121 void S_UnlockBuffer(void);
123 extern size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* in_format, qbyte *out_data, const char* sfxname);
125 // ====================================================================
126 // User-setable variables
127 // ====================================================================
129 // 0 to NUM_AMBIENTS - 1 = water, etc
130 // NUM_AMBIENTS to NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS - 1 = normal entity sounds
131 // NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS to total_channels = static sounds
132 #define MAX_CHANNELS 516
133 #define MAX_DYNAMIC_CHANNELS 128
135 extern channel_t channels[MAX_CHANNELS];
137 extern unsigned int total_channels;
139 extern int paintedtime;
140 extern int soundtime;
141 extern volatile dma_t *shm;
143 extern cvar_t snd_swapstereo;
144 extern cvar_t snd_streaming;
146 extern int snd_blocked;