engine/EngineAudioDMA.c
/*	Called once each time through the main loop
*/
Called once each time through the main loop
Called once each time through the main loop
void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
{
	int			i, j;
	int			total;
	channel_t	*ch;
	channel_t	*combine;
	if (!sound_started || (snd_blocked > 0))
		return;
	Math_VectorCopy(origin, listener_origin);
	Math_VectorCopy(forward, listener_forward);
	Math_VectorCopy(right, listener_right);
	Math_VectorCopy(up, listener_up);
	S_UpdateAmbientSounds ();
	combine = NULL;
	ch = channels+BSP_AMBIENT_END;
	for (i=BSP_AMBIENT_END ; i<total_channels; i++, ch++)
	{
		if (!ch->sfx)
			continue;
		SND_Spatialize(ch);         
		if (!ch->leftvol && !ch->rightvol)
			continue;
		if (i >= MAX_DYNAMIC_CHANNELS + BSP_AMBIENT_END)
		{
			if (combine && combine->sfx == ch->sfx)
			{
				combine->leftvol += ch->leftvol;
				combine->rightvol += ch->rightvol;
				ch->leftvol = ch->rightvol = 0;
				continue;
			}
			combine = channels+MAX_DYNAMIC_CHANNELS + BSP_AMBIENT_END;
			for (j=MAX_DYNAMIC_CHANNELS + BSP_AMBIENT_END ; j<i; j++, combine++)
				if (combine->sfx == ch->sfx)
					break;
			if (j == total_channels)
				combine = NULL;
			else
			{
				if (combine != ch)
				{
					combine->leftvol += ch->leftvol;
					combine->rightvol += ch->rightvol;
					ch->leftvol = ch->rightvol = 0;
				}
				continue;
			}
		}
	}
	if (snd_show.value)
	{
		total = 0;
		ch = channels;
		for (i=0 ; i<total_channels; i++, ch++)
			if (ch->sfx && (ch->leftvol || ch->rightvol) )
			{
				total++;
			}
		Con_Printf ("----(%i)----\n", total);
	}
	S_Update_();
}
void S_Update ( vec3_t origin , vec3_t forward , vec3_t right , vec3_t up ) { int i , j ; int total ; channel_t * ch ; channel_t * combine ; if ( ! sound_started || ( snd_blocked > 0 ) ) return ; Math_VectorCopy ( origin , listener_origin ) ; Math_VectorCopy ( forward , listener_forward ) ; Math_VectorCopy ( right , listener_right ) ; Math_VectorCopy ( up , listener_up ) ; S_UpdateAmbientSounds ( ) ; combine = NULL ; ch = channels + BSP_AMBIENT_END ; for ( i = BSP_AMBIENT_END ; i < total_channels ; i ++ , ch ++ ) { if ( ! ch -> sfx ) continue ; SND_Spatialize ( ch ) ; if ( ! ch -> leftvol && ! ch -> rightvol ) continue ; if ( i >= MAX_DYNAMIC_CHANNELS + BSP_AMBIENT_END ) { if ( combine && combine -> sfx == ch -> sfx ) { combine -> leftvol += ch -> leftvol ; combine -> rightvol += ch -> rightvol ; ch -> leftvol = ch -> rightvol = 0 ; continue ; } combine = channels + MAX_DYNAMIC_CHANNELS + BSP_AMBIENT_END ; for ( j = MAX_DYNAMIC_CHANNELS + BSP_AMBIENT_END ; j < i ; j ++ , combine ++ ) if ( combine -> sfx == ch -> sfx ) break ; if ( j == total_channels ) combine = NULL ; else { if ( combine != ch ) { combine -> leftvol += ch -> leftvol ; combine -> rightvol += ch -> rightvol ; ch -> leftvol = ch -> rightvol = 0 ; } continue ; } } } if ( snd_show . value ) { total = 0 ; ch = channels ; for ( i = 0 ; i < total_channels ; i ++ , ch ++ ) if ( ch -> sfx && ( ch -> leftvol || ch -> rightvol ) ) { total ++ ; } Con_Printf ( " \n " , total ) ; } S_Update_ ( ) ; }
Called once each time through the main loop
Called once each time through the main loop
// update general area ambient sound sources // update spatialization for static and dynamic sounds // respatialize channel // try to combine static sounds with a previous channel of the same // sound effect so we don't mix five torches every frame // see if it can just use the last one // search for one // Debugging output //Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name); // Mix some sound