DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
snd_mem.c File Reference
#include "darkplaces.h"
#include "snd_main.h"
#include "snd_ogg.h"
#include "snd_wav.h"
#include "sound.h"
+ Include dependency graph for snd_mem.c:

Go to the source code of this file.

Functions

qbool S_LoadSound (sfx_t *sfx, qbool complain)
 
void SCR_PopLoadingScreen (qbool)
 
void SCR_PushLoadingScreen (const char *, float)
 
snd_ringbuffer_tSnd_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 "sampleframes" is 0, the function chooses the size).
 

Function Documentation

◆ S_LoadSound()

qbool S_LoadSound ( sfx_t * sfx,
qbool complain )

Definition at line 87 of file snd_mem.c.

88{
89 char namebuffer[MAX_QPATH + 16];
90 size_t len;
91
92 // See if already loaded
93 if (sfx->fetcher != NULL)
94 return true;
95
96 // If we weren't able to load it previously, no need to retry
97 // Note: S_PrecacheSound clears this flag to cause a retry
98 if (sfx->flags & SFXFLAG_FILEMISSING)
99 return false;
100
101 // No sound?
102 if (snd_renderbuffer == NULL)
103 return false;
104
105 // Initialize volume peak to 0; if ReplayGain is supported, the loader will change this away
106 sfx->volume_peak = 0.0;
107
109 Con_Printf("loading sound %s\n", sfx->name);
110
111 SCR_PushLoadingScreen(sfx->name, 1);
112
113 // LadyHavoc: if the sound filename does not begin with sound/, try adding it
114 if (strncasecmp(sfx->name, "sound/", 6))
115 {
116 dpsnprintf (namebuffer, sizeof(namebuffer), "sound/%s", sfx->name);
117 len = strlen(namebuffer);
118 if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
119 {
120 if (S_LoadWavFile (namebuffer, sfx))
121 goto loaded;
122 memcpy (namebuffer + len - 3, "ogg", 4);
123 }
124 if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".ogg"))
125 {
126 if (OGG_LoadVorbisFile (namebuffer, sfx))
127 goto loaded;
128 }
129#ifdef USEXMP
130 else if (len >= 1)
131 {
132 if (XMP_LoadModFile (namebuffer, sfx))
133 goto loaded;
134 }
135#endif
136 }
137
138 // LadyHavoc: then try without the added sound/ as wav and ogg
139 dpsnprintf (namebuffer, sizeof(namebuffer), "%s", sfx->name);
140 len = strlen(namebuffer);
141 // request foo.wav: tries foo.wav, then foo.ogg
142 // request foo.ogg: tries foo.ogg only
143 // request foo.mod: tries foo.mod only
144 if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".wav"))
145 {
146 if (S_LoadWavFile (namebuffer, sfx))
147 goto loaded;
148 memcpy (namebuffer + len - 3, "ogg", 4);
149 }
150 if (len >= 4 && !strcasecmp (namebuffer + len - 4, ".ogg"))
151 {
152 if (OGG_LoadVorbisFile (namebuffer, sfx))
153 goto loaded;
154 }
155#ifdef USEXMP
156 else if (len >= 1)
157 {
158 if (XMP_LoadModFile (namebuffer, sfx))
159 goto loaded;
160 }
161#endif
162
163 // Can't load the sound!
164 sfx->flags |= SFXFLAG_FILEMISSING;
165 if (complain)
166 Con_Printf(CON_ERROR "Failed to load sound \"%s\"\n", sfx->name);
167
169 return false;
170
171loaded:
173 return true;
174}
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:997
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
#define CON_ERROR
Definition console.h:102
cvar_t developer_loading
Definition host.c:52
float strlen(string s)
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
#define NULL
Definition qtypes.h:12
snd_ringbuffer_t * snd_renderbuffer
Definition snd_main.c:131
#define SFXFLAG_FILEMISSING
wasn't able to load the associated sound file
Definition snd_main.h:60
void SCR_PopLoadingScreen(qbool)
Definition cl_screen.c:1899
void SCR_PushLoadingScreen(const char *, float)
Definition cl_screen.c:1873
qbool OGG_LoadVorbisFile(const char *filename, sfx_t *sfx)
Definition snd_ogg.c:598
qbool S_LoadWavFile(const char *filename, sfx_t *sfx)
Definition snd_wav.c:268
qbool XMP_LoadModFile(const char *filename, sfx_t *sfx)
Definition snd_xmp.c:596
int integer
Definition cvar.h:73

References CON_ERROR, Con_Printf(), developer_loading, dpsnprintf(), cvar_t::integer, MAX_QPATH, NULL, OGG_LoadVorbisFile(), S_LoadWavFile(), SCR_PopLoadingScreen(), SCR_PushLoadingScreen(), SFXFLAG_FILEMISSING, snd_renderbuffer, strlen(), and XMP_LoadModFile().

◆ SCR_PopLoadingScreen()

void SCR_PopLoadingScreen ( qbool redraw)

Definition at line 1899 of file cl_screen.c.

1900{
1902
1903 if(!s)
1904 {
1905 Con_DPrintf("Popping a loading screen item from an empty stack!\n");
1906 return;
1907 }
1908
1910 if(s->prev)
1911 s->prev->relative_completion = (s->absolute_loading_amount_min + s->absolute_loading_amount_len - s->prev->absolute_loading_amount_min) / s->prev->absolute_loading_amount_len;
1912 Z_Free(s);
1913
1914 if (scr_loading && redraw)
1916}
void CL_UpdateScreen(void)
Definition cl_screen.c:2130
qbool scr_loading
Definition cl_screen.c:104
static loadingscreenstack_t * loadingscreenstack
Definition cl_screen.c:1566
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
float absolute_loading_amount_min
Definition cl_screen.c:1561
float absolute_loading_amount_len
Definition cl_screen.c:1562
struct loadingscreenstack_s * prev
Definition cl_screen.c:1559
#define Z_Free(data)
Definition zone.h:164

References loadingscreenstack_t::absolute_loading_amount_len, loadingscreenstack_t::absolute_loading_amount_min, CL_UpdateScreen(), Con_DPrintf(), loadingscreenstack, loadingscreenstack_t::prev, scr_loading, and Z_Free.

Referenced by CL_BeginDownloads(), Mod_LoadModel(), Mod_Reload(), mod_start(), S_LoadSound(), and SCR_ClearLoadingScreen().

◆ SCR_PushLoadingScreen()

void SCR_PushLoadingScreen ( const char * msg,
float len_in_parent )

Definition at line 1873 of file cl_screen.c.

1874{
1878
1879 dp_strlcpy(s->msg, msg, sizeof(s->msg));
1880 s->relative_completion = 0;
1881
1882 if(s->prev)
1883 {
1884 s->absolute_loading_amount_min = s->prev->absolute_loading_amount_min + s->prev->absolute_loading_amount_len * s->prev->relative_completion;
1885 s->absolute_loading_amount_len = s->prev->absolute_loading_amount_len * len_in_parent;
1886 if(s->absolute_loading_amount_len > s->prev->absolute_loading_amount_min + s->prev->absolute_loading_amount_len - s->absolute_loading_amount_min)
1887 s->absolute_loading_amount_len = s->prev->absolute_loading_amount_min + s->prev->absolute_loading_amount_len - s->absolute_loading_amount_min;
1888 }
1889 else
1890 {
1893 }
1894
1895 if (scr_loading)
1897}
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
char msg[MAX_QPATH]
Definition cl_screen.c:1560
#define Z_Malloc(size)
Definition zone.h:161

References loadingscreenstack_t::absolute_loading_amount_len, loadingscreenstack_t::absolute_loading_amount_min, CL_UpdateScreen(), dp_strlcpy, loadingscreenstack, loadingscreenstack_t::msg, loadingscreenstack_t::prev, loadingscreenstack_t::relative_completion, scr_loading, and Z_Malloc.

Referenced by CL_BeginDownloads(), Mod_LoadModel(), Mod_Reload(), mod_start(), and S_LoadSound().

◆ Snd_CreateRingBuffer()

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 "sampleframes" is 0, the function chooses the size).

Definition at line 43 of file snd_mem.c.

44{
45 snd_ringbuffer_t *ringbuffer;
46
47 // If the caller provides a buffer, it must give us its size
48 if (sampleframes == 0 && buffer != NULL)
49 return NULL;
50
51 ringbuffer = (snd_ringbuffer_t*)Mem_Alloc(snd_mempool, sizeof (*ringbuffer));
52 memset(ringbuffer, 0, sizeof(*ringbuffer));
53 memcpy(&ringbuffer->format, format, sizeof(ringbuffer->format));
54
55 // If we haven't been given a buffer
56 if (buffer == NULL)
57 {
58 unsigned int maxframes;
59 size_t memsize;
60
61 if (sampleframes == 0)
62 maxframes = (format->speed + 1) / 2; // Make the sound buffer large enough for containing 0.5 sec of sound
63 else
64 maxframes = sampleframes;
65
66 memsize = maxframes * format->width * format->channels;
67 ringbuffer->ring = (unsigned char *) Mem_Alloc(snd_mempool, memsize);
68 ringbuffer->maxframes = maxframes;
69 }
70 else
71 {
72 ringbuffer->ring = (unsigned char *) buffer;
73 ringbuffer->maxframes = sampleframes;
74 }
75
76 return ringbuffer;
77}
GLuint buffer
Definition glquake.h:630
GLint GLint GLint GLsizei GLsizei GLenum format
Definition glquake.h:649
mempool_t * snd_mempool
Definition snd_main.c:144
snd_format_t format
Definition snd_main.h:47
unsigned char * ring
Definition snd_main.h:48
unsigned int maxframes
max size (buffer size), in sample frames
Definition snd_main.h:49
#define Mem_Alloc(pool, size)
Definition zone.h:92

References buffer, format, snd_ringbuffer_t::format, snd_ringbuffer_t::maxframes, Mem_Alloc, NULL, snd_ringbuffer_t::ring, and snd_mempool.

Referenced by S_Startup(), and SndSys_Init().