DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
snd_main.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20
21#ifndef SND_MAIN_H
22#define SND_MAIN_H
23
24#include <stddef.h>
25#include "qtypes.h"
26#include "qdefs.h"
27struct mempool_s;
28struct sfx_s;
29
30typedef struct snd_format_s
31{
32 unsigned int speed;
33 unsigned short width;
34 unsigned short channels;
36
37typedef struct snd_buffer_s
38{
40 unsigned int nbframes;
41 unsigned int maxframes;
42 unsigned char samples[4];
44
45typedef struct snd_ringbuffer_s
46{
48 unsigned char *ring;
49 unsigned int maxframes;
52 unsigned int startframe;
55 unsigned int endframe;
57
58// struct sfx_s flags
59#define SFXFLAG_NONE 0
60#define SFXFLAG_FILEMISSING (1 << 0)
61#define SFXFLAG_LEVELSOUND (1 << 1)
62#define SFXFLAG_STREAMED (1 << 2)
63#define SFXFLAG_MENUSOUND (1 << 3)
64
65typedef struct snd_fetcher_s snd_fetcher_t;
66struct sfx_s
67{
69 struct sfx_s *next;
70 size_t memsize;
71
73 unsigned int flags;
74 unsigned int loopstart;
75 unsigned int total_length;
76 const snd_fetcher_t *fetcher;
78
81};
82
83// maximum supported speakers constant
84#define SND_LISTENERS 8
85
86typedef struct channel_s
87{
88 // provided sound information
89 struct sfx_s *sfx;
90 float basevolume;
91 unsigned int flags;
92 int entnum;
98 float basespeed;
99
102 float mixspeed;
105
108 double position;
109} channel_t;
110
111// Sound fetching functions
112// "start" is both an input and output parameter: it returns the actual start time of the sound buffer
113typedef void (*snd_fetcher_getsamplesfloat_t) (channel_t *ch, struct sfx_s *sfx, int firstsampleframe, int numsampleframes, float *outsamplesfloat);
115typedef void (*snd_fetcher_freesfx_t) (struct sfx_s *sfx);
122
123extern unsigned int total_channels;
125
127extern qbool snd_threaded;
129
130extern cvar_t snd_waterfx;
131extern cvar_t snd_streaming;
133
134#define SND_CHANNELLAYOUT_AUTO 0
135#define SND_CHANNELLAYOUT_STANDARD 1
136#define SND_CHANNELLAYOUT_ALSA 2
138
139extern bool snd_blocked;
140
141extern struct mempool_s *snd_mempool;
142
146extern qbool simsound;
147
149
150#define STREAM_BUFFERSIZE 16384
151
152
153// ====================================================================
154// Architecture-independent functions
155// ====================================================================
156
157void S_SetUnderwaterIntensity(void);
158
159void S_MixToBuffer(void *stream, unsigned int frames);
160
161qbool S_LoadSound (struct sfx_s *sfx, qbool complain);
162
165snd_ringbuffer_t *Snd_CreateRingBuffer (const snd_format_t* format, unsigned int sampleframes, void* buffer);
166
167
168// ====================================================================
169// Architecture-dependent functions
170// ====================================================================
171
175
177void SndSys_Shutdown (void);
178
180void SndSys_Submit (void);
181
183unsigned int SndSys_GetSoundTime (void);
184
187
189void SndSys_UnlockRenderBuffer (void);
190
192void SndSys_SendKeyEvents(void);
193
195typedef struct portable_samplepair_s
196{
197 float sample[SND_LISTENERS];
199
200typedef struct listener_s
201{
203 float yawangle;
204 float dotscale;
205 float dotbias;
207}
209typedef struct speakerlayout_s
210{
211 const char *name;
212 unsigned int channels;
214}
216
217#endif
void() predraw
GLsizei samples
Definition glquake.h:623
GLuint buffer
Definition glquake.h:630
GLint GLint GLint GLsizei GLsizei GLenum format
Definition glquake.h:649
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
#define MAX_CHANNELS
Definition qdefs.h:147
float vec_t
Definition qtypes.h:68
vec_t vec3_t[3]
Definition qtypes.h:71
bool qbool
Definition qtypes.h:9
cvar_t volume
Definition snd_main.c:166
struct mempool_s * snd_mempool
Definition snd_main.c:144
qbool snd_threaded
enables use of snd_usethreadedmixing, provided that no sound hacks are in effect (like timedemo)
Definition snd_main.c:136
cvar_t snd_channellayout
Definition snd_main.c:170
void SndSys_Submit(void)
Submit the contents of "snd_renderbuffer" to the sound card.
Definition snd_sdl.c:196
void SndSys_SendKeyEvents(void)
if the sound system can generate events, send them
Definition snd_null.c:150
cvar_t snd_bufferlength
Definition snd_main.c:248
bool snd_blocked
When true, we submit silence to the audio device.
Definition snd_main.c:155
snd_ringbuffer_t * Snd_CreateRingBuffer(const snd_format_t *format, unsigned int sampleframes, void *buffer)
If "buffer" is NULL, the function allocates one buffer of "sampleframes" sample frames itself (if "sa...
Definition snd_mem.c:43
cvar_t snd_waterfx
Definition snd_main.c:173
qbool simsound
If simsound is true, the sound card is not initialized and no sound is submitted to it.
Definition snd_main.c:149
qbool S_LoadSound(struct sfx_s *sfx, qbool complain)
qbool SndSys_Init(snd_format_t *fmt)
Create "snd_renderbuffer", attempting to use the chosen sound format, but accepting if the driver wan...
Definition snd_sdl.c:103
void S_SetUnderwaterIntensity(void)
Definition snd_mix.c:320
cvar_t snd_streaming
Definition snd_main.c:171
unsigned int total_channels
Definition snd_main.c:129
unsigned int SndSys_GetSoundTime(void)
Returns the number of sample frames consumed since the sound started.
Definition snd_sdl.c:209
void(* snd_fetcher_getsamplesfloat_t)(channel_t *ch, struct sfx_s *sfx, int firstsampleframe, int numsampleframes, float *outsamplesfloat)
Definition snd_main.h:113
void S_MixToBuffer(void *stream, unsigned int frames)
Definition snd_mix.c:369
#define SND_LISTENERS
Definition snd_main.h:84
void SndSys_Shutdown(void)
Stop the sound card, delete "snd_renderbuffer" and free its other resources.
Definition snd_sdl.c:174
channel_t channels[MAX_CHANNELS]
Definition snd_main.c:128
snd_ringbuffer_t * snd_renderbuffer
Definition snd_main.c:131
void(* snd_fetcher_stopchannel_t)(channel_t *ch)
Definition snd_main.h:114
qbool SndSys_LockRenderBuffer(void)
Get the exclusive lock on "snd_renderbuffer".
Definition snd_sdl.c:222
void(* snd_fetcher_freesfx_t)(struct sfx_s *sfx)
Definition snd_main.h:115
cvar_t snd_streaming_length
Definition snd_main.c:172
qbool snd_usethreadedmixing
if true, the main thread does not mix sound, soundtime does not advance, and neither does snd_renderb...
Definition snd_main.c:137
void SndSys_UnlockRenderBuffer(void)
Release the exclusive lock on "snd_renderbuffer".
Definition snd_sdl.c:236
unsigned int flags
cf CHANNELFLAG_* defines
Definition snd_main.h:91
int prologic_invert
whether a sound is played on the surround channels in prologic
Definition snd_main.h:97
float basevolume
0-1 master volume
Definition snd_main.h:90
double position
updated ONLY by mixer position in sfx, starts at 0, loops or stops at sfx->total_length
Definition snd_main.h:108
vec_t distfade
distance multiplier (attenuation/clipK)
Definition snd_main.h:95
int entchannel
which channel id on the entity
Definition snd_main.h:93
float basespeed
playback rate multiplier for pitch variation
Definition snd_main.h:98
struct sfx_s * sfx
pointer to sound sample being used
Definition snd_main.h:89
float mixspeed
these are often updated while mixer is running, glitching should be minimized (mismatched channel vol...
Definition snd_main.h:102
vec3_t origin
origin of sound effect
Definition snd_main.h:94
void * fetcher_data
Per-channel data for the sound fetching function.
Definition snd_main.h:96
int entnum
makes sound follow entity origin (allows replacing interrupting existing sound on same id)
Definition snd_main.h:92
Definition cvar.h:66
int channel_unswapped
for un-swapping
Definition snd_main.h:202
float ambientvolume
Definition snd_main.h:206
float dotscale
Definition snd_main.h:204
float dotbias
Definition snd_main.h:205
float yawangle
Definition snd_main.h:203
exported for capturevideo so ogg can see all channels
Definition snd_main.h:196
unsigned int loopstart
in sample frames. equals total_length if not looped
Definition snd_main.h:74
void * fetcher_data
Per-sfx data for the sound fetching functions.
Definition snd_main.h:77
snd_format_t format
format describing the audio data that fetcher->getsamplesfloat will return
Definition snd_main.h:72
unsigned int total_length
in sample frames
Definition snd_main.h:75
char name[MAX_QPATH]
Definition snd_main.h:68
const snd_fetcher_t * fetcher
Definition snd_main.h:76
unsigned int flags
cf SFXFLAG_* defines
Definition snd_main.h:73
size_t memsize
total memory used (including struct sfx_s and fetcher data)
Definition snd_main.h:70
struct sfx_s * next
Definition snd_main.h:69
float volume_mult
for replay gain (multiplier to apply)
Definition snd_main.h:79
float volume_peak
for replay gain (highest peak); if set to 0, ReplayGain isn't supported
Definition snd_main.h:80
unsigned int maxframes
max size (buffer size), in sample frames
Definition snd_main.h:41
snd_format_t format
Definition snd_main.h:39
unsigned int nbframes
current size, in sample frames
Definition snd_main.h:40
snd_fetcher_freesfx_t freesfx
Definition snd_main.h:120
snd_fetcher_stopchannel_t stopchannel
Definition snd_main.h:119
snd_fetcher_getsamplesfloat_t getsamplesfloat
Definition snd_main.h:118
unsigned int speed
Definition snd_main.h:32
unsigned short channels
Definition snd_main.h:34
unsigned short width
Definition snd_main.h:33
snd_format_t format
Definition snd_main.h:47
unsigned char * ring
Definition snd_main.h:48
unsigned int startframe
index of the first frame in the buffer if startframe == endframe, the bufffer is empty
Definition snd_main.h:52
unsigned int maxframes
max size (buffer size), in sample frames
Definition snd_main.h:49
unsigned int endframe
index of the first EMPTY frame in the "ring" buffer may be smaller than startframe if the "ring" buff...
Definition snd_main.h:55
unsigned int channels
Definition snd_main.h:212
const char * name
Definition snd_main.h:211