void CAI_Senses::Listen( void )
{
	m_iAudibleList = SOUNDLIST_EMPTY; 

	int iSoundMask = GetOuter()->GetSoundInterests();
	
	if ( iSoundMask != SOUND_NONE && !(GetOuter()->HasSpawnFlags(SF_NPC_WAIT_TILL_SEEN)) )
	{
		int	iSound = CSoundEnt::ActiveList();
		
		while ( iSound != SOUNDLIST_EMPTY )
		{
			CSound *pCurrentSound = CSoundEnt::SoundPointerForIndex( iSound );

			if ( pCurrentSound	&& (iSoundMask & pCurrentSound->SoundType()) && CanHearSound( pCurrentSound ) )
			{
	 			// the npc cares about this sound, and it's close enough to hear.
				pCurrentSound->m_iNextAudible = m_iAudibleList;
				m_iAudibleList = iSound;
			}

			iSound = pCurrentSound->NextSound();
		}
	}
	
	GetOuter()->OnListened();
}
//-----------------------------------------------------------------------------
// Purpose: Listens for sounds and updates the value of the SoundLevel output.
//-----------------------------------------------------------------------------
void CEnvMicrophone::Think(void)
{
	int nSound = CSoundEnt::ActiveList();
	bool fHearSound = false;

	float flMaxVolume = 0;
	
	//
	// Find the loudest sound that this microphone cares about.
	//
	while (nSound != SOUNDLIST_EMPTY)
	{
		CSound *pCurrentSound = CSoundEnt::SoundPointerForIndex(nSound);

		if (pCurrentSound)
		{
			if (m_nSoundMask & pCurrentSound->SoundType())
			{
				float flVolume = 0;
				if (CanHearSound(pCurrentSound, flVolume) && (flVolume > flMaxVolume))
				{
					flMaxVolume = flVolume;
					fHearSound = true;
				}
			}
		}

		nSound = pCurrentSound->NextSound();
	}

	if( fHearSound )
	{
		m_OnHeardSound.FireOutput( this, this );
	}

	if (flMaxVolume != m_SoundLevel.Get())
	{
		//
		// Don't smooth if we are within an epsilon. This allows the output to stop firing
		// much more quickly.
		//
		if (fabs(flMaxVolume - m_SoundLevel.Get()) < MICROPHONE_SETTLE_EPSILON)
		{
			m_SoundLevel.Set(flMaxVolume, this, this);
		}
		else
		{
			m_SoundLevel.Set(flMaxVolume * (1 - m_flSmoothFactor) + m_SoundLevel.Get() * m_flSmoothFactor, this, this);
		}
	}

	SetNextThink( gpGlobals->curtime + 0.1f );
}