Quake II RTX doxygen  1.0 dev
sound.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 
19 // sound.h -- private sound functions
20 
21 #include "../client.h"
22 
23 #if USE_SNDDMA
24 #include "client/sound/dma.h"
25 #endif
26 
27 // !!! if this is changed, the asm code must change !!!
28 typedef struct samplepair_s {
29  int left;
30  int right;
31 } samplepair_t;
32 
33 typedef struct sfxcache_s {
34  int length;
35  int loopstart;
36  int width;
37 #if USE_OPENAL
38  int size;
39  int bufnum;
40 #endif
41  byte data[1]; // variable sized
42 } sfxcache_t;
43 
44 typedef struct sfx_s {
45  char name[MAX_QPATH];
48  char *truename;
49  qerror_t error;
50 } sfx_t;
51 
52 // a playsound_t will be generated by each call to S_StartSound,
53 // when the mixer reaches playsound->begin, the playsound will
54 // be assigned to a channel
55 typedef struct playsound_s {
56  struct playsound_s *prev, *next;
58  float volume;
59  float attenuation;
60  int entnum;
62  qboolean fixed_origin; // use origin field instead of entnum's origin
63  vec3_t origin;
64  unsigned begin; // begin on this sample
65 } playsound_t;
66 
67 // !!! if this is changed, the asm code must change !!!
68 typedef struct channel_s {
69  sfx_t *sfx; // sfx number
70  int leftvol; // 0-255 volume
71  int rightvol; // 0-255 volume
72  int end; // end time in global paintsamples
73  int pos; // sample position in sfx
74  int looping; // where to loop, -1 = no looping OBSOLETE?
75  int entnum; // to allow overriding a specific sound
76  int entchannel; //
77  vec3_t origin; // only use if fixed_origin is set
78  vec_t dist_mult; // distance multiplier (attenuation/clipK)
79  float master_vol; // 0.0-1.0 master volume
80  qboolean fixed_origin; // use origin instead of fetching entnum's origin
81  qboolean autosound; // from an entity->sound, cleared each frame
82 #if USE_OPENAL
83  int autoframe;
84  int srcnum;
85 #endif
86 } channel_t;
87 
88 typedef struct {
89  char *name;
90  int rate;
91  int width;
92  int loopstart;
93  int samples;
94  byte *data;
95 } wavinfo_t;
96 
97 /*
98 ====================================================================
99 
100  SYSTEM SPECIFIC FUNCTIONS
101 
102 ====================================================================
103 */
104 
105 #if USE_SNDDMA
106 void DMA_SoundInfo(void);
107 qboolean DMA_Init(void);
108 void DMA_Shutdown(void);
109 void DMA_Activate(void);
110 int DMA_DriftBeginofs(float timeofs);
111 void DMA_ClearBuffer(void);
112 void DMA_Update(void);
113 #endif
114 
115 #if USE_OPENAL
116 void AL_SoundInfo(void);
117 qboolean AL_Init(void);
118 void AL_Shutdown(void);
120 void AL_DeleteSfx(sfx_t *s);
121 void AL_StopChannel(channel_t *ch);
122 void AL_PlayChannel(channel_t *ch);
123 void AL_StopAllChannels(void);
124 void AL_Update(void);
125 void AL_RawSamples(int samples, int rate, int width, int channels, byte *data, float volume);
126 void AL_UnqueueRawSamples();
127 
128 /* number of buffers in flight (needed for ogg) */
129 extern int active_buffers;
130 #endif
131 
132 //====================================================================
133 
134 // only begin attenuating sound volumes when outside the FULLVOLUME range
135 #define SOUND_FULLVOLUME 80
136 
137 #define SOUND_LOOPATTENUATE 0.003
138 
139 extern qboolean s_active;
140 
141 #define MAX_CHANNELS 32
143 extern int s_numchannels;
144 
145 extern int paintedtime;
147 
148 extern vec3_t listener_origin;
149 extern vec3_t listener_forward;
150 extern vec3_t listener_right;
151 extern vec3_t listener_up;
152 extern int listener_entnum;
153 
154 #define S_MAX_RAW_SAMPLES 8192
156 extern int s_rawend;
157 
158 extern wavinfo_t s_info;
159 
160 extern cvar_t *s_volume;
161 #if USE_SNDDMA
162 extern cvar_t *s_khz;
163 extern cvar_t *s_testsound;
164 #endif
165 extern cvar_t *s_ambient;
166 extern cvar_t *s_show;
167 
168 #define S_Malloc(x) Z_TagMalloc(x, TAG_SOUND)
169 #define S_CopyString(x) Z_TagCopyString(x, TAG_SOUND)
170 
171 sfx_t *S_SfxForHandle(qhandle_t hSfx);
173 channel_t *S_PickChannel(int entnum, int entchannel);
174 void S_IssuePlaysound(playsound_t *ps);
175 void S_BuildSoundList(int *sounds);
176 #if USE_SNDDMA
177 void S_InitScaletable(void);
178 void S_PaintChannels(int endtime);
179 #endif
180 
listener_entnum
int listener_entnum
Definition: main.c:39
AL_PlayChannel
void AL_PlayChannel(channel_t *ch)
Definition: al.c:284
S_PickChannel
channel_t * S_PickChannel(int entnum, int entchannel)
Definition: main.c:579
wavinfo_t::width
int width
Definition: sound.h:91
MAX_CHANNELS
#define MAX_CHANNELS
Definition: sound.h:141
AL_UploadSfx
sfxcache_t * AL_UploadSfx(sfx_t *s)
Definition: al.c:201
samplepair_t
struct samplepair_s samplepair_t
sfx_s::truename
char * truename
Definition: sound.h:48
s_show
cvar_t * s_show
s_khz
cvar_t * s_khz
Definition: dma.c:24
playsound_s
Definition: sound.h:55
channel_s::dist_mult
vec_t dist_mult
Definition: sound.h:78
DMA_Shutdown
void DMA_Shutdown(void)
Definition: dma.c:79
DMA_Update
void DMA_Update(void)
Definition: dma.c:150
sfx_t
struct sfx_s sfx_t
samplepair_s::left
int left
Definition: sound.h:29
s_volume
cvar_t * s_volume
Definition: main.c:58
AL_Init
qboolean AL_Init(void)
Definition: al.c:127
sfxcache_t
struct sfxcache_s sfxcache_t
wavinfo_t::samples
int samples
Definition: sound.h:93
sfx_s
Definition: sound.h:44
channel_s::origin
vec3_t origin
Definition: sound.h:77
s_active
qboolean s_active
Definition: main.c:33
s_numchannels
int s_numchannels
Definition: main.c:30
S_InitScaletable
void S_InitScaletable(void)
Definition: mix.c:281
samplepair_s::right
int right
Definition: sound.h:30
channel_s::end
int end
Definition: sound.h:72
sfxcache_s::length
int length
Definition: sound.h:34
AL_SoundInfo
void AL_SoundInfo(void)
Definition: al.c:40
playsound_s::attenuation
float attenuation
Definition: sound.h:59
channel_s::entchannel
int entchannel
Definition: sound.h:76
channel_s::looping
int looping
Definition: sound.h:74
AL_Shutdown
void AL_Shutdown(void)
Definition: al.c:183
playsound_s::begin
unsigned begin
Definition: sound.h:64
playsound_s::sfx
sfx_t * sfx
Definition: sound.h:57
listener_right
vec3_t listener_right
Definition: main.c:37
paintedtime
int paintedtime
Definition: main.c:43
sfx_s::error
qerror_t error
Definition: sound.h:49
playsound_s::prev
struct playsound_s * prev
Definition: sound.h:56
width
static int width
Definition: physical_sky.c:38
sfx_s::cache
sfxcache_t * cache
Definition: sound.h:47
AL_UnqueueRawSamples
void AL_UnqueueRawSamples()
Definition: al.c:562
channel_s::entnum
int entnum
Definition: sound.h:75
s_testsound
cvar_t * s_testsound
Definition: dma.c:25
s_ambient
cvar_t * s_ambient
Definition: main.c:59
wavinfo_t::data
byte * data
Definition: sound.h:94
listener_origin
vec3_t listener_origin
Definition: main.c:35
AL_StopChannel
void AL_StopChannel(channel_t *ch)
Definition: al.c:271
s_info
wavinfo_t s_info
Definition: mem.c:22
DMA_Init
qboolean DMA_Init(void)
Definition: dma.c:44
channel_s::pos
int pos
Definition: sound.h:73
playsound_s::next
struct playsound_s * next
Definition: sound.h:56
samplepair_s
Definition: sound.h:28
channels
channel_t channels[MAX_CHANNELS]
Definition: main.c:29
playsound_s::volume
float volume
Definition: sound.h:58
S_LoadSound
sfxcache_t * S_LoadSound(sfx_t *s)
Definition: mem.c:288
channel_s::autosound
qboolean autosound
Definition: sound.h:81
sfxcache_s::data
byte data[1]
Definition: sound.h:41
AL_DeleteSfx
void AL_DeleteSfx(sfx_t *s)
Definition: al.c:240
playsound_s::entchannel
int entchannel
Definition: sound.h:61
sfxcache_s::loopstart
int loopstart
Definition: sound.h:35
channel_s::sfx
sfx_t * sfx
Definition: sound.h:69
channel_t
struct channel_s channel_t
DMA_Activate
void DMA_Activate(void)
Definition: dma.c:85
wavinfo_t::rate
int rate
Definition: sound.h:90
s_rawsamples
samplepair_t s_rawsamples[S_MAX_RAW_SAMPLES]
Definition: mix.c:27
sfxcache_s
Definition: sound.h:33
channel_s::rightvol
int rightvol
Definition: sound.h:71
S_BuildSoundList
void S_BuildSoundList(int *sounds)
Definition: main.c:969
listener_up
vec3_t listener_up
Definition: main.c:38
DMA_DriftBeginofs
int DMA_DriftBeginofs(float timeofs)
Definition: dma.c:93
channel_s::leftvol
int leftvol
Definition: sound.h:70
AL_Update
void AL_Update(void)
Definition: al.c:438
S_IssuePlaysound
void S_IssuePlaysound(playsound_t *ps)
Definition: main.c:759
playsound_s::origin
vec3_t origin
Definition: sound.h:63
wavinfo_t::name
char * name
Definition: sound.h:89
AL_RawSamples
void AL_RawSamples(int samples, int rate, int width, int channels, byte *data, float volume)
Definition: al.c:505
channel_s
Definition: sound.h:68
DMA_SoundInfo
void DMA_SoundInfo(void)
Definition: dma.c:33
playsound_s::entnum
int entnum
Definition: sound.h:60
channel_s::fixed_origin
qboolean fixed_origin
Definition: sound.h:80
S_SfxForHandle
sfx_t * S_SfxForHandle(qhandle_t hSfx)
Definition: main.c:312
wavinfo_t::loopstart
int loopstart
Definition: sound.h:92
AL_StopAllChannels
void AL_StopAllChannels(void)
Definition: al.c:330
samples
unsigned samples[LAG_WIDTH]
Definition: screen.c:528
S_MAX_RAW_SAMPLES
#define S_MAX_RAW_SAMPLES
Definition: sound.h:154
playsound_t
struct playsound_s playsound_t
playsound_s::fixed_origin
qboolean fixed_origin
Definition: sound.h:62
DMA_ClearBuffer
void DMA_ClearBuffer(void)
Definition: dma.c:113
listener_forward
vec3_t listener_forward
Definition: main.c:36
S_PaintChannels
void S_PaintChannels(int endtime)
Definition: mix.c:179
s_pendingplays
playsound_t s_pendingplays
Definition: main.c:56
sfxcache_s::width
int width
Definition: sound.h:36
channel_s::master_vol
float master_vol
Definition: sound.h:79
s_rawend
int s_rawend
Definition: mix.c:28
active_buffers
int active_buffers
Definition: al.c:34
wavinfo_t
Definition: sound.h:88
sfx_s::name
char name[MAX_QPATH]
Definition: sound.h:45
sfx_s::registration_sequence
int registration_sequence
Definition: sound.h:46