char *CAudioSourceMP3Cache::GetDataPointer( void )
{
	char *pData = (char *)Cache_Check( &m_cache );
	if ( !pData )
		CacheLoad();
	return (char *)Cache_Check( &m_cache );
}
Exemplo n.º 2
0
/*
 * ==============
 * Cache_AllocPadded
 * ==============
 */
void *
Cache_AllocPadded(cache_user_t *c, int pad, int size, const char *name)
{
    cache_system_t *cs;

    if (c->data)
	Sys_Error("%s: allready allocated", __func__);

    if (size <= 0)
	Sys_Error("%s: size %i", __func__, size);

    size = (size + pad + sizeof(cache_system_t) + 15) & ~15;

    /* find memory for it */
    while (1) {
	cs = Cache_TryAlloc(size, false);
	if (cs) {
	    strncpy(cs->name, name, sizeof(cs->name) - 1);
	    cs->user = c;
	    c->pad = pad;
	    c->data = Cache_Data(cs);
	    break;
	}
	/* free the least recently used cache data */
	if (cache_head.lru_prev == &cache_head)
	    Sys_Error("%s: out of memory", __func__);
	/* not enough memory at all */
	Cache_Free(cache_head.lru_prev->user);
    }

    return Cache_Check(c);
}
Exemplo n.º 3
0
/*
==============
Cache_Alloc
==============
*/
void *Cache_Alloc (cache_user_t *c, int size, const char *name)
{
	cache_system_t	*cs;

	if (c->data)
		Sys_Error ("Cache_Alloc: already allocated");
	
	if (size <= 0)
		Sys_Error ("Cache_Alloc: size %i", size);

	size = (size + sizeof(cache_system_t) + 15) & ~15;

// find memory for it	
	while (1)
	{
		cs = Cache_TryAlloc (size, false);
		if (cs)
		{
			Q_strncpy(cs->name, name, sizeof(cs->name));
			c->data = (void *)(cs+1);
			cs->user = c;
			break;
		}

	// free the least recently used entry
		// assume if it's a locked entry that we've run out.
		if (cache_head.lru_prev == &cache_head || cache_head.lru_prev->locked)
			Sys_Error ("Cache_Alloc: out of memory");
		
		Cache_Free ( cache_head.lru_prev->user );
	}
	
	return Cache_Check (c);
}
Exemplo n.º 4
0
/*
==============
Cache_Alloc
==============
*/
void *Cache_Alloc (cache_user_t *c, int size, const char *name)
{
	cache_system_t	*cs;

	if (c->data)
		Sys_Error ("%s: %s is already allocated", __thisfunc__, name);

	if (size <= 0)
		Sys_Error ("%s: bad size %i for %s", __thisfunc__, size, name);

	size = (size + sizeof(cache_system_t) + 15) & ~15;

// find memory for it
	while (1)
	{
		cs = Cache_TryAlloc (size, false);
		if (cs)
		{
			q_strlcpy (cs->name, name, CACHENAME_LEN);
			c->data = (void *)(cs + 1);
			cs->user = c;
			break;
		}

	// free the least recently used cahedat
		if (cache_head.lru_prev == &cache_head)	// not enough memory at all
			Sys_Error ("%s: out of memory", __thisfunc__);
		Cache_Free ( cache_head.lru_prev->user );
	}

	return Cache_Check (c);
}
Exemplo n.º 5
0
Arquivo: zone.cpp Projeto: m4c0/Quake
/*
==============
Cache_Alloc
==============
*/
void *Cache_Alloc (cache_user_t *c, int size, const char *name)
{
	cache_system_t	*cs;

	if (c->data)
		Sys_Error ("Cache_Alloc: allready allocated");
	
	if (size <= 0)
		Sys_Error ("Cache_Alloc: size %i", size);

	size = (size + sizeof(cache_system_t) + 15) & ~15;

// find memory for it	
	while (1)
	{
		cs = Cache_TryAlloc (size, false);
		if (cs)
		{
			strncpy (cs->name, name, sizeof(cs->name)-1);
			c->data = (void *)(cs+1);
			cs->user = c;
			break;
		}
	
	// free the least recently used cahedat
		if (cache_head.lru_prev == &cache_head)
			Sys_Error ("Cache_Alloc: out of memory");
													// not enough memory at all
		Cache_Free ( cache_head.lru_prev->user );
	} 
	
	return Cache_Check (c);
}
Exemplo n.º 6
0
/*
==================
S_TouchSound

==================
*/
void S_TouchSound (char *name)
{
	sfx_t	*sfx;
	
	sfx = S_FindName (name);
	Cache_Check (&sfx->cache);
}
Exemplo n.º 7
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
	char	namebuffer[256];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	byte	stackbuf[1*1024];		// avoid dirtying the cache heap

// see if still in memory
	sc = (sfxcache_t *) Cache_Check (&s->cache);
	if (sc)
		return sc;

//	Con_Printf ("%s: %x\n", __thisfunc__, (int)stackbuf);

// load it in
	q_strlcpy(namebuffer, "sound/", sizeof(namebuffer));
	q_strlcat(namebuffer, s->name, sizeof(namebuffer));

//	Con_Printf ("loading %s\n",namebuffer);

	data = FS_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));

	if (!data)
	{
		Con_Printf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	info = GetWavinfo (s->name, data, fs_filesize);
	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;

	sc = (sfxcache_t *) Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
		return NULL;

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	return sc;
}
Exemplo n.º 8
0
/*
================
ResampleSfx
================
*/
void ResampleSfx(sfx_t *sfx, int inrate, int inwidth, byte *data)
{
    int		outcount;
    int		srcsample;
    float	stepscale;
    int		i;
    int		sample, samplefrac, fracstep;
    sfxcache_t	*sc;

    sc = Cache_Check(&sfx->cache);
    if (!sc) {
        return;
    }

    stepscale = (float)inrate / shm->speed;	// this is usually 0.5, 1, or 2

    outcount = sc->length / stepscale;
    sc->length = outcount;
    if (sc->loopstart != -1) {
        sc->loopstart = sc->loopstart / stepscale;
    }

    sc->speed = shm->speed;
    if (loadas8bit.value) {
        sc->width = 1;
    } else {
        sc->width = inwidth;
    }
    sc->stereo = 0;

// resample / decimate to the current source rate

    if (stepscale == 1 && inwidth == 1 && sc->width == 1) {
// fast special case
        for (i=0 ; i<outcount ; i++)
            ((signed char *)sc->data)[i]
            = (int)((unsigned char)(data[i]) - 128);
    } else {
// general case
        samplefrac = 0;
        fracstep = stepscale*256;
        for (i=0 ; i<outcount ; i++) {
            srcsample = samplefrac >> 8;
            samplefrac += fracstep;
            if (inwidth == 2) {
                sample = LittleShort(((short *)data)[srcsample]);
            } else {
                sample = (int)((unsigned char)(data[srcsample]) - 128) << 8;
            }
            if (sc->width == 2) {
                ((short *)sc->data)[i] = sample;
            } else {
                ((signed char *)sc->data)[i] = sample >> 8;
            }
        }
    }
}
Exemplo n.º 9
0
/*
==================
S_TouchSound

==================
*/
void S_TouchSound (char *name)
{
	sfx_t	*sfx;
	
	if (!sound_started)
		return;

	sfx = S_FindName (name);
	Cache_Check (&sfx->cache);
}
Exemplo n.º 10
0
bool CAudioSourceMP3Cache::IsCached( void )
{
	if ( m_cache.data )
	{
		if ( Cache_Check( &m_cache ) != NULL )
			return true;
	}

	return false;
}
Exemplo n.º 11
0
/*
==================
Mod_TouchModel

==================
*/
void Mod_TouchModel (char *name)
{
    model_t	*mod;

    mod = Mod_FindName (name);

    if (!mod->needload)
    {
        if (mod->type == mod_alias)
            Cache_Check (&mod->cache);
    }
}
Exemplo n.º 12
0
/* <99d0> ../engine/com_custom.c:19 */
void COM_ClearCustomizationList(customization_t *pHead, qboolean bCleanDecals)
{
	customization_s *pCurrent, *pNext;
	cachewad_t *pWad;
	cachepic_t *pic;

	pCurrent = pHead->pNext;
	if (!pCurrent)
		return;

	while (pCurrent)
	{
		pNext = pCurrent->pNext;

		if (pCurrent->bInUse)
		{
			if (pCurrent->pBuffer)
				Mem_Free(pCurrent->pBuffer);

			if (pCurrent->pInfo)
			{
				if (pCurrent->resource.type == t_decal)
				{
					if (bCleanDecals && g_pcls.state == ca_active)
					{
						R_DecalRemoveAll(-1 - pCurrent->resource.playernum);
					}

					pWad = (cachewad_t *)pCurrent->pInfo;

					Mem_Free(pWad->lumps);

					for (int i = 0; i < pWad->cacheCount; i++)
					{
						pic = &pWad->cache[i];
						if (Cache_Check(&pic->cache))
							Cache_Free(&pic->cache);
					}

					Mem_Free(pWad->name);
					Mem_Free(pWad->cache);
				}

				Mem_Free(pCurrent->pInfo);
			}
		}

		Mem_Free(pCurrent);
		pCurrent = pNext;
	}

	pHead->pNext = NULL;
}
Exemplo n.º 13
0
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char		namebuffer[512];
	wavinfo_t	info;
	int			len;
	float		stepscale;
	sfxcache_t	*sc;

	// see if still in memory
	sc = (sfxcache_t*)Cache_Check(&s->cache);
	if(sc)
		return sc;

	// load it in
	strncpy(namebuffer, g_state.cSoundPath, sizeof(namebuffer));
	strcat(namebuffer, s->name);

	uint8_t *data = (uint8_t*)COM_LoadHeapFile(namebuffer);
	if (!data)
	{
		Con_Warning("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	info = GetWavinfo (s->name, data, com_filesize);

	stepscale = (float)info.rate / shm->speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t*)Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
	{
		free(data);
		return NULL;
	}

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	free(data);

	return sc;
}
Exemplo n.º 14
0
/*
===============
Mod_Init

Caches the data if needed
===============
*/
void *Mod_Extradata (model_t *mod)
{
    void	*r;

    r = Cache_Check (&mod->cache);
    if (r)
        return r;

    Mod_LoadModel (mod, true);

    if (!mod->cache.data)
        Sys_Error ("Mod_Extradata: caching failed");
    return mod->cache.data;
}
Exemplo n.º 15
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char	namebuffer[256];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	fs_offset_t filesize;

// see if still in memory
	sc = Cache_Check (&s->cache);
	if (sc)
		return sc;

// load it in
    strcpy (namebuffer, "sound/");
    strcat (namebuffer, s->name);

	data = FS_LoadFile (namebuffer, false, &filesize);
	if (!data)
		return NULL;

	info = GetWavinfo (s->name, data, filesize);
	if (info.channels != 1)
	{
		Com_Printf ("%s is a stereo sample\n",s->name);
		return NULL;
	}

	stepscale = (float)info.rate / dma.speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t *) Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
		return NULL;

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	return sc;
}
Exemplo n.º 16
0
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char		namebuffer[512];
	byte		*data;
	wavinfo_t	info;
	int			len;
	float		stepscale;
	sfxcache_t	*sc;
	byte		stackbuf[1*1024];		// avoid dirtying the cache heap

	// see if still in memory
	sc = (sfxcache_t*)Cache_Check(&s->cache);
	if(sc)
		return sc;

	// load it in
	Q_strcpy(namebuffer,Global.cSoundPath);
    Q_strcat(namebuffer,s->name);

	data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));
	if (!data)
	{
		Con_Warning("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	info = GetWavinfo (s->name, data, com_filesize);

	stepscale = (float)info.rate / shm->speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t*)Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
		return NULL;

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	return sc;
}
Exemplo n.º 17
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte *Skin_Cache (skin_t *skin)
{
	int		y;
	byte	*pic, *out, *pix;
	int		width, height;
	char	name[MAX_OSPATH];

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//
	Q_snprintf (name, sizeof(name), "skins/%s", skin->name);
	pic = Image_LoadImage (name, &width, &height);
	if (!pic || width > 320 || height > 200)
	{
		if (pic)
			Q_free (pic);

		skin->failedload = true;
		Com_DPrintf ("Couldn't load skin %s\n", name);
		return NULL;
	}

	out = pix = Cache_Alloc (&skin->cache, 320*200, skin->name);
	if (!out)
		Sys_Error ("Skin_Cache: couldn't allocate");

	memset (out, 0, 320*200);
	for (y=0 ; y<height ; y++, pix += 320)
		memcpy (pix, pic + y*width, width);

	Q_free (pic);

	skin->failedload = false;

	return out;
}
Exemplo n.º 18
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte *
Skin_Cache ( skin_t *skin )
{
	char	name[1024];
//	byte	*raw;
	byte	*out;//, *pix;
//	pcx_t	*pcx;
//	int		x, y;
//	int		dataByte;
//	int		runLength;

	if (cls.downloadtype == dl_skin)
		return NULL;		// use base until downloaded

	if (noskins->value==1)	// JACK: So NOSKINS > 1 will show skins, but
		return NULL;		// not download new ones.

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//

	snprintf(name, sizeof(name), "skins/%s.pcx", skin->name);
	out = LoadPCX (name, &skin->cache, 320, 200);
	if (out == NULL) {
		Con_Printf ("Couldn't load skin %s\n", name);
		snprintf(name, sizeof(name), "skins/%s.pcx", baseskin->string);
		out = LoadPCX (name, &skin->cache, 320, 200);
		if (out == NULL) {
			skin->failedload = true;
			return NULL;
		}
	}

	skin->failedload = false;
	return out;
}
Exemplo n.º 19
0
/*
==================
Mod_FindName

==================
*/
model_t *Mod_FindName (char *name)
{
	int		i;
	model_t	*mod;
	model_t	*avail = NULL;

	if (!name[0])
		Sys_Error ("Mod_ForName: NULL name");
		
//
// search the currently loaded models
//
	for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
	{
		if (!strcmp (mod->name, name) )
			break;
		if (mod->needload == NL_UNREFERENCED)
			if (!avail || mod->type != mod_alias)
				avail = mod;
	}
			
	if (i == mod_numknown)
	{
		if (mod_numknown == MAX_MOD_KNOWN)
		{
			if (avail)
			{
				mod = avail;
				if (mod->type == mod_alias)
					if (Cache_Check (&mod->cache))
						Cache_Free (&mod->cache);
			}
			else
				Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
		}
		else
			mod_numknown++;
		strcpy (mod->name, name);
		mod->needload = NL_NEEDS_LOADED;
	}

	return mod;
}
Exemplo n.º 20
0
static void S_SoundList_f (void)
{
	int i, total = 0;
	unsigned int size;
	sfx_t *sfx;
	sfxcache_t *sc;

	for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) {
		sc = (sfxcache_t *) Cache_Check (&sfx->cache);
		if (!sc)
			continue;
		size = sc->total_length * sc->format.width * (sc->format.channels);
		total += size;
		if (sc->loopstart >= 0)
			Com_Printf ("L");
		else
			Com_Printf (" ");
		Com_Printf ("(%2db) %6i : %s\n",sc->format.width*8,  size, sfx->name);
	}
	Com_Printf ("Total resident: %i\n", total);
}
Exemplo n.º 21
0
void S_SoundList(void)
{
	int		i;
	sfx_t	*sfx;
	sfxcache_t	*sc;
	int		size, total;

	total = 0;
	for (sfx=known_sfx, i=0 ; i<num_sfx ; i++, sfx++)
	{
		sc = Cache_Check (&sfx->cache);
		if (!sc)
			continue;
		size = sc->length*sc->width*(sc->stereo+1);
		total += size;
		if (sc->loopstart >= 0)
			Con_Printf ("L");
		else
			Con_Printf (" ");
		Con_Printf("(%2db) %6i : %s\n",sc->width*8,  size, sfx->name);
	}
	Con_Printf ("Total resident: %i\n", total);
}
Exemplo n.º 22
0
static void S_SoundList (void)
{
	int		i;
	sfx_t	*sfx;
	sfxcache_t	*sc;
	int		size, total;

	total = 0;
	for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++)
	{
		sc = (sfxcache_t *) Cache_Check (&sfx->cache);
		if (!sc)
			continue;
		size = sc->length*sc->width*(sc->stereo + 1);
		total += size;
		if (sc->loopstart >= 0)
			Con_SafePrintf ("L"); //johnfitz -- was Con_Printf
		else
			Con_SafePrintf (" "); //johnfitz -- was Con_Printf
		Con_SafePrintf("(%2db) %6i : %s\n", sc->width*8, size, sfx->name); //johnfitz -- was Con_Printf
	}
	Con_Printf ("%i sounds, %i bytes\n", num_sfx, total); //johnfitz -- added count
}
Exemplo n.º 23
0
/* <83669> ../engine/r_studio.c:663 */
mstudioanim_t *R_GetAnim(model_t *psubmodel, mstudioseqdesc_t *pseqdesc)
{
	mstudioseqgroup_t *pseqgroup;
	cache_user_t *paSequences;

	pseqgroup = (mstudioseqgroup_t *)((char *)pstudiohdr + pstudiohdr->seqgroupindex);
	pseqgroup += pseqdesc->seqgroup;
	if (!pseqdesc->seqgroup)
		return (mstudioanim_t *)((char *)pstudiohdr + pseqdesc->animindex);

	paSequences = (cache_user_t *)psubmodel->submodels;
	if (!paSequences)
	{
		paSequences = (cache_user_t *)Mem_Calloc(16, 4);
		psubmodel->submodels = (dmodel_t *)paSequences;
	}
	if (!Cache_Check(&paSequences[pseqdesc->seqgroup]))
	{
		Con_DPrintf("loading %s\n", pseqgroup->name);
		COM_LoadCacheFile(pseqgroup->name, &paSequences[pseqdesc->seqgroup]);
	}

	return (mstudioanim_t *)((char *)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex);
}
Exemplo n.º 24
0
sfxcache_t *S_LoadSound(sfx_t *s)
{
	char namebuffer[MAX_OSPATH];
	char extionless[MAX_OSPATH];
	sfxcache_t *sc = NULL;
	int eof = 0;
	int current_section;
	vfsfile_t *f;
	OggVorbis_File oggfile;
	vorbis_info *ogginfo;
	ov_callbacks ovc = {
		vorbis_callback_read,
		vorbis_callback_seek,
		vorbis_callback_close,
		vorbis_callback_tell
	};
	static char pcmbuff[4096];
	
	//unsigned char *data;
	wavinfo_t info;
	int len;
	//int filesize;

	// see if still in memory
	if ((sc = (sfxcache_t *) Cache_Check (&s->cache)))
		return sc;

	if (!vorbis_CheckActive())
		vorbis_LoadLibrary();

	// load it in
	COM_StripExtension(s->name, extionless);
	snprintf (namebuffer, sizeof (namebuffer), "sound/%s.ogg", extionless);

/*	if (!(data = FS_LoadTempFile (namebuffer, &filesize))) {
		Com_Printf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}*/

	if (!(f = FS_OpenVFS(namebuffer, "rb", FS_ANY))) {
		Com_Printf("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	if (qov_open_callbacks(f, &oggfile, NULL, 0, ovc)) {
		Com_Printf("Invalid sound file %s\n", namebuffer);
		VFS_CLOSE(f);
		return NULL;
	}
	if (!(ogginfo = qov_info(&oggfile,-1))) {
		Com_Printf("Unable to retrieve information for %s\n", namebuffer);
		goto fail;
	}

	/* Print some information */
	fprintf(stderr, "%s\n", namebuffer);
	{
		char **ptr = qov_comment(&oggfile,-1)->user_comments;
		while(*ptr){
			fprintf(stderr,"%s\n",*ptr);
			++ptr;
		}
		fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",
				ogginfo->channels, ogginfo->rate);
		fprintf(stderr,"\nDecoded length: %ld samples\n",
				(long) qov_pcm_total(&oggfile,-1));
		fprintf(stderr,"Encoded by: %s\n\n", qov_comment(&oggfile,-1)->vendor);
	}

	info.rate = ogginfo->rate;			// Frequency rate
	info.width = 1;						// 8 bit samples
	info.channels = ogginfo->channels;	// 1 == mono, 2 == stereo
	info.loopstart = -1;				// NOOO idea...
	info.samples = qov_pcm_total(&oggfile,-1);	// Total samples
	info.dataofs = 0;					// offset

	
	//FMod_CheckModel(namebuffer, data, filesize);

	//info = GetWavinfo (s->name, data, filesize);

	// Stereo sounds are allowed (intended for music)
	if (info.channels < 1 || info.channels > 2) {
		Com_Printf("%s has an unsupported number of channels (%i)\n",s->name, info.channels);
		return NULL;
	}

	len = (int) ((double) info.samples * (double) shm->format.speed / (double) info.rate);
	len = len * info.width * info.channels;

	if (!(sc = (sfxcache_t *) Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name)))
		return NULL;

	/* Read the whole Ogg Vorbis file in */
	byte *output = sc->data;
	while (!eof) {
		// 0 == little endian, 1 = big endian
		// 1 == 8 bit samples, 2 = 16 bit samples
		// 1 == signed samples
		long ret = qov_read(&oggfile, pcmbuff, sizeof(pcmbuff), 
				0, info.width, 1, &current_section);
		if (ret == 0) {
			eof = 1;
		} else if (ret < 0) {
			/* error in the stream. Not a problem, just reporting it in
			 * case we (the app) cares. In this case, we don't. */
		} else {
			/* we don't bother dealing with sample rate changes, etc, but
			 * you'll have to */
			memcpy(output, pcmbuff, ret);
			output += ret;
		}
	}
	qov_clear(&oggfile);

	sc->total_length = (unsigned int) info.samples;
	sc->format.speed = info.rate;
	sc->format.width = info.width;
	sc->format.channels = info.channels;
	if (info.loopstart < 0)
		sc->loopstart = -1;
	else
		sc->loopstart = (int)((double)info.loopstart * (double)shm->format.speed / (double)sc->format.speed);

//	ResampleSfx (s, data + info.dataofs, info.samples, &sc->format, sc->data);
	return sc;

fail:
	qov_clear(&oggfile); // Only goto fail if ov_open* succeded
	if (f) {
		VFS_CLOSE(f);
	}
	return NULL;
}
Exemplo n.º 25
0
/*
==================
Mod_LoadModel

Loads a model into the cache
==================
*/
model_t *Mod_LoadModel (model_t *mod, qboolean crash)
{
    void	*d;
    unsigned *buf;
    byte	stackbuf[1024];		// avoid dirtying the cache heap

    if (!mod->needload)
    {
        if (mod->type == mod_alias)
        {
            d = Cache_Check (&mod->cache);
            if (d)
                return mod;
        }
        else
            return mod;		// not cached at all
    }

//
// because the world is so huge, load it one piece at a time
//
    if (!crash)
    {

    }

//
// load the file
//
    buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
    if (!buf)
    {
        if (crash)
            Sys_Error ("Mod_NumForName: %s not found", mod->name);
        return NULL;
    }

//
// allocate a new model
//
    COM_FileBase (mod->name, loadname);

    loadmodel = mod;

//
// fill it in
//

// call the apropriate loader
    mod->needload = false;

    switch (LittleLong(*(unsigned *)buf))
    {
    case IDPOLYHEADER:
        Mod_LoadAliasModel (mod, buf);
        break;

    case IDSPRITEHEADER:
        Mod_LoadSpriteModel (mod, buf);
        break;

    default:
        Mod_LoadBrushModel (mod, buf);
        break;
    }

    return mod;
}
Exemplo n.º 26
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound(sfx_t *s)
{
    char	namebuffer[256];
    byte	*data;
    wavinfo_t	info;
    int		len;
    float	stepscale;
    sfxcache_t	*sc;
    byte	stackbuf[1*1024];		// avoid dirtying the cache heap
    loadedfile_t	*fileinfo;	// 2001-09-12 Returning information about loaded file by Maddes

// see if still in memory
    sc = Cache_Check(&s->cache);
    if (sc) {
        return sc;
    }

//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
    Q_strcpy(namebuffer, "sound/");
    Q_strcat(namebuffer, s->name);

    if (developer.value == 1) {
        Con_DPrintf("Loading %s\n",namebuffer);    // Edited
    }
//	Con_Printf ("loading %s\n",namebuffer);

// 2001-09-12 Returning information about loaded file by Maddes  start
    /*
    	data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));

    	if (!data)
    */
    fileinfo = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));
    if (!fileinfo)
// 2001-09-12 Returning information about loaded file by Maddes  end
    {
        Con_Printf("Couldn't load %s\n", namebuffer);
        return NULL;
    }
    data = fileinfo->data;	// 2001-09-12 Returning information about loaded file by Maddes

    info = GetWavinfo(s->name, data, com_filesize);
    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;

    sc = Cache_Alloc(&s->cache, len + sizeof(sfxcache_t), s->name);
    if (!sc) {
        return NULL;
    }

    sc->length = info.samples;
    sc->loopstart = info.loopstart;
    sc->speed = info.rate;
    sc->width = info.width;
    sc->stereo = info.channels;

    ResampleSfx(s, sc->speed, sc->width, data + info.dataofs);

    return sc;
}
Exemplo n.º 27
0
sfxbuffer_t *
SND_CacheTouch (sfx_t *sfx)
{
	return Cache_Check (&sfx->data.block->cache);
}
Exemplo n.º 28
0
// Returns a pointer to the skin bitmap, or NULL to use the default
byte *Skin_Cache (skin_t *skin, qbool no_baseskin) 
{
	int y, max_w, max_h, bpp, real_width = -1, real_height = -1;
	byte *pic = NULL, *out, *pix;
	char name[MAX_OSPATH];

	if (noskins.value == 1) // JACK: So NOSKINS > 1 will show skins, but
		return NULL;		// not download new ones.

	if (skin->failedload)
		return NULL;

	if ((out = (byte *) Cache_Check (&skin->cache)))
		return out;

	// not cached, load from HDD

	snprintf (name, sizeof(name), "skins/%s.pcx", skin->name);

	if (!(pic = Skin_PixelsLoad(name, &max_w, &max_h, &bpp, &real_width, &real_height)) || real_width > max_w || real_height > max_h) 
	{
		Q_free(pic);

		if (no_baseskin) 
		{
			skin->warned = true;
			return NULL; // well, we not set skin->failedload = true, that how I need it here
		}
		else if (!skin->warned)
		{
			Com_Printf ("&cf22Couldn't load skin:&r %s\n", name);
		}

		skin->warned = true;
	}

	if (!pic) 
	{ 
		// Attempt load at least default/base.
		snprintf (name, sizeof(name), "skins/%s.pcx", baseskin.string);

		if (!(pic = Skin_PixelsLoad(name, &max_w, &max_h, &bpp, &real_width, &real_height)) || real_width > max_w || real_height > max_h) 
		{
			Q_free(pic);
			skin->failedload = true;
			return NULL;
		}
	}

	if (!(out = pix = (byte *) Cache_Alloc (&skin->cache, max_w * max_h * bpp, skin->name)))
		Sys_Error ("Skin_Cache: couldn't allocate");

	memset (out, 0, max_w * max_h * bpp);
	for (y = 0; y < real_height; y++, pix += (max_w * bpp))
	{
		memcpy (pix, pic + y * real_width * bpp, real_width * bpp);
	}

	Q_free (pic);
	skin->bpp 	 = bpp;
	skin->width	 = real_width;
	skin->height = real_height;

	// load 32bit skin ASAP, so later we not affected by Cache changes, actually we don't need cache for 32bit skins at all
	//	skin->texnum = (bpp != 1) ? GL_LoadTexture (skin->name, skin->width, skin->height, pix, TEX_MIPMAP | TEX_NOSCALE, bpp) : 0;
	// FIXME: Above line does't work, texture loaded wrong, seems I need set some global gl states, but I dunno which,
	// so moved it to R_TranslatePlayerSkin() and here set texture to 0
	skin->texnum = 0;
	skin->failedload = false;

	return out;
}
Exemplo n.º 29
0
/*
==================
Mod_LoadModel

Loads a model into the cache
==================
*/
model_t *Mod_LoadModel (model_t *mod, qboolean crash)
{
	unsigned *buf;
// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Deferring allocation. Stack in this device is pretty small:
	//byte	stackbuf[1024];		// avoid dirtying the cache heap
	byte*	stackbuf;		// avoid dirtying the cache heap
// <<< FIX

	if (mod->type == mod_alias)
	{
		if (Cache_Check (&mod->cache))
		{
			mod->needload = NL_PRESENT;
			return mod;
		}
	}
	else
	{
		if (mod->needload == NL_PRESENT)
			return mod;
	}

//
// because the world is so huge, load it one piece at a time
//
	
//
// load the file
//
// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Allocating for previous fixes (and, this time, expanding the allocated size), in big stack:
	stackbuf = Sys_BigStackAlloc(4096 * sizeof(byte), "Mod_LoadModel");
// <<< FIX
// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Adjusting for previous fix:
	//buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
	buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, 4096);
// <<< FIX
	if (!buf)
	{
		if (crash)
			Sys_Error ("Mod_NumForName: %s not found", mod->name);
// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Deallocating from previous fixes:
		Sys_BigStackFree(4096 * sizeof(byte), "Mod_LoadModel");
// <<< FIX
		return NULL;
	}
	
//
// allocate a new model
//
	COM_FileBase (mod->name, loadname);
	
	loadmodel = mod;

//
// fill it in
//

// call the apropriate loader
	mod->needload = NL_PRESENT;

	switch (LittleLong(*(unsigned *)buf))
	{
	case IDPOLYHEADER:
		Mod_LoadAliasModel (mod, buf);
		break;
		
	case IDSPRITEHEADER:
		Mod_LoadSpriteModel (mod, buf);
		break;
	
	default:
		Mod_LoadBrushModel (mod, buf);
		break;
	}

// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Deallocating from previous fixes:
	Sys_BigStackFree(4096 * sizeof(byte), "Mod_LoadModel");
// <<< FIX

	return mod;
}
Exemplo n.º 30
0
/*
================
ResampleSfx
================
*/
static void
ResampleSfx(sfx_t *sfx, int inrate, int inwidth, const byte *data)
{
   int outcount;
   int srcsample;
   float stepscale;
   int i;
   int sample, samplefrac, fracstep;
   sfxcache_t *sc;

   sc = (sfxcache_t*)Cache_Check(&sfx->cache);
   if (!sc)
      return;

   stepscale = (float)inrate / shm->speed;	// this is usually 0.5, 1, or 2

   outcount = sc->length / stepscale;
   sc->length = outcount;
   if (sc->loopstart != -1)
      sc->loopstart = sc->loopstart / stepscale;

   sc->speed = shm->speed;
   sc->width = inwidth;
   sc->stereo = 1;

   // resample / decimate to the current source rate

   if (stepscale == 1/* && inwidth == 1*/ && sc->width == 1)
   {
      // fast special case
      for (i = 0; i < outcount; i++)
         ((signed char *)sc->data)[i]
         = (int)((unsigned char)(data[i]) - 128);
   }
   else if (stepscale == 1/* && inwidth == 2*/ && sc->width == 2) // LordHavoc: quick case for 16bit
	{
		if (sc->stereo) // LordHavoc: stereo sound support
			for (i=0 ; i<outcount*2 ;i++)
				((short *)sc->data)[i] = LittleShort (((short *)data)[i]);
		else
			for (i=0 ; i<outcount ;i++)
				((short *)sc->data)[i] = LittleShort (((short *)data)[i]);
	}
   else
   {
      // general case
      samplefrac = 0;
      fracstep = stepscale * 256;
      for (i = 0; i < outcount; i++)
      {
         srcsample = samplefrac >> 8;
         samplefrac += fracstep;
         if (inwidth == 2)
         {
#ifdef MSB_FIRST
            sample = LittleShort(((const short *)data)[srcsample]);
#else
            sample = (((const short *)data)[srcsample]);
#endif
         }
         else
            sample = (int)((unsigned char)(data[srcsample]) - 128) << 8;
         if (sc->width == 2)
            ((short *)sc->data)[i] = sample;
         else
            ((signed char *)sc->data)[i] = sample >> 8;
      }
   }
}