| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef SND_MAIN_H |
| 22 |
#define SND_MAIN_H |
| 23 |
|
| 24 |
#include "sound.h" |
| 25 |
|
| 26 |
|
| 27 |
typedef struct snd_format_s |
| 28 |
{ |
| 29 |
unsigned int speed; |
| 30 |
unsigned short width; |
| 31 |
unsigned short channels; |
| 32 |
} snd_format_t; |
| 33 |
|
| 34 |
typedef struct snd_buffer_s |
| 35 |
{ |
| 36 |
snd_format_t format; |
| 37 |
unsigned int nbframes; |
| 38 |
unsigned int maxframes; |
| 39 |
unsigned char samples[4]; |
| 40 |
} snd_buffer_t; |
| 41 |
|
| 42 |
typedef struct snd_ringbuffer_s |
| 43 |
{ |
| 44 |
snd_format_t format; |
| 45 |
unsigned char* ring; |
| 46 |
unsigned int maxframes; |
| 47 |
unsigned int startframe; |
| 48 |
|
| 49 |
unsigned int endframe; |
| 50 |
|
| 51 |
} snd_ringbuffer_t; |
| 52 |
|
| 53 |
|
| 54 |
#define SFXFLAG_NONE 0 |
| 55 |
#define SFXFLAG_FILEMISSING (1 << 0) // wasn't able to load the associated sound file |
| 56 |
#define SFXFLAG_LEVELSOUND (1 << 1) // the sfx is part of the server or client precache list for this level |
| 57 |
#define SFXFLAG_STREAMED (1 << 2) // informative only. You shouldn't need to know that |
| 58 |
#define SFXFLAG_MENUSOUND (1 << 3) // not freed during level change (menu sounds, music, etc) |
| 59 |
|
| 60 |
typedef struct snd_fetcher_s snd_fetcher_t; |
| 61 |
struct sfx_s |
| 62 |
{ |
| 63 |
char name[MAX_QPATH]; |
| 64 |
sfx_t *next; |
| 65 |
size_t memsize; |
| 66 |
|
| 67 |
snd_format_t format; |
| 68 |
unsigned int flags; |
| 69 |
unsigned int loopstart; |
| 70 |
unsigned int total_length; |
| 71 |
const snd_fetcher_t *fetcher; |
| 72 |
void *fetcher_data; |
| 73 |
|
| 74 |
float volume_mult; |
| 75 |
float volume_peak; |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
#define SND_LISTENERS 8 |
| 80 |
|
| 81 |
typedef struct channel_s |
| 82 |
{ |
| 83 |
|
| 84 |
sfx_t *sfx; |
| 85 |
float basevolume; |
| 86 |
unsigned int flags; |
| 87 |
int entnum; |
| 88 |
int entchannel; |
| 89 |
vec3_t origin; |
| 90 |
vec_t distfade; |
| 91 |
void *fetcher_data; |
| 92 |
int prologic_invert; |
| 93 |
float basespeed; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
float mixspeed; |
| 98 |
|
| 99 |
float volume[SND_LISTENERS]; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
double position; |
| 104 |
} channel_t; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
typedef void (*snd_fetcher_getsamplesfloat_t) (channel_t *ch, sfx_t *sfx, int firstsampleframe, int numsampleframes, float *outsamplesfloat); |
| 109 |
typedef void (*snd_fetcher_stopchannel_t) (channel_t *ch); |
| 110 |
typedef void (*snd_fetcher_freesfx_t) (sfx_t *sfx); |
| 111 |
struct snd_fetcher_s |
| 112 |
{ |
| 113 |
snd_fetcher_getsamplesfloat_t getsamplesfloat; |
| 114 |
snd_fetcher_stopchannel_t stopchannel; |
| 115 |
snd_fetcher_freesfx_t freesfx; |
| 116 |
}; |
| 117 |
|
| 118 |
extern unsigned int total_channels; |
| 119 |
extern channel_t channels[MAX_CHANNELS]; |
| 120 |
|
| 121 |
extern snd_ringbuffer_t *snd_renderbuffer; |
| 122 |
extern qboolean snd_threaded; |
| 123 |
extern qboolean snd_usethreadedmixing; |
| 124 |
|
| 125 |
extern cvar_t _snd_mixahead; |
| 126 |
extern cvar_t snd_swapstereo; |
| 127 |
extern cvar_t snd_streaming; |
| 128 |
extern cvar_t snd_streaming_length; |
| 129 |
|
| 130 |
#define SND_CHANNELLAYOUT_AUTO 0 |
| 131 |
#define SND_CHANNELLAYOUT_STANDARD 1 |
| 132 |
#define SND_CHANNELLAYOUT_ALSA 2 |
| 133 |
extern cvar_t snd_channellayout; |
| 134 |
|
| 135 |
extern int snd_blocked; |
| 136 |
|
| 137 |
extern mempool_t *snd_mempool; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
extern qboolean simsound; |
| 143 |
|
| 144 |
|
| 145 |
#define STREAM_BUFFERSIZE 16384 // in sampleframes |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void S_MixToBuffer(void *stream, unsigned int frames); |
| 153 |
|
| 154 |
qboolean S_LoadSound (sfx_t *sfx, qboolean complain); |
| 155 |
|
| 156 |
snd_buffer_t *Snd_CreateSndBuffer (const unsigned char *samples, unsigned int sampleframes, const snd_format_t* in_format, unsigned int sb_speed); |
| 157 |
qboolean Snd_AppendToSndBuffer (snd_buffer_t* sb, const unsigned char *samples, unsigned int sampleframes, const snd_format_t* format); |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
snd_ringbuffer_t *Snd_CreateRingBuffer (const snd_format_t* format, unsigned int sampleframes, void* buffer); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested); |
| 171 |
|
| 172 |
|
| 173 |
void SndSys_Shutdown (void); |
| 174 |
|
| 175 |
|
| 176 |
void SndSys_Submit (void); |
| 177 |
|
| 178 |
|
| 179 |
unsigned int SndSys_GetSoundTime (void); |
| 180 |
|
| 181 |
|
| 182 |
qboolean SndSys_LockRenderBuffer (void); |
| 183 |
|
| 184 |
|
| 185 |
void SndSys_UnlockRenderBuffer (void); |
| 186 |
|
| 187 |
|
| 188 |
void SndSys_SendKeyEvents(void); |
| 189 |
|
| 190 |
|
| 191 |
typedef struct portable_samplepair_s |
| 192 |
{ |
| 193 |
float sample[SND_LISTENERS]; |
| 194 |
} portable_sampleframe_t; |
| 195 |
|
| 196 |
typedef struct listener_s |
| 197 |
{ |
| 198 |
int channel_unswapped; |
| 199 |
float yawangle; |
| 200 |
float dotscale; |
| 201 |
float dotbias; |
| 202 |
float ambientvolume; |
| 203 |
} |
| 204 |
listener_t; |
| 205 |
typedef struct speakerlayout_s |
| 206 |
{ |
| 207 |
const char *name; |
| 208 |
unsigned int channels; |
| 209 |
listener_t listeners[SND_LISTENERS]; |
| 210 |
} |
| 211 |
speakerlayout_t; |
| 212 |
|
| 213 |
#endif |