/** * @brief Loads and registers a sound file for later use * @param[in] soundFile The name of the soundfile, relative to the sounds dir * @return The index of the loaded sample or 0 * @sa S_LoadSound */ int S_LoadSampleIdx (const char *soundFile) { Mix_Chunk *chunk; s_sample_t *sample; char name[MAX_QPATH]; unsigned hash; if (!s_env.initialized) return 0; Com_StripExtension(soundFile, name, sizeof(name)); sample = S_FindByName(name); if (sample) return sample->index; /* make sure the sound is loaded */ chunk = S_LoadSampleChunk(name); if (!chunk) return 0; /* couldn't load the sound's data */ hash = Com_HashKey(name, SAMPLE_HASH_SIZE); sample = (s_sample_t *)Mem_PoolAlloc(sizeof(*sample), cl_soundSysPool, 0); sample->name = Mem_PoolStrDup(name, cl_soundSysPool, 0); sample->chunk = chunk; sample->hashNext = sampleHash[hash]; sampleHash[hash] = sample; sampleIndex[++sampleIndexLast] = sample; sample->index = sampleIndexLast; return sample->index; }
/* * @brief */ s_sample_t *S_LoadSample(const char *name) { char key[MAX_QPATH]; s_sample_t *sample; if (!s_env.initialized) return NULL; if (!name || !name[0]) { Com_Error(ERR_DROP, "NULL name\n"); } StripExtension(name, key); if (!(sample = (s_sample_t *) S_FindMedia(key))) { sample = (s_sample_t *) S_AllocMedia(key, sizeof(s_sample_t)); sample->media.Free = S_FreeSample; S_LoadSampleChunk(sample); S_RegisterMedia((s_media_t *) sample); } return sample; }