示例#1
0
/*
==================
S_AddLoopingSound

Called during entity generation for a frame
Include velocity in case I get around to doing doppler...
==================
*/
void S_Base_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfxHandle ) {
	sfx_t *sfx;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "S_AddRealLoopingSound: handle %i out of range\n", sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( !sfx->soundLength ) {
		Com_Error( ERR_DROP, "%s has length 0", sfx->soundName );
	}
	VectorCopy( origin, loopSounds[entityNum].origin );
	VectorCopy( velocity, loopSounds[entityNum].velocity );
	loopSounds[entityNum].sfx = sfx;
	loopSounds[entityNum].active = qtrue;
	loopSounds[entityNum].kill = qfalse;
	loopSounds[entityNum].doppler = qfalse;
}
示例#2
0
/*
==================
S_RegisterSound

Creates a default buzz sound if the file can't be loaded
==================
*/
sfxHandle_t	S_Base_RegisterSound( const char *name, qboolean compressed ) {
	sfx_t	*sfx;

	compressed = qfalse;
	if (!s_soundStarted) {
		return 0;
	}

	if ( strlen( name ) >= MAX_QPATH ) {
		Com_Printf( "Sound name exceeds MAX_QPATH\n" );
		return 0;
	}

	sfx = S_FindName( name );
	if ( sfx->soundData ) {
		if ( sfx->defaultSound ) {
			Com_Printf( S_COLOR_YELLOW "WARNING: could not find %s - using default\n", sfx->soundName );
			return 0;
		}
		return sfx - s_knownSfx;
	}

	sfx->inMemory = qfalse;
	sfx->soundCompressed = compressed;

  S_memoryLoad(sfx);

	if ( sfx->defaultSound ) {
		Com_Printf( S_COLOR_YELLOW "WARNING: could not find %s - using default\n", sfx->soundName );
		return 0;
	}

	return sfx - s_knownSfx;
}
示例#3
0
/*
==================
S_Base_AddLoopingSound

Called during entity generation for a frame
Include velocity in case I get around to doing doppler...
==================
*/
static void S_Base_AddRealLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfxHandle ) {
	sfx_t *sfx;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if (entityNum >= MAX_LOOP_SOUNDS  ||  entityNum < 0) {
		Com_Printf(S_COLOR_YELLOW "%s() invalid entity number %d\n", __FUNCTION__, entityNum);
		return;
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "%s() handle %i out of range\n", __FUNCTION__, sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];
	//Com_Printf("S_AddRealLoopingSound %d : %s\n", sfxHandle, sfx->soundName);

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( !sfx->soundLength ) {
		Com_Error( ERR_DROP, "%s has length 0", sfx->soundName );
	}
	VectorCopy( origin, loopSounds[entityNum].origin );
	VectorCopy( velocity, loopSounds[entityNum].velocity );
	loopSounds[entityNum].sfx = sfx;
	loopSounds[entityNum].active = qtrue;
	loopSounds[entityNum].kill = qfalse;
	loopSounds[entityNum].doppler = qfalse;
}
示例#4
0
文件: dma.c 项目: icanhas/yantar
/*
 * Called during entity generation for a frame
 * Include velocity in case I get around to doing doppler...
 */
static void
S_Base_AddRealLoopingSound(int entityNum, const Vec3 origin,
                           const Vec3 velocity,
                           Handle sfxHandle)
{
    Sfx *sfx;

    if(!s_soundStarted || s_soundMuted)
        return;
    if(sfxHandle < 0 || sfxHandle >= s_numSfx) {
        comprintf(
            S_COLOR_YELLOW
            "sndaddrealloop: handle %i out of range\n",
            sfxHandle);
        return;
    }
    sfx = &s_knownSfx[ sfxHandle ];
    if(sfx->inMemory == qfalse)
        S_memoryLoad(sfx);

    if(!sfx->soundLength)
        comerrorf(ERR_DROP, "%s has length 0", sfx->soundName);
    copyv3(origin, loopSounds[entityNum].origin);
    copyv3(velocity, loopSounds[entityNum].velocity);
    loopSounds[entityNum].sfx = sfx;
    loopSounds[entityNum].active = qtrue;
    loopSounds[entityNum].kill = qfalse;
    loopSounds[entityNum].doppler = qfalse;
}
示例#5
0
/*
==================
S_AddLoopingSound

Called during entity generation for a frame
Include velocity in case I get around to doing doppler...
==================
*/
void S_Base_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfxHandle ) {
	sfx_t *sfx;
	int listener;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "S_AddLoopingSound: handle %i out of range\n", sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( !sfx->soundLength ) {
		Com_Error( ERR_DROP, "%s has length 0", sfx->soundName );
	}

	VectorCopy( origin, loopSounds[entityNum].origin );
	VectorCopy( velocity, loopSounds[entityNum].velocity );
	loopSounds[entityNum].active = qtrue;
	loopSounds[entityNum].kill = qtrue;
	loopSounds[entityNum].doppler = qfalse;
	loopSounds[entityNum].oldDopplerScale = 1.0;
	loopSounds[entityNum].dopplerScale = 1.0;
	loopSounds[entityNum].sfx = sfx;

	listener = S_ClosestListener(loopSounds[entityNum].origin);

	if (listener >= 0 && listener < MAX_LISTENERS && s_doppler->integer && VectorLengthSquared(velocity)>0.0) {
		vec3_t	out;
		float	lena, lenb;

		loopSounds[entityNum].doppler = qtrue;
		lena = DistanceSquared(listeners[listener].origin, loopSounds[entityNum].origin);
		VectorAdd(loopSounds[entityNum].origin, loopSounds[entityNum].velocity, out);
		lenb = DistanceSquared(listeners[listener].origin, out);
		if ((loopSounds[entityNum].framenum+1) != cls.framecount) {
			loopSounds[entityNum].oldDopplerScale = 1.0;
		} else {
			loopSounds[entityNum].oldDopplerScale = loopSounds[entityNum].dopplerScale;
		}
		loopSounds[entityNum].dopplerScale = lenb/(lena*100);
		if (loopSounds[entityNum].dopplerScale<=1.0) {
			loopSounds[entityNum].doppler = qfalse;			// don't bother doing the math
		} else if (loopSounds[entityNum].dopplerScale>MAX_DOPPLER_SCALE) {
			loopSounds[entityNum].dopplerScale = MAX_DOPPLER_SCALE;
		}
	}

	loopSounds[entityNum].framenum = cls.framecount;
}
示例#6
0
文件: snd_dma.c 项目: fretn/etlegacy
/**
 * @brief Creates a default buzz sound if the file can't be loaded
 */
sfxHandle_t S_Base_RegisterSound(const char *name, qboolean compressed)
{
	sfx_t *sfx;

	compressed = qfalse; // FIXME: non WAV
	if (!s_soundStarted)
	{
		return 0;
	}

	if (!name)
	{
		Com_DPrintf(S_COLOR_RED "ERROR: [S_AL_RegisterSound: NULL");
		return 0;
	}
	if (!name[0])
	{
		Com_DPrintf(S_COLOR_RED "ERROR: [S_AL_RegisterSound: empty name");
		return 0;
	}

	if (strlen(name) >= MAX_QPATH)
	{
		Com_DPrintf(S_COLOR_RED "ERROR: [S_Base_RegisterSound] Sound name exceeds MAX_QPATH - %s\n", name);
		return 0;
	}

	sfx = S_FindName(name);
	if (!sfx)
	{
		return 0;
	}

	if (sfx->soundData)
	{
		if (sfx->defaultSound)
		{
			Com_DPrintf(S_COLOR_YELLOW "WARNING: [S_Base_RegisterSound]: could not find %s - using default\n", sfx->soundName);
			return 0;
		}
		return sfx - knownSfx;
	}

	sfx->inMemory        = qfalse;
	sfx->soundCompressed = compressed;

	S_memoryLoad(sfx);

	if (sfx->defaultSound)
	{
		Com_DPrintf(S_COLOR_YELLOW "WARNING: [S_Base_RegisterSound] could not find %s - using default\n", sfx->soundName);
		return 0;
	}

	return sfx - knownSfx;
}
示例#7
0
文件: dma.c 项目: icanhas/yantar
/*
 * Called during entity generation for a frame
 * Include velocity in case I get around to doing doppler...
 */
static void
S_Base_AddLoopingSound(int entityNum, const Vec3 origin, const Vec3 velocity,
                       Handle sfxHandle)
{
    Sfx *sfx;

    if(!s_soundStarted || s_soundMuted)
        return;
    if(sfxHandle < 0 || sfxHandle >= s_numSfx) {
        comprintf(
            S_COLOR_YELLOW
            "sndaddloop: handle %i out of range\n",
            sfxHandle);
        return;
    }
    sfx = &s_knownSfx[sfxHandle];
    if(sfx->inMemory == qfalse)
        S_memoryLoad(sfx);
    if(!sfx->soundLength)
        comerrorf(ERR_DROP, "%s has length 0", sfx->soundName);

    copyv3(origin, loopSounds[entityNum].origin);
    copyv3(velocity, loopSounds[entityNum].velocity);
    loopSounds[entityNum].active = qtrue;
    loopSounds[entityNum].kill = qtrue;
    loopSounds[entityNum].doppler = qfalse;
    loopSounds[entityNum].oldDopplerScale = 1.0;
    loopSounds[entityNum].dopplerScale = 1.0;
    loopSounds[entityNum].sfx = sfx;

    if(s_doppler->integer && lensqrv3(velocity)>0.0) {
        Vec3	out;
        float	lena, lenb;

        loopSounds[entityNum].doppler = qtrue;
        lena = distsqrv3(loopSounds[listener_number].origin,
                         loopSounds[entityNum].origin);
        addv3(loopSounds[entityNum].origin,
              loopSounds[entityNum].velocity,
              out);
        lenb = distsqrv3(loopSounds[listener_number].origin, out);
        if((loopSounds[entityNum].framenum+1) != cls.framecount)
            loopSounds[entityNum].oldDopplerScale = 1.0;
        else
            loopSounds[entityNum].oldDopplerScale =
                loopSounds[entityNum].dopplerScale;
        loopSounds[entityNum].dopplerScale = lenb/(lena*100);
        if(loopSounds[entityNum].dopplerScale<=1.0)
            loopSounds[entityNum].doppler = qfalse;		/* don't bother doing the math */
        else if(loopSounds[entityNum].dopplerScale>MAX_DOPPLER_SCALE)
            loopSounds[entityNum].dopplerScale = MAX_DOPPLER_SCALE;
    }

    loopSounds[entityNum].framenum = cls.framecount;
}
示例#8
0
文件: snd_dma.c 项目: fretn/etlegacy
/**
 * @brief Called during entity generation for a frame
 *        Include velocity in case I get around to doing doppler...
 */
void S_Base_AddRealLoopingSound(const vec3_t origin, const vec3_t velocity, int range, sfxHandle_t sfxHandle, int volume, int soundTime)
{
	sfx_t *sfx;

	if (!s_soundStarted || s_soundMuted || !volume)
	{
		return;
	}

	if (numLoopSounds >= MAX_LOOP_SOUNDS)
	{
		return;
	}

	if (sfxHandle < 0 || sfxHandle >= numSfx)
	{
		Com_Printf(S_COLOR_YELLOW "S_Base_AddRealLoopingSound: handle %i out of range\n", sfxHandle);
		return;
	}

	sfx = &knownSfx[sfxHandle];

	if (sfx->inMemory == qfalse)
	{
		S_memoryLoad(sfx);
	}

	if (!sfx->soundLength)
	{
		Com_Error(ERR_DROP, "%s has length 0", sfx->soundName);
	}

	VectorCopy(origin, loopSounds[numLoopSounds].origin);
	VectorCopy(velocity, loopSounds[numLoopSounds].velocity);
	loopSounds[numLoopSounds].sfx             = sfx;
	loopSounds[numLoopSounds].active          = qtrue;
	loopSounds[numLoopSounds].kill            = qfalse;
	loopSounds[numLoopSounds].doppler         = qfalse;
	loopSounds[numLoopSounds].oldDopplerScale = 1;
	loopSounds[numLoopSounds].dopplerScale    = 1;
	loopSounds[numLoopSounds].range           = range ? range : SOUND_RANGE_DEFAULT;
	loopSounds[numLoopSounds].loudUnderWater  = (volume & 1 << UNDERWATER_BIT) != 0;
	if (volume > 65535)
	{
		volume = 65535;
	}
	else if (volume < 0)
	{
		volume = 0;
	}
	loopSounds[numLoopSounds].volume = (int)((float)volume * s_volCurrent);
	numLoopSounds++;
}
示例#9
0
文件: snd_dma.c 项目: fretn/etlegacy
void S_Base_Reload(void)
{
	sfx_t *sfx;
	int   i;

	if (!s_soundStarted)
	{
		return;
	}

	Com_Printf("reloading sounds...\n");

	S_Base_StopAllSounds();

	for (sfx = knownSfx, i = 0; i < numSfx; i++, sfx++)
	{
		sfx->inMemory = qfalse;
		S_memoryLoad(sfx);
	}
}
示例#10
0
/*
====================
S_Base_StartSoundEx

Validates the parms and ques the sound up
if origin is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
static void S_Base_StartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle, qboolean localSound ) {
	channel_t	*ch;
	sfx_t		*sfx;
  int i, oldest, chosen, time;
  int	inplay, allowed;
	qboolean	fullVolume;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if ( !origin && ( entityNum < 0 || entityNum > MAX_GENTITIES ) ) {
		Com_Error( ERR_DROP, "S_StartSound: bad entitynum %i", entityNum );
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "S_StartSound: handle %i out of range\n", sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( s_show->integer == 1 ) {
		Com_Printf( "%i : %s\n", s_paintedtime, sfx->soundName );
	}

	time = Com_Milliseconds();

//	Com_Printf("playing %s\n", sfx->soundName);
	// pick a channel to play on

	allowed = 4;
	if (entityNum == listener_number) {
		allowed = 8;
	}

	fullVolume = qfalse;
	if (localSound || S_Base_HearingThroughEntity(entityNum, origin)) {
		fullVolume = qtrue;
	}

	ch = s_channels;
	inplay = 0;
	for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) {		
		if (ch->entnum == entityNum && ch->thesfx == sfx) {
			if (time - ch->allocTime < 50) {
//				if (Cvar_VariableValue( "cg_showmiss" )) {
//					Com_Printf("double sound start\n");
//				}
				return;
			}
			inplay++;
		}
	}

	if (inplay>allowed) {
		return;
	}

	sfx->lastTimeUsed = time;

	ch = S_ChannelMalloc();	// entityNum, entchannel);
	if (!ch) {
		ch = s_channels;

		oldest = sfx->lastTimeUsed;
		chosen = -1;
		for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
			if (ch->entnum != listener_number && ch->entnum == entityNum && ch->allocTime<oldest && ch->entchannel != CHAN_ANNOUNCER) {
				oldest = ch->allocTime;
				chosen = i;
			}
		}
		if (chosen == -1) {
			ch = s_channels;
			for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
				if (ch->entnum != listener_number && ch->allocTime<oldest && ch->entchannel != CHAN_ANNOUNCER) {
					oldest = ch->allocTime;
					chosen = i;
				}
			}
			if (chosen == -1) {
				ch = s_channels;
				if (ch->entnum == listener_number) {
					for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
						if (ch->allocTime<oldest) {
							oldest = ch->allocTime;
							chosen = i;
						}
					}
				}
				if (chosen == -1) {
					Com_Printf("dropping sound\n");
					return;
				}
			}
		}
		ch = &s_channels[chosen];
		ch->allocTime = sfx->lastTimeUsed;
	}

	if (origin) {
		VectorCopy (origin, ch->origin);
		ch->fixed_origin = qtrue;
	} else {
		ch->fixed_origin = qfalse;
	}

	ch->master_vol = 127;
	ch->entnum = entityNum;
	ch->thesfx = sfx;
	ch->startSample = START_SAMPLE_IMMEDIATE;
	ch->entchannel = entchannel;
	ch->leftvol = ch->master_vol;		// these will get calced at next spatialize
	ch->rightvol = ch->master_vol;		// unless the game isn't running
	ch->doppler = qfalse;
	ch->fullVolume = fullVolume;
}
示例#11
0
文件: snd_dma.c 项目: fretn/etlegacy
void S_Base_AddLoopingSound(const vec3_t origin, const vec3_t velocity, int range, sfxHandle_t sfxHandle, int volume, int soundTime)
{
	sfx_t *sfx;

	if (!s_soundStarted || s_soundMuted || !volume)
	{
		return;
	}

	if (numLoopSounds >= MAX_LOOP_SOUNDS)
	{
		return;
	}

	if (sfxHandle < 0 || sfxHandle >= numSfx)
	{
		Com_Printf(S_COLOR_YELLOW "S_AddLoopingSound: handle %i out of range\n", sfxHandle);
		return;
	}

	sfx = &knownSfx[sfxHandle];

	if (sfx->inMemory == qfalse)
	{
		S_memoryLoad(sfx);
	}

	if (!sfx->soundLength)
	{
		Com_Error(ERR_DROP, "%s has length 0", sfx->soundName);
	}

	VectorCopy(origin, loopSounds[numLoopSounds].origin);
	VectorCopy(velocity, loopSounds[numLoopSounds].velocity);
	loopSounds[numLoopSounds].startSample     = soundTime % sfx->soundLength;
	loopSounds[numLoopSounds].active          = qtrue;
	loopSounds[numLoopSounds].kill            = qtrue;
	loopSounds[numLoopSounds].doppler         = qfalse;
	loopSounds[numLoopSounds].oldDopplerScale = 1;
	loopSounds[numLoopSounds].dopplerScale    = 1;
	loopSounds[numLoopSounds].sfx             = sfx;
	loopSounds[numLoopSounds].range           = range ? range : SOUND_RANGE_DEFAULT;
	loopSounds[numLoopSounds].loudUnderWater  = (volume & 1 << UNDERWATER_BIT) != 0;
	if (volume > 65535)
	{
		volume = 65535;
	}
	else if (volume < 0)
	{
		volume = 0;
	}
	loopSounds[numLoopSounds].volume = (int)((float)volume * s_volCurrent);

	if (s_doppler->integer && VectorLengthSquared(velocity) > 0)
	{
		vec3_t out;
		float  lena, lenb;

		// don't do the doppler effect when trumpets of train and station are at the same position
		if (entityPositions[listener_number] != entityPositions[numLoopSounds])
		{
			loopSounds[numLoopSounds].doppler = qtrue;
		}
		else
		{
			loopSounds[numLoopSounds].doppler = qfalse;
		}

		lena = DistanceSquared(entityPositions[listener_number], entityPositions[numLoopSounds]);

		VectorAdd(entityPositions[numLoopSounds], loopSounds[numLoopSounds].velocity, out);

		lenb = DistanceSquared(entityPositions[listener_number], out);

		if ((loopSounds[numLoopSounds].framenum + 1) != cls.framecount)
		{
			loopSounds[numLoopSounds].oldDopplerScale = 1;
		}
		else
		{
			loopSounds[numLoopSounds].oldDopplerScale = loopSounds[numLoopSounds].dopplerScale;
		}

		if (lena == 0) // div/0
		{
			loopSounds[numLoopSounds].dopplerScale = 1; // no doppler
		}
		else
		{
			loopSounds[numLoopSounds].dopplerScale = lenb / (lena * 100);
		}

		if (loopSounds[numLoopSounds].dopplerScale <= 1)
		{
			loopSounds[numLoopSounds].doppler = qfalse;         // don't bother doing the math
		}
		else if (loopSounds[numLoopSounds].dopplerScale > MAX_DOPPLER_SCALE)
		{
			loopSounds[numLoopSounds].dopplerScale = MAX_DOPPLER_SCALE;
		}
	}

	loopSounds[numLoopSounds].framenum = cls.framecount;
	numLoopSounds++;
}
示例#12
0
文件: snd_dma.c 项目: fretn/etlegacy
/*
====================
S_StartSoundEx

Validates the parms and ques the sound up
if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
void S_Base_StartSoundEx(vec3_t origin, int entnum, int entchannel, sfxHandle_t sfxHandle, int flags, int volume)
{
	channel_t *ch;
	sfx_t     *sfx;
	int       i, time;

	if (!s_soundStarted || s_soundMuted)
	{
		//Com_Printf(S_COLOR_YELLOW "S_Base_StartSoundEx: sound not started or muted\n");
		return;
	}

	if (!origin && (entnum < 0 || entnum >= MAX_GENTITIES))
	{
		Com_Error(ERR_DROP, "S_Base_StartSoundEx: bad entitynum %i", entnum);
	}

	if (sfxHandle < 0 || sfxHandle >= numSfx)
	{
		Com_Printf(S_COLOR_YELLOW "S_Base_StartSoundEx: handle %i out of range", sfxHandle);
		return;
	}

	sfx = &knownSfx[sfxHandle];

	if (sfx->inMemory == qfalse)
	{
		S_memoryLoad(sfx);
	}

	if (s_show->integer == 1)
	{
		Com_Printf("S_Base_StartSoundEx: %i : %s\n", s_paintedtime, sfx->soundName);
	}

	time = Sys_Milliseconds();
	ch   = s_channels;

	for (i = 0; i < MAX_CHANNELS ; i++, ch++)
	{
		if (ch->entnum == entnum && ch->thesfx)
		{
			if (ch->thesfx == sfx && time - ch->allocTime < 50) // double played in one frame
			{
				return;
			}
			else if (ch->entchannel == entchannel && (flags & SND_CUTOFF_ALL)) // cut the sounds that are flagged to be cut
			{
				S_ChannelFree(ch);
			}
		}
	}

	sfx->lastTimeUsed = time;

	ch = S_ChannelMalloc();
	if (!ch)
	{
		int oldest = sfx->lastTimeUsed;
		int chosen = -1;

		ch = s_channels;

		for (i = 0 ; i < MAX_CHANNELS ; i++, ch++)
		{
			if (ch->entnum != listener_number && ch->entnum == entnum && ch->allocTime < oldest && ch->entchannel != CHAN_ANNOUNCER)
			{
				oldest = ch->allocTime;
				chosen = i;
			}
		}
		if (chosen == -1)
		{
			ch = s_channels;
			for (i = 0 ; i < MAX_CHANNELS ; i++, ch++)
			{
				if (ch->entnum != listener_number && ch->allocTime < oldest && ch->entchannel != CHAN_ANNOUNCER)
				{
					oldest = ch->allocTime;
					chosen = i;
				}
			}
			if (chosen == -1)
			{
				ch = s_channels;
				if (ch->entnum == listener_number)
				{
					for (i = 0 ; i < MAX_CHANNELS ; i++, ch++)
					{
						if (ch->allocTime < oldest)
						{
							oldest = ch->allocTime;
							chosen = i;
						}
					}
				}
				if (chosen == -1)
				{
					Com_Printf("S_Base_StartSoundEx WARNING: dropping sound\n");
					return;
				}
			}
		}
		ch            = &s_channels[chosen];
		ch->allocTime = sfx->lastTimeUsed;
	}

	if (origin)
	{
		VectorCopy(origin, ch->origin);
		ch->fixed_origin = qtrue;
	}
	else
	{
		ch->fixed_origin = qfalse;
	}

	ch->flags       = flags;
	ch->master_vol  = volume;
	ch->entnum      = entnum;
	ch->thesfx      = sfx;
	ch->startSample = START_SAMPLE_IMMEDIATE;
	ch->entchannel  = entchannel;
	ch->leftvol     = ch->master_vol;   // these will get calced at next spatialize
	ch->rightvol    = ch->master_vol;   // unless the game isn't running
	ch->doppler     = qfalse;
}
示例#13
0
/*
==================
S_Base_AddLoopingSound

Called during entity generation for a frame
Include velocity in case I get around to doing doppler...
==================
*/
static void S_Base_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfxHandle ) {
	sfx_t *sfx;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if (entityNum >= MAX_LOOP_SOUNDS  ||  entityNum < 0) {
		Com_Printf(S_COLOR_YELLOW "%s() invalid entity number %d\n", __FUNCTION__, entityNum);
		return;
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "%s() handle %i out of range\n", __FUNCTION__, sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];
	//Com_Printf("S_Base_AddLoopingSound %d : %s  velocity %f\n", sfxHandle, sfx->soundName, VectorLengthSquared(velocity));

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( !sfx->soundLength ) {
		Com_Error( ERR_DROP, "%s has length 0", sfx->soundName );
	}

	VectorCopy( origin, loopSounds[entityNum].origin );
	VectorCopy( velocity, loopSounds[entityNum].velocity );
	loopSounds[entityNum].active = qtrue;
	loopSounds[entityNum].kill = qtrue;
	loopSounds[entityNum].doppler = qfalse;
	loopSounds[entityNum].oldDopplerScale = 1.0;
	loopSounds[entityNum].dopplerScale = 1.0;
	loopSounds[entityNum].sfx = sfx;

	if (s_doppler->integer && VectorLengthSquared(velocity)>0.0) {
		vec3_t	out;
		float	lena, lenb;

		//Com_Printf("distance: %f\n", Distance(loopSounds[listener_number].origin, loopSounds[entityNum].origin));
		//Com_Printf("distance: %f\n", Distance(listener_origin, loopSounds[entityNum].origin));

		loopSounds[entityNum].doppler = qtrue;
		//lena = DistanceSquared(loopSounds[listener_number].origin, loopSounds[entityNum].origin);
		lena = DistanceSquared(listener_origin, loopSounds[entityNum].origin);
		VectorAdd(loopSounds[entityNum].origin, loopSounds[entityNum].velocity, out);
		//lenb = DistanceSquared(loopSounds[listener_number].origin, out);
		lenb = DistanceSquared(listener_origin, out);
		if ((loopSounds[entityNum].framenum+1) != cls.framecount) {
			loopSounds[entityNum].oldDopplerScale = 1.0;
		} else {
			loopSounds[entityNum].oldDopplerScale = loopSounds[entityNum].dopplerScale;
		}
		loopSounds[entityNum].dopplerScale = lenb/(lena*100);
		if (loopSounds[entityNum].dopplerScale<=1.0) {
			loopSounds[entityNum].doppler = qfalse;			// don't bother doing the math
		} else if (loopSounds[entityNum].dopplerScale>MAX_DOPPLER_SCALE) {
		//} else if (loopSounds[entityNum].dopplerScale > 2.0) {
			loopSounds[entityNum].dopplerScale = MAX_DOPPLER_SCALE;
			//loopSounds[entityNum].dopplerScale = 2.0;
		}
		//if (loopSounds[entityNum].doppler) {
			//Com_Printf("dopplerscale %f\n", loopSounds[entityNum].dopplerScale);
		//}
		//if (loopSounds[entityNum].doppler) {
			//Com_Printf("doppler set: %d\n", loopSounds[entityNum].doppler);
		//}
	}

	loopSounds[entityNum].framenum = cls.framecount;
}
示例#14
0
/*
====================
S_Base_StartSound

Validates the parms and ques the sound up
if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
static void S_Base_StartSound (const vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle) {
	channel_t	*ch;
	sfx_t		*sfx;
  int i, oldest, chosen, time;
  int	inplay, allowed;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if ( !origin && ( entityNum < 0 || entityNum >= MAX_GENTITIES ) ) {
		Com_Error( ERR_DROP, "S_StartSound: bad entitynum %i", entityNum );
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "S_StartSound: handle %i out of range\n", sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( s_show->integer == 1 ) {
		Com_Printf("%f  %i : %s  (%d -> %d)\n", (float)cl.serverTime + Overf, s_paintedtime, sfx->soundName, listener_number, entityNum);
	}

	time = S_Milliseconds();

//	Com_Printf("playing %s\n", sfx->soundName);
	// pick a channel to play on

	allowed = s_maxSoundInstances->integer;
	if (allowed < 0) {  // old q3 code
		allowed = 4;

		if (entityNum == listener_number) {
			allowed = 8;
		}
	}

	ch = s_channels;
	inplay = 0;
	for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) {
		if (ch->entnum == entityNum && ch->thesfx == sfx) {
			if (time - ch->allocTime < 50) {
				//Com_Printf("^2%f double sound start '%s' last played (%d)  length %f\n", (float)cl.serverTime + Overf, sfx->soundName, time - ch->allocTime, (float)sfx->soundLength / (float)dma.speed);
			}

			if (time - ch->allocTime < s_maxSoundRepeatTime->integer) {
			//if (time - ch->allocTime < (int)((float)sfx->soundLength / (float)dma.speed * 1000.0)) {
				if (s_showMiss->integer) {
					Com_Printf("^3%f double sound start '%s' last played (%d)  length %f\n", (float)cl.serverTime + Overf, sfx->soundName, time - ch->allocTime, (float)sfx->soundLength / (float)dma.speed);
				}
				return;
			}
			inplay++;
		}
	}

	//Com_Printf("inplay %d\n", inplay);

	if (inplay > 4) {
		//Com_Printf("^5%f inplay > x  %d > %d  '%s'\n", (float)cl.serverTime + Overf, inplay, allowed, sfx->soundName);
	}

	if (inplay > allowed) {
		if (s_showMiss->integer > 1) {
			Com_Printf("^1%f inplay > allowed  %d > %d  '%s' ent %d ch %d/%d\n", (float)cl.serverTime + Overf, inplay, allowed, sfx->soundName, entityNum, entchannel, listener_number);
		}
		return;
	}

	sfx->lastTimeUsed = time;

	ch = S_ChannelMalloc();	// entityNum, entchannel);
	if (!ch) {
		if (s_showMiss->integer > 2) {
			Com_Printf("^1%f %s() couldn't allocate channel\n", (float)cl.serverTime + Overf, __FUNCTION__);
		}
		ch = s_channels;

		oldest = sfx->lastTimeUsed;
		chosen = -1;
		for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
			if (ch->entnum != listener_number && ch->entnum == entityNum && ch->allocTime<oldest && ch->entchannel != CHAN_ANNOUNCER) {
				oldest = ch->allocTime;
				chosen = i;
			}
		}
		if (chosen == -1) {
			ch = s_channels;
			for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
				if (ch->entnum != listener_number && ch->allocTime<oldest && ch->entchannel != CHAN_ANNOUNCER) {
					oldest = ch->allocTime;
					chosen = i;
				}
			}
			if (chosen == -1) {
				ch = s_channels;
				if (ch->entnum == listener_number) {
					for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
						if (ch->allocTime<oldest) {
							oldest = ch->allocTime;
							chosen = i;
						}
					}
				}
				if (chosen == -1) {
					Com_Printf("dropping sound\n");
					return;
				}
			}
		}
		ch = &s_channels[chosen];
		ch->allocTime = sfx->lastTimeUsed;
		//Com_Printf("use old\n");
	} else {
		//Com_Printf("alloc\n");
	}

	if (origin) {
		VectorCopy (origin, ch->origin);
		ch->fixed_origin = qtrue;
	} else {
		ch->fixed_origin = qfalse;
	}

	ch->master_vol = 127;
	ch->leftvol = 127;
	ch->rightvol = 127;
	ch->entnum = entityNum;
	ch->thesfx = sfx;
	ch->startSample = START_SAMPLE_IMMEDIATE;
	ch->entchannel = entchannel;
	ch->leftvol = ch->master_vol;		// these will get calced at next spatialize
	ch->rightvol = ch->master_vol;		// unless the game isn't running
	ch->doppler = qfalse;

	if (ch->entnum != listener_number) {
		if (ch->fixed_origin) {
			S_SpatializeOrigin (origin, ch->master_vol, &ch->leftvol, &ch->rightvol);
		}
	} else {
		//Com_Printf("dont respa!!!\n");
	}
}
示例#15
0
文件: dma.c 项目: icanhas/yantar
/*
 * Validates the parms and ques the sound up
 * if pos is NULL, the sound will be dynamically sourced from the entity
 * Entchannel 0 will never override a playing sound
 */
static void
S_Base_StartSound(Vec3 origin, int entityNum, int entchannel,
                  Handle sfxHandle)
{
    Channel	*ch;
    Sfx		*sfx;
    int	i, oldest, chosen, time;
    int	inplay, allowed;

    if(!s_soundStarted || s_soundMuted)
        return;
    if(!origin && (entityNum < 0 || entityNum > MAX_GENTITIES))
        comerrorf(ERR_DROP, "sndstartsound: bad entitynum %i", entityNum);

    if(sfxHandle < 0 || sfxHandle >= s_numSfx) {
        comprintf(S_COLOR_YELLOW "sndstartsound: handle %i out of range\n",
                  sfxHandle);
        return;
    }

    sfx = &s_knownSfx[sfxHandle];
    if(sfx->inMemory == qfalse)
        S_memoryLoad(sfx);

    if(s_show->integer == 1)
        comprintf("%i : %s\n", s_paintedtime, sfx->soundName);

    time = commillisecs();

    /*	comprintf("playing %s\n", sfx->soundName); */
    /* pick a channel to play on */

    allowed = 4;
    if(entityNum == listener_number)
        allowed = 8;

    ch = s_channels;
    inplay = 0;
    for(i = 0; i < MAX_CHANNELS; i++, ch++)
        if(ch->entnum == entityNum && ch->thesfx == sfx) {
            if(time - ch->allocTime < 50)
                /*                      if (cvargetf( "cg_showmiss" )) {
                 *                              comprintf("double sound start\n");
                 *                      } */
                return;
            inplay++;
        }

    if(inplay>allowed)
        return;

    sfx->lastTimeUsed = time;

    ch = S_ChannelMalloc();	/* entityNum, entchannel); */
    if(!ch) {
        ch = s_channels;

        oldest	= sfx->lastTimeUsed;
        chosen	= -1;
        for(i = 0; i < MAX_CHANNELS; i++, ch++)
            if(ch->entnum != listener_number && ch->entnum ==
                    entityNum && ch->allocTime<oldest &&
                    ch->entchannel !=
                    CHAN_ANNOUNCER) {
                oldest	= ch->allocTime;
                chosen	= i;
            }
        if(chosen == -1) {
            ch = s_channels;
            for(i = 0; i < MAX_CHANNELS; i++, ch++)
                if(ch->entnum != listener_number &&
                        ch->allocTime<oldest && ch->entchannel !=
                        CHAN_ANNOUNCER) {
                    oldest	= ch->allocTime;
                    chosen	= i;
                }
            if(chosen == -1) {
                ch = s_channels;
                if(ch->entnum == listener_number) {
                    for(i = 0; i < MAX_CHANNELS; i++, ch++)
                        if(ch->allocTime<oldest) {
                            oldest	= ch->allocTime;
                            chosen	= i;
                        }
                }
                if(chosen == -1) {
                    comprintf("dropping sound\n");
                    return;
                }
            }
        }
        ch = &s_channels[chosen];
        ch->allocTime = sfx->lastTimeUsed;
    }

    if(origin) {
        copyv3 (origin, ch->origin);
        ch->fixed_origin = qtrue;
    } else
        ch->fixed_origin = qfalse;

    ch->master_vol	= 127;
    ch->entnum	= entityNum;
    ch->thesfx	= sfx;
    ch->startSample = START_SAMPLE_IMMEDIATE;
    ch->entchannel	= entchannel;
    ch->leftvol	= ch->master_vol;	/* these will get calced at next spatialize */
    ch->rightvol	= ch->master_vol;	/* unless the game isn't running */
    ch->doppler	= qfalse;
}
示例#16
0
/*
====================
S_StartSound

Validates the parms and ques the sound up
if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
void S_Base_StartSound(vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle ) {
	channel_t	*ch;
	sfx_t		*sfx;
  int i, oldest, chosen, time;
  int	inplay, allowed;

	if ( !s_soundStarted || s_soundMuted ) {
		return;
	}

	if ( !origin && ( entityNum < 0 || entityNum > MAX_GENTITIES ) ) {
		Com_Error( ERR_DROP, "S_StartSound: bad entitynum %i", entityNum );
	}

	if ( sfxHandle < 0 || sfxHandle >= s_numSfx ) {
		Com_Printf( S_COLOR_YELLOW "S_StartSound: handle %i out of range\n", sfxHandle );
		return;
	}

	sfx = &s_knownSfx[ sfxHandle ];

	#ifdef USE_AUTOMATION
		if (!Q_stricmp(sfx->soundName, "sound/weapons/beretta/92G_noammo.wav")) {
			if (cl_noAmmo->integer == 1) {
				Cbuf_AddText("weapprev\n");
				return;
			} else if (cl_noAmmo->integer == 2) {
				Cbuf_AddText("+button5;wait;-button5\n");
				return;
			} else if (cl_noAmmo->integer == 3) {
				Cbuf_AddText("ut_weapdrop\n");
				return;
			}
		}
	#endif

	#ifdef USE_SOUNDHAX
	if (s_soundhax->integer == 1) {
		for (i = 0; ; i++) {
			if (!s_ignoredSounds[i])
				break;
			if (!Q_stricmp(sfx->soundName, s_ignoredSounds[i]))
				return;
		}
	}
	#endif

	if (s_chatsound->integer == 0 && !Q_stricmp(sfx->soundName, "sound/player/talk.wav")) {
		return;
	}

	if (s_debug->integer == 1) {
		Com_Printf("Playing: %s\n", sfx->soundName);
	}

	if (sfx->inMemory == qfalse) {
		S_memoryLoad(sfx);
	}

	if ( s_show->integer == 1 ) {
		Com_Printf( "%i : %s\n", s_paintedtime, sfx->soundName );
	}

	time = Com_Milliseconds();

	// pick a channel to play on

	allowed = 16;
	if (entityNum == listener_number) {
		allowed = 32;
	}

	ch = s_channels;
	inplay = 0;
	for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) 
	{
		if (ch[i].entnum == entityNum && ch[i].thesfx == sfx)
		{
			if (time - ch[i].allocTime < 30)
			{
//				if (Cvar_VariableValue( "cg_showmiss" )) {
//					Com_Printf("double sound start\n");
//				}
				return;
			}
			inplay++;
		}
	}

	if (inplay > allowed) {
		return;
	}

	sfx->lastTimeUsed = time;

	ch = S_ChannelMalloc();	// entityNum, entchannel);
	if (!ch) {
		ch = s_channels;

		oldest = sfx->lastTimeUsed;
		chosen = -1;
		for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
			if (ch->entnum != listener_number && ch->entnum == entityNum && ch->allocTime<oldest && ch->entchannel != CHAN_ANNOUNCER) {
				oldest = ch->allocTime;
				chosen = i;
			}
		}
		if (chosen == -1) {
			ch = s_channels;
			for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
				if (ch->entnum != listener_number && ch->allocTime<oldest && ch->entchannel != CHAN_ANNOUNCER) {
					oldest = ch->allocTime;
					chosen = i;
				}
			}
			if (chosen == -1) {
				if (ch->entnum == listener_number) {
					for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) {
						if (ch->allocTime<oldest) {
							oldest = ch->allocTime;
							chosen = i;
						}
					}
				}
				if (chosen == -1) {
					Com_Printf("dropping sound\n");
					return;
				}
			}
		}
		ch = &s_channels[chosen];
		ch->allocTime = sfx->lastTimeUsed;
	}

	if (origin) {
		VectorCopy (origin, ch->origin);
		ch->fixed_origin = qtrue;
	} else {
		ch->fixed_origin = qfalse;
	}

	ch->master_vol = 127;
	ch->entnum = entityNum;
	ch->thesfx = sfx;
	ch->startSample = START_SAMPLE_IMMEDIATE;
	ch->entchannel = entchannel;
	ch->leftvol = ch->master_vol;		// these will get calced at next spatialize
	ch->rightvol = ch->master_vol;		// unless the game isn't running
	ch->doppler = qfalse;
}