Esempio n. 1
0
VOID AudioPlay(HSOUND sound, VEC2 position)
{
    /* use the opportunity to clean up */
    DestroyQueuedInstances();

    if (sound != INVALID_HSOUND_VALUE &&
        sound < MAX_SOUNDS)
    {
        float dist = Vec2Len(Vec2Add(position, Vec2Neg(g_player.Position)));
        float maxDist = 15;
        float falloff = 1 - max(min(dist / maxDist, 1), 0);

        assert(g_sounds[sound].Data);

        if ((AudioIsSFX(sound) && g_soundsEnabled) ||
            (!AudioIsSFX(sound) && g_musicEnabled))
        {
            PSOUNDINSTANCE instance = CreateSoundInstance(&g_sounds[sound]);
            if (instance && falloff > 0)
            {
                waveOutSetVolume(instance->WaveOut, instance->Volume * falloff);
                waveOutWrite(instance->WaveOut, instance->Header, sizeof(WAVEHDR));
            }
        }
    }
}
ISoundInstance* FMODAudioSystem::Play( const SimpleString& DefinitionName, const Vector& Location )
{
	ISoundInstance* const pInstance = CreateSoundInstance( DefinitionName );
	ASSERT( pInstance );

	// Set variables, then unpause
	pInstance->SetLocation( Location );

	// Apply reverb
	for( uint i = 0; i < m_ReverbCategories.Size(); ++i )
	{
		if( pInstance->GetCategory() == m_ReverbCategories[i] )
		{
			// HACKY, but I don't really need to wrap channel groups in my own
			// custom interface when I'm using them for like ONE THING.
			( ( FMODSoundInstance* )pInstance )->m_Channel->setChannelGroup( m_ReverbGroup );
			break;
		}
	}

	pInstance->Tick();	// To make sure all changes are applied
	pInstance->SetPaused( false );

	return pInstance;
}