예제 #1
0
파일: snd_mem.c 프로젝트: TimeDoctor/ioq3
/*
==============
S_LoadSound

The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
qboolean S_LoadSound( sfx_t *sfx )
{
	byte	*data;
	short	*samples;
	snd_info_t	info;
//	int		size;

	// load it in
	data = S_CodecLoad(sfx->soundName, &info);
	if(!data)
		return qfalse;

	if ( info.width == 1 ) {
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit audio file\n", sfx->soundName);
	}

	if ( info.rate != 22050 ) {
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz audio file\n", sfx->soundName);
	}

	samples = Hunk_AllocateTempMemory(info.channels * info.samples * sizeof(short) * 2);

	sfx->lastTimeUsed = Com_Milliseconds()+1;

	// each of these compression schemes works just fine
	// but the 16bit quality is much nicer and with a local
	// install assured we can rely upon the sound memory
	// manager to do the right thing for us and page
	// sound in as needed

	if( info.channels == 1 && sfx->soundCompressed == qtrue) {
		sfx->soundCompressionMethod = 1;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.channels, info.rate, info.width, info.samples, data + info.dataofs );
		S_AdpcmEncodeSound(sfx, samples);
#if 0
	} else if (info.channels == 1 && info.samples>(SND_CHUNK_SIZE*16) && info.width >1) {
		sfx->soundCompressionMethod = 3;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.channels, info.rate, info.width, info.samples, (data + info.dataofs) );
		encodeMuLaw( sfx, samples);
	} else if (info.channels == 1 && info.samples>(SND_CHUNK_SIZE*6400) && info.width >1) {
		sfx->soundCompressionMethod = 2;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.channels, info.rate, info.width, info.samples, (data + info.dataofs) );
		encodeWavelet( sfx, samples);
#endif
	} else {
		sfx->soundCompressionMethod = 0;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfx( sfx, info.channels, info.rate, info.width, info.samples, data + info.dataofs, qfalse );
	}

	sfx->soundChannels = info.channels;
	
	Hunk_FreeTempMemory(samples);
	Hunk_FreeTempMemory(data);

	return qtrue;
}
예제 #2
0
파일: snd_mem.cpp 프로젝트: DaTa-/cnq3x
qbool S_LoadSound( sfx_t* sfx )
{
	// player specific sounds are never directly loaded
	if (sfx->soundName[0] == '*') {
		return qfalse;
	}

	snd_info_t info;
	byte* data = S_CodecLoad( sfx->soundName, &info );
	if (!data)
		return qfalse;

	if ( info.width == 1 ) {
		Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName );
	}

	if ( info.rate != 22050 ) {
		Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName );
	}

	sfx->lastTimeUsed = Com_Milliseconds();

	sfx->soundLength = info.samples;
	sfx->soundData = NULL;
	ResampleSfx( sfx, info.rate, info.width, data + info.dataofs );

	Z_Free(data);

	return qtrue;
}
예제 #3
0
/*
==============
S_LoadSound

The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
bool S_LoadSound( sfx_t *sfx )
{
	byte	*data;
	short	*samples;
	wavinfo_t	info;
	int		size;

	// player specific sounds are never directly loaded
	if ( sfx->soundName[0] == '*')
		return false;

	// load it in
	size = FS_ReadFile( sfx->soundName, (void **)&data );
	if ( !data ) 
		return false;

	info = GetWavinfo( sfx->soundName, data, size );
	if ( info.channels != 1 ) 
	{
		Com_Printf ("%s is a stereo wav file\n", sfx->soundName);
		FS_FreeFile (data);
		return false;
	}

	if ( info.width == 1 ) 
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName);

	if ( info.rate != 22050 ) 
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName);

	samples = reinterpret_cast<short*>(Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2));

	sfx->lastTimeUsed = Com_Milliseconds()+1;

	// each of these compression schemes works just fine
	// but the 16bit quality is much nicer and with a local
	// install assured we can rely upon the sound memory
	// manager to do the right thing for us and page
	// sound in as needed

	if( sfx->soundCompressed == true) 
	{
		sfx->soundCompressionMethod = 1;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) );
		S_AdpcmEncodeSound(sfx, samples);
	} 
	else 
	{
		sfx->soundCompressionMethod = 0;
		sfx->soundLength = info.samples;
		sfx->soundData = NULL;
		ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, false );
	}
	
	Hunk_FreeTempMemory(samples);
	FS_FreeFile( data );

	return true;
}
예제 #4
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;
}
예제 #5
0
파일: snd_mem.cpp 프로젝트: DrLabman/QMB
/*
==============
S_LoadSound
==============
 */
sfxcache_t *S_LoadSound(sfx_t *s) {
    char namebuffer[256];
    byte *data;
    wavinfo_t info;
    int len;
    float stepscale;
    sfxcache_t *sc = NULL;
    byte stackbuf[1 * 1024]; // avoid dirtying the cache heap

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

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

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

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

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

    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;

    s->cache = MemoryObj::Alloc(MemoryObj::CACHE, s->name, len + sizeof (sfxcache_t));
    sc = (sfxcache_t *) s->cache->getData();
    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;
}
예제 #6
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;
}
예제 #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;
	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;
}
예제 #8
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;
}
예제 #9
0
파일: snd_mem.c 프로젝트: otty/cake3
/*
==============
S_LoadSound

The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
qboolean S_LoadSound(sfx_t * sfx)
{
	byte           *data;
	short          *samples;
	snd_info_t      info;

	// player specific sounds are never directly loaded
	if(sfx->soundName[0] == '*')
	{
		return qfalse;
	}

	// load it in
	data = S_CodecLoad(sfx->soundName, &info);
	if(!data)
		return qfalse;

	if(info.width == 1)
	{
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName);
	}

	if(info.rate != 22050)
	{
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName);
	}

	samples = Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2);

	sfx->lastTimeUsed = Com_Milliseconds() + 1;

	sfx->soundLength = info.samples;
	sfx->soundData = NULL;
	ResampleSfx(sfx, info.rate, info.width, data + info.dataofs, qfalse);

	Hunk_FreeTempMemory(samples);
	Z_Free(data);

	return qtrue;
}
예제 #10
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char	namebuffer[MAX_QPATH];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	int		size;
	char	*name;

	if (s->name[0] == '*')
		return NULL;

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

//Com_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
	if (s->truename)
		name = s->truename;
	else
		name = s->name;

	if (name[0] == '#')
		strcpy(namebuffer, &name[1]);
	else
		Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name);

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

	size = FS_LoadFile (namebuffer, (void **)&data);

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

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

	// jeyries : test, do not force 8 bit
	//s_loadas8bit->value = 0;

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

	// moved here to save sound memory
	if (s_loadas8bit->value)
		len = len * 1 * info.channels;
	else
		len = len * info.width * info.channels;


#if DEBUG_AUDIO
	Com_Printf ("loading %s : samples=%d width=%d rate=%d channels=%d memsize=%d\n",
			namebuffer, info.samples, info.width, info.rate, info.channels, len  );
#endif


	sc = s->cache = Z_Malloc (len + sizeof(sfxcache_t));
	if (!sc)
	{
		FS_FreeFile (data);
		return NULL;
	}
	
	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	//sc->width = info.width;
	sc->stereo = info.channels;

	// moved here to save sound memory
	if (s_loadas8bit->value)
		sc->width = 1;
	else
		sc->width = info.width;

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

	FS_FreeFile (data);

	return sc;
}
예제 #11
0
파일: snd_mem.c 프로젝트: Justasic/RTCW-MP
/*
==============
S_LoadSound

The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
qboolean S_LoadSound( sfx_t *sfx ) {
	byte    *data;
	short   *samples;
	wavinfo_t info;
	int size;

	// player specific sounds are never directly loaded
	if ( sfx->soundName[0] == '*' ) {
		return qfalse;
	}

	// load it in
	size = FS_ReadFile( sfx->soundName, (void **)&data );
	if ( !data ) {
		return qfalse;
	}

	info = GetWavinfo( sfx->soundName, data, size );
	if ( info.channels != 1 ) {
		Com_Printf( "%s is a stereo wav file\n", sfx->soundName );
		FS_FreeFile( data );
		return qfalse;
	}

	if ( info.width == 1 ) {
		Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName );
	}

	if ( info.rate != 22050 ) {
		Com_DPrintf( S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName );
	}

	samples = Hunk_AllocateTempMemory( info.samples * sizeof( short ) * 2 );

	// DHM - Nerve
	sfx->lastTimeUsed = Sys_Milliseconds() + 1;

	// each of these compression schemes works just fine
	// but the 16bit quality is much nicer and with a local
	// install assured we can rely upon the sound memory
	// manager to do the right thing for us and page
	// sound in as needed


	if ( s_nocompressed->value ) {
		sfx->soundCompressionMethod = 0;
		sfx->soundLength = info.samples;
		sfx->soundData = NULL;
		ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse );
	} else if ( sfx->soundCompressed == qtrue )     {
		sfx->soundCompressionMethod = 1;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) );
		S_AdpcmEncodeSound( sfx, samples );
#ifdef COMPRESSION
	} else if ( info.samples > ( SND_CHUNK_SIZE * 16 ) && info.width > 1 ) {
		sfx->soundCompressionMethod = 3;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) );
		encodeMuLaw( sfx, samples );
	} else if ( info.samples > ( SND_CHUNK_SIZE * 6400 ) && info.width > 1 ) {
		sfx->soundCompressionMethod = 2;
		sfx->soundData = NULL;
		sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, ( data + info.dataofs ) );
		encodeWavelet( sfx, samples );
#endif
	} else {
		sfx->soundCompressionMethod = 0;
		sfx->soundLength = info.samples;
		sfx->soundData = NULL;
		ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse );
	}
	Hunk_FreeTempMemory( samples );
	FS_FreeFile( data );

	return qtrue;
}
예제 #12
0
파일: snd_mem.c 프로젝트: mattx86/myq2
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char	namebuffer[MAX_QPATH];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	int		size;
	char	*name;

	if (s->name[0] == '*')
		return NULL;

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

//S_Printf(PRINT_ALL, "S_LoadSound: %x\n", (int)stackbuf);
// load it in
	if (s->truename)
		name = s->truename;
	else
		name = s->name;

	if (name[0] == '#')
		strcpy(namebuffer, &name[1]);
	else
		Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name);

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

	size = FS_LoadFile (namebuffer, (void **)&data);

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

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

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

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

	sc = s->cache = Z_Malloc (len + sizeof(sfxcache_t));
	if (!sc)
	{
		FS_FreeFile (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);

	FS_FreeFile (data);

	return sc;
}
예제 #13
0
/**
 * @brief The filename may be different than sfx->name in the case
 * of a forced fallback of a player specific sound
 * @param[in,out] sfx
 * @return
 */
qboolean S_LoadSound(sfx_t *sfx)
{
	byte       *data;
	short      *samples;
	snd_info_t info;

	// player specific sounds are never directly loaded
	if (sfx->soundName[0] == '*')
	{
		return qfalse;
	}

	if (FS_FOpenFileRead(sfx->soundName, NULL, qfalse) <= 0)
	{
		// changed from debug to common print - let admins know and fix such missing files ...
		Com_Printf(S_COLOR_RED "ERROR: sound file \"%s\" does not exist or can't be read\n", sfx->soundName);
		return qfalse;
	}

	// load it in
	data = S_CodecLoad(sfx->soundName, &info);
	if (!data)
	{
		return qfalse;
	}

	if (info.width == 1)
	{
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit audio file\n", sfx->soundName);
	}

	if ((info.rate != 11025) && (info.rate != 22050) && (info.rate != 44100))
	{
		Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 11kHz, 22kHz nor 44kHz audio file. It has sample rate %i\n", sfx->soundName, info.rate);
	}

	samples = Hunk_AllocateTempMemory(info.channels * info.samples * sizeof(short) * 2);

	sfx->lastTimeUsed = Sys_Milliseconds() + 1;

	// each of these compression schemes works just fine
	// but the 16bit quality is much nicer and with a local
	// install assured we can rely upon the sound memory
	// manager to do the right thing for us and page
	// sound in as needed

	if (info.channels == 1 && sfx->soundCompressed == qtrue)
	{
		sfx->soundCompressionMethod = 1;
		sfx->soundData              = NULL;
		sfx->soundLength            = ResampleSfxRaw(samples, info.channels, info.rate, info.width, info.samples, data + info.dataofs);
		S_AdpcmEncodeSound(sfx, samples);
#if 0
	}
	else if (info.channels == 1 && info.samples > (SND_CHUNK_SIZE * 16) && info.width > 1)
	{
		sfx->soundCompressionMethod = 3;
		sfx->soundData              = NULL;
		sfx->soundLength            = ResampleSfxRaw(samples, info.channels, info.rate, info.width, info.samples, (data + info.dataofs));
		encodeMuLaw(sfx, samples);
	}
	else if (info.channels == 1 && info.samples > (SND_CHUNK_SIZE * 6400) && info.width > 1)
	{
		sfx->soundCompressionMethod = 2;
		sfx->soundData              = NULL;
		sfx->soundLength            = ResampleSfxRaw(samples, info.channels, info.rate, info.width, info.samples, (data + info.dataofs));
		encodeWavelet(sfx, samples);
#endif
	}
	else
	{
		sfx->soundCompressionMethod = 0;
		sfx->soundLength            = info.samples;
		sfx->soundData              = NULL;
		sfx->soundLength            = ResampleSfx(sfx, info.channels, info.rate, info.width, info.samples, data + info.dataofs, qfalse);
	}
	sfx->soundChannels = info.channels;

	Hunk_FreeTempMemory(samples);
	Hunk_FreeTempMemory(data);

	return qtrue;
}
예제 #14
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;
}
예제 #15
0
파일: snd_mem.c 프로젝트: basecq/q2dos
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
	char	namebuffer[MAX_QPATH];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	int		size;
	const char	*name;

	if (s->name[0] == '*')
		return NULL;

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

// load it in
	name = (s->truename)? s->truename : s->name;
	if (name[0] == '#')
		Q_strncpyz(namebuffer, &name[1], sizeof(namebuffer));
	else
		Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name);

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

	size = FS_LoadFile (namebuffer, (void **)&data);

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

	info = GetWavinfo (s->name, data, size);
/*	if (info.channels != 1)
	{
		Com_Printf ("%s is a stereo sample\n",s->name);
		FS_FreeFile (data);
		return NULL;
	}*/
	if (info.channels < 1 || info.channels > 2)	//CDawg changed
	{
		Com_Printf ("%s has an invalid number of channels\n", s->name);
		FS_FreeFile (data);
		return NULL;
	}

	if (info.width != 1 && info.width != 2)
	{
		Com_Printf("%s is not 8 or 16 bit\n", s->name);
		FS_FreeFile (data);
		return NULL;
	}

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

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

	if (info.samples == 0 || len == 0)
	{
		Com_Printf("%s has zero samples\n", s->name);
		FS_FreeFile (data);
		return NULL;
	}

	sc = s->cache = Z_Malloc (len + sizeof(sfxcache_t));
	if (!sc)
	{
		FS_FreeFile (data);
		return NULL;
	}

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
//	sc->speed = info.rate;
	sc->speed = info.rate * info.channels;	//CDawg changed
	sc->width = info.width;
	sc->stereo = info.channels;

	// Knightmare: force loopstart if it's a music file
	if (!strncmp(namebuffer, "music/", 6) && (sc->loopstart == -1))
		sc->loopstart = 0;
	// end Knightmare

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

	FS_FreeFile (data);

	return sc;
}
예제 #16
0
파일: snd_mem.c 프로젝트: elhobbs/quake2dsi
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char	namebuffer[MAX_QPATH];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	int		size;
	char	*name;
	int		close_file = 0;
	extern int s_in_precache;

	if(r_rache_is_empty) {
		return NULL;
	}

	if (s->name[0] == '*')
		return NULL;

	sc = (sfxcache_t *)Cache_Check (&ds_snd_cache,&(s->extradata));
	if (sc)
		return sc;

	if(s_in_precache == 0) {
		s_in_precache = 0;
	}

//Com_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
	if (s->truename)
		name = s->truename;
	else
		name = s->name;

	if (name[0] == '#')
		strcpy(namebuffer, &name[1]);
	else
		Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name);

	//printf ("%s\n",namebuffer);

	FILE *h = (FILE *)s->handle;
	size = s->len;
	if(h == 0) {
		close_file = 1;
		//size = FS_LoadFile (namebuffer, (void **)&data);
		size = FS_FOpenFile (namebuffer, &h);
	} else {
		ds_fseek (h, s->pos, SEEK_SET);
	}
	if (!h) {
		Com_DPrintf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}
	r_cache_set_fail(0);
	data = (byte *)Z_Malloc(size);
	if (!data)
	{
		r_cache_set_fail(1);
		if(close_file) {
			ds_fclose (h);
		}
		Com_DPrintf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}
	FS_Read (data, size, h);
	if(close_file) {
		ds_fclose (h);
		s->handle = g_pack_file;
		s->pos = g_pack_file_pos;
		s->len = g_pack_file_len;
	}

	info = GetWavinfo (s->name, data, size);
	if (info.channels != 1)
	{
		r_cache_set_fail(1);
		Com_DPrintf ("%s is a stereo sample\n",s->name);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}

	stepscale = (float)info.rate / dma.speed;	
	len = info.samples / stepscale;
	/*if (info.width != 1)
	{
		r_cache_set_fail(1);
		printf ("%s is a 16 bit sample\n",s->name);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}*/

	//we are forcing 8 bit sound
	//len = len * info.width * info.channels;

	Cache_Alloc(&ds_snd_cache,(cache_user_t *)&(s->extradata),len + sizeof(sfxcache_t) + 4,s->name);

	/*cached_t *ds = DS_CacheAlloc(&ds_snd_cache,len + sizeof(sfxcache_t) + 4);
	if(!ds) {
		r_cache_set_fail(1);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}
	ds->owner = (cached_t **)&s->cache;
	ds->visframe = r_framecount;
	sc = s->cache = (sfxcache_t *)(ds+1);
	*/
	//sc = s->cache = (sfxcache_t *)Hunk_Alloc (len + sizeof(sfxcache_t) + 4);//pad by 4 just to be certain - too lazy to check
	sc = (sfxcache_t *)s->extradata;
	if (!sc)
	{
		r_cache_set_fail(1);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}
	r_cache_set_fail(1);
	
	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);

	//FS_FreeFile (data);
	Z_Free(data);

	return sc;
}