]> icculus.org git repositories - divverent/darkplaces.git/blob - snd_main.h
fixed bug with engine sounds (for TE_ effects) and local sounds (menu, etc) being...
[divverent/darkplaces.git] / snd_main.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #ifndef SND_MAIN_H
22 #define SND_MAIN_H
23
24 #include "sound.h"
25
26
27 typedef struct
28 {
29         size_t  length;
30         size_t  offset;
31         qbyte   data[4];        // variable sized
32 } sfxbuffer_t;
33
34 typedef struct
35 {
36         unsigned int    speed;
37         unsigned int    width;
38         unsigned int    channels;
39 } snd_format_t;
40
41 // sfx_t flags
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_PERMANENT               (1 << 3) // the sfx is used by the client code and should not be purged (even if it is also in the server precache list)
47
48 typedef struct snd_fetcher_s snd_fetcher_t;
49 struct sfx_s
50 {
51         char                            name[MAX_QPATH];
52         sfx_t                           *next;
53         mempool_t                       *mempool;
54         unsigned int            locks;                  // A locked sfx_t must not be freed.
55                                                                                 // Locks are added by S_PrecacheSound and S_ServerSounds.
56                                                                                 // SFX can be freed by S_UnlockSfx or S_ServerSounds.
57         unsigned int            flags;                  // cf SFXFLAG_* defines
58         snd_format_t            format;
59         int                                     loopstart;
60         size_t                          total_length;
61         const snd_fetcher_t     *fetcher;
62         void                            *fetcher_data;  // Per-sfx data for the sound fetching functions
63 };
64
65 typedef struct
66 {
67         snd_format_t    format;
68         int                             samples;                // mono samples in buffer
69         int                             samplepos;              // in mono samples
70         unsigned char   *buffer;
71         int                             bufferlength;   // used only by certain drivers
72 } dma_t;
73
74 typedef struct
75 {
76         sfx_t                   *sfx;                   // sfx number
77         unsigned int    flags;                  // cf CHANNELFLAG_* defines
78         int                             master_vol;             // 0-255 master volume
79         int                             leftvol;                // 0-255 volume
80         int                             rightvol;               // 0-255 volume
81         int                             end;                    // end time in global paintsamples
82         int                             lastptime;              // last time this channel was painted
83         int                             pos;                    // sample position in sfx
84         int                             entnum;                 // to allow overriding a specific sound
85         int                             entchannel;
86         vec3_t                  origin;                 // origin of sound effect
87         vec_t                   dist_mult;              // distance multiplier (attenuation/clipK)
88         void                    *fetcher_data;  // Per-channel data for the sound fetching function
89 } channel_t;
90
91 typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples);
92 typedef void (*snd_fetcher_end_t) (channel_t* ch);
93 struct snd_fetcher_s
94 {
95         snd_fetcher_getsb_t             getsb;
96         snd_fetcher_end_t               end;
97 };
98
99 void S_PaintChannels(int endtime);
100
101 // initializes cycling through a DMA buffer and returns information on it
102 qboolean SNDDMA_Init(void);
103
104 // gets the current DMA position
105 int SNDDMA_GetDMAPos(void);
106
107 void SNDDMA_Submit(void);
108
109 // shutdown the DMA xfer.
110 void SNDDMA_Shutdown(void);
111
112 qboolean S_LoadSound (sfx_t *s, qboolean complain);
113 void S_UnloadSound(sfx_t *s);
114
115 void *S_LockBuffer(void);
116 void S_UnlockBuffer(void);
117
118 extern size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* in_format, qbyte *out_data, const char* sfxname);
119
120 // ====================================================================
121 // User-setable variables
122 // ====================================================================
123
124 // 0 to NUM_AMBIENTS - 1 = water, etc
125 // NUM_AMBIENTS to NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS - 1 = normal entity sounds
126 // NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS to total_channels = static sounds
127 #define MAX_CHANNELS                    516
128 #define MAX_DYNAMIC_CHANNELS    128
129
130 extern channel_t channels[MAX_CHANNELS];
131
132 extern unsigned int total_channels;
133
134 extern int paintedtime;
135 extern int soundtime;
136 extern volatile dma_t *shm;
137
138 extern cvar_t snd_swapstereo;
139 extern cvar_t snd_streaming;
140
141 extern int snd_blocked;
142
143
144 #endif