void SND_setup() { sndBuffer *p, *q; cvar_t * cv; int scs; cv = Cvar_Get("com_soundMegs", DEF_COMSOUNDMEGS, CVAR_LATCH | CVAR_ARCHIVE); scs = (cv->integer * 1536); buffer = (sndBuffer *)malloc(scs * sizeof(sndBuffer)); // allocate the stack based hunk allocator sfxScratchBuffer = (short *)malloc(SND_CHUNK_SIZE * sizeof(short) * 4); //Hunk_Alloc(SND_CHUNK_SIZE * sizeof(short) * 4); sfxScratchPointer = NULL; inUse = scs * sizeof(sndBuffer); p = buffer;; q = p + scs; while (--q > p) { *(sndBuffer **)q = q - 1; } *(sndBuffer **)q = NULL; freelist = p + scs - 1; Com_Printf("Sound memory manager started\n"); }
sndBuffer *SND_malloc() { sndBuffer *v; redo: if (freelist == NULL) { S_FreeOldestSound(); goto redo; } inUse -= sizeof(sndBuffer); totalInUse += sizeof(sndBuffer); v = freelist; freelist = *(sndBuffer **)freelist; v->next = NULL; return(v); }
void SND_free(sndBuffer *v) { *(sndBuffer **)v = freelist; freelist = (sndBuffer *)v; inUse += sizeof(sndBuffer); }