-sfxcache_t *S_LoadSound (sfx_t *s)
-{
- char namebuffer[256];
- qbyte *data;
- wavinfo_t info;
- int len;
- float stepscale;
- sfxcache_t *sc;
-
-// see if still in memory
- if (s->sfxcache)
- return s->sfxcache;
-
-//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_LoadFile(namebuffer, 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);
- Mem_Free(data);
- 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;
-
- // FIXME: add S_UnloadSounds or something?
- Mem_FreePool(&s->mempool);
- s->mempool = Mem_AllocPool(s->name);
- sc = s->sfxcache = Mem_Alloc(s->mempool, len + sizeof(sfxcache_t));
- if (!sc)
- {
- Mem_Free(data);
- 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, data + info.dataofs, s->name);
-
- Mem_Free(data);
- return sc;
-}
-
-
-
-/*
-===============================================================================
-
-WAV loading
-
-===============================================================================
-*/
-
-
-qbyte *data_p;
-qbyte *iff_end;
-qbyte *last_chunk;
-qbyte *iff_data;
-int iff_chunk_len;
-
-
-short GetLittleShort(void)