-/*
-==============
-S_LoadWavFile
-==============
-*/
-sfxcache_t *S_LoadWavFile (const char *filename, sfx_t *s)
-{
- qbyte *data;
- wavinfo_t info;
- int len;
- sfxcache_t *sc;
-
- // Load the file
- data = FS_LoadFile(filename, false);
- if (!data)
- return NULL;
-
- info = GetWavinfo (s->name, data, fs_filesize);
- // Stereo sounds are 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;
- }
-
- // calculate resampled length
- len = (int) ((double) info.samples * (double) shm->speed / (double) info.rate);
- 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)
- {
- Con_Printf("failed to allocate memory for sound \"%s\"\n", s->name);
- Mem_FreePool(&s->mempool);
- 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(sc, data + info.dataofs, s->name);
-
- Mem_Free(data);
- return sc;
-}
-
-