-/*
-==============
-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;
-
- // Don't try to load it if it's not a WAV file
- if (memcmp (data, "RIFF", 4) || memcmp (data + 8, "WAVE", 4))
- 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;
-
- 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;
-
-#if BYTE_ORDER != LITTLE_ENDIAN
- // We must convert the WAV data from little endian
- // to the machine endianess before resampling it
- if (info.width == 2)
- {
- int i;
- short* ptr;
-
- len = info.samples * info.channels;
- ptr = (short*)(data + info.dataofs);
- for (i = 0; i < len; i++)
- ptr[i] = LittleShort (ptr[i]);
- }
-#endif
-
- ResampleSfx(sc, data + info.dataofs, s->name);
-
- Mem_Free(data);
- return sc;
-}
-
-