コード例 #1
0
ファイル: snd_dma.c プロジェクト: sago007/openarena_engine
/*
====================
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;
}
コード例 #2
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;
}
コード例 #3
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;
}
コード例 #4
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");
	}
}
コード例 #5
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;
}