-sfxcache_t *S_LoadSound (sfx_t *s)
-{
- char namebuffer[256];
- byte *data;
- wavinfo_t info;
- int len;
- float stepscale;
- sfxcache_t *sc;
- byte stackbuf[1*1024]; // avoid dirtying the cache heap
-
-// see if still in memory
- sc = Cache_Check (&s->cache);
- if (sc)
- return sc;
-
-//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
-// load it in
- strcpy(namebuffer, "sound/");
- strcat(namebuffer, s->name);
-
-// Con_Printf ("loading %s\n",namebuffer);
-
- data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf), false);
-
- if (!data)
- {
- Con_Printf ("Couldn't load %s\n", namebuffer);
- return NULL;
- }
-
- info = GetWavinfo (s->name, data, com_filesize);
- // LordHavoc: stereo sounds are now allowed (intended for music)
- if (info.channels < 1 || info.channels > 2)
- {
- Con_Printf ("%s has an unsupported number of channels (%i)\n",s->name, info.channels);
- return NULL;
- }
- /*
- if (info.channels != 1)
- {
- Con_Printf ("%s is a stereo sample\n",s->name);
- return NULL;
- }
- */
-
- stepscale = (float)info.rate / shm->speed;
- len = info.samples / stepscale;
-
- len = len * info.width * info.channels;
-
- sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
- if (!sc)
- return NULL;
-
- sc->length = info.samples;
- sc->loopstart = info.loopstart;
- sc->speed = info.rate;
- sc->width = info.width;
- sc->stereo = info.channels == 2;
-
- ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);
-
- return sc;
-}
-
-
-
-/*
-===============================================================================
-
-WAV loading
-
-===============================================================================
-*/
-
-
-byte *data_p;
-byte *iff_end;
-byte *last_chunk;
-byte *iff_data;
-int iff_chunk_len;
-
-
-short GetLittleShort(void)
-{
- short val = 0;
- val = *data_p;
- val = val + (*(data_p+1)<<8);
- data_p += 2;
- return val;
-}
-
-int GetLittleLong(void)
-{
- int val = 0;
- val = *data_p;
- val = val + (*(data_p+1)<<8);
- val = val + (*(data_p+2)<<16);
- val = val + (*(data_p+3)<<24);
- data_p += 4;
- return val;
-}
-
-void FindNextChunk(char *name)
-{
- while (1)
- {
- data_p=last_chunk;
-
- if (data_p >= iff_end)
- { // didn't find the chunk
- data_p = NULL;
- return;
- }
-
- data_p += 4;
- iff_chunk_len = GetLittleLong();
- if (iff_chunk_len < 0)
- {
- data_p = NULL;
- return;
- }
-// if (iff_chunk_len > 1024*1024)
-// Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len);
- data_p -= 8;
- last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 );
- if (!strncmp(data_p, name, 4))
- return;
- }
-}
-
-void FindChunk(char *name)