You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
8.4 KiB
254 lines
8.4 KiB
14 years ago
|
/*==LICENSE==*
|
||
|
|
||
|
CyanWorlds.com Engine - MMOG client, server and tools
|
||
13 years ago
|
Copyright (C) 2011 Cyan Worlds, Inc.
|
||
14 years ago
|
|
||
|
This program is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 years ago
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 years ago
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
13 years ago
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
|
Additional permissions under GNU GPL version 3 section 7
|
||
|
|
||
|
If you modify this Program, or any covered work, by linking or
|
||
|
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
|
||
|
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
|
||
|
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
|
||
|
(or a modified version of those libraries),
|
||
|
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
|
||
|
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
|
||
|
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
|
||
|
licensors of this Program grant you additional
|
||
|
permission to convey the resulting work. Corresponding Source for a
|
||
|
non-source form of such a combination shall include the source code for
|
||
|
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
|
||
|
work.
|
||
14 years ago
|
|
||
|
You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||
|
or by snail mail at:
|
||
|
Cyan Worlds, Inc.
|
||
|
14617 N Newport Hwy
|
||
|
Mead, WA 99021
|
||
|
|
||
|
*==LICENSE==*/
|
||
|
//////////////////////////////////////////////////////////////////////////////
|
||
|
// //
|
||
|
// plEAXListenerMod //
|
||
|
// //
|
||
|
//////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
13 years ago
|
#ifndef EAX_SDK_AVAILABLE
|
||
|
#include <EFX-Util.h>
|
||
|
#endif
|
||
14 years ago
|
#include "hsTypes.h"
|
||
|
#include "plEAXListenerMod.h"
|
||
|
#include "../plIntersect/plSoftVolume.h"
|
||
|
#include "hsResMgr.h"
|
||
|
#include "plgDispatch.h"
|
||
|
#include "plAudioSystem.h"
|
||
|
#include "../pnMessage/plAudioSysMsg.h"
|
||
|
|
||
13 years ago
|
#ifdef EAX_SDK_AVAILABLE
|
||
14 years ago
|
#include <eax-util.h>
|
||
13 years ago
|
#endif
|
||
14 years ago
|
|
||
|
|
||
|
plEAXListenerMod::plEAXListenerMod()
|
||
|
{
|
||
|
fListenerProps = TRACKED_NEW EAXREVERBPROPERTIES;
|
||
|
fSoftRegion = nil;
|
||
|
fRegistered = false;
|
||
|
fGetsMessages = false;
|
||
|
|
||
13 years ago
|
#ifdef EAX_SDK_AVAILABLE
|
||
14 years ago
|
memcpy( fListenerProps, &REVERB_ORIGINAL_PRESETS[ ORIGINAL_GENERIC ], sizeof( EAXREVERBPROPERTIES ) );
|
||
13 years ago
|
#endif
|
||
14 years ago
|
}
|
||
|
|
||
|
plEAXListenerMod::~plEAXListenerMod()
|
||
|
{
|
||
|
// Tell the audio sys we're going away
|
||
|
IUnRegister();
|
||
|
|
||
|
// Unregister for audioSys messages
|
||
|
if( fGetsMessages )
|
||
|
{
|
||
|
plgDispatch::Dispatch()->UnRegisterForExactType( plAudioSysMsg::Index(), GetKey() );
|
||
|
fGetsMessages = false;
|
||
|
}
|
||
|
|
||
|
delete fListenerProps;
|
||
|
}
|
||
|
|
||
|
void plEAXListenerMod::IRegister( void )
|
||
|
{
|
||
|
if( !fGetsMessages )
|
||
|
{
|
||
|
plgDispatch::Dispatch()->RegisterForExactType( plAudioSysMsg::Index(), GetKey() );
|
||
|
fGetsMessages = true;
|
||
|
}
|
||
|
|
||
|
if( fRegistered || GetKey() == nil )
|
||
|
return;
|
||
|
|
||
|
plKey sysKey = hsgResMgr::ResMgr()->FindKey( plUoid( kAudioSystem_KEY ) );
|
||
|
if( sysKey != nil )
|
||
|
{
|
||
|
plGenRefMsg *refMsg = TRACKED_NEW plGenRefMsg( sysKey, plRefMsg::kOnCreate, 0, plAudioSystem::kRefEAXRegion );
|
||
|
hsgResMgr::ResMgr()->AddViaNotify( GetKey(), refMsg, plRefFlags::kPassiveRef );
|
||
|
fRegistered = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void plEAXListenerMod::IUnRegister( void )
|
||
|
{
|
||
|
if( !fRegistered || GetKey() == nil )
|
||
|
return;
|
||
|
|
||
|
plKey sysKey = hsgResMgr::ResMgr()->FindKey( plUoid( kAudioSystem_KEY ) );
|
||
|
if( sysKey != nil && GetKey() != nil )
|
||
|
sysKey->Release( GetKey() );
|
||
|
|
||
|
fRegistered = false;
|
||
|
}
|
||
|
|
||
|
hsBool plEAXListenerMod::IEval( double secs, hsScalar del, UInt32 dirty )
|
||
|
{
|
||
|
IRegister();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
hsBool plEAXListenerMod::MsgReceive( plMessage* pMsg )
|
||
|
{
|
||
|
plGenRefMsg *refMsg = plGenRefMsg::ConvertNoRef( pMsg );
|
||
|
if( refMsg != nil )
|
||
|
{
|
||
|
switch( refMsg->fType )
|
||
|
{
|
||
|
case kRefSoftRegion:
|
||
|
if( refMsg->GetContext() & ( plRefMsg::kOnCreate | plRefMsg::kOnRequest | plRefMsg::kOnReplace ) )
|
||
|
{
|
||
|
fSoftRegion = plSoftVolume::ConvertNoRef( refMsg->GetRef() );
|
||
|
fSoftRegion->SetCheckListener();
|
||
|
}
|
||
|
else if( refMsg->GetContext() & ( plRefMsg::kOnRemove | plRefMsg::kOnDestroy ) )
|
||
|
{
|
||
|
fSoftRegion = nil;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
plAudioSysMsg *sysMsg = plAudioSysMsg::ConvertNoRef( pMsg );
|
||
|
if( sysMsg != nil )
|
||
|
{
|
||
|
if( sysMsg->GetAudFlag() == plAudioSysMsg::kActivate )
|
||
|
{
|
||
|
IRegister();
|
||
|
}
|
||
|
else if( sysMsg->GetAudFlag() == plAudioSysMsg::kDeActivate )
|
||
|
{
|
||
|
IUnRegister();
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return plSingleModifier::MsgReceive( pMsg );
|
||
|
}
|
||
|
|
||
|
void plEAXListenerMod::Read( hsStream* s, hsResMgr* mgr )
|
||
|
{
|
||
|
plSingleModifier::Read( s, mgr );
|
||
|
|
||
|
// Read in the soft region
|
||
|
mgr->ReadKeyNotifyMe( s, TRACKED_NEW plGenRefMsg( GetKey(), plRefMsg::kOnCreate, 0, kRefSoftRegion ), plRefFlags::kActiveRef );
|
||
|
|
||
|
// Read the listener params
|
||
|
fListenerProps->ulEnvironment = s->ReadSwap32();
|
||
|
fListenerProps->flEnvironmentSize = s->ReadSwapFloat();
|
||
|
fListenerProps->flEnvironmentDiffusion = s->ReadSwapFloat();
|
||
|
fListenerProps->lRoom = s->ReadSwap32();
|
||
|
fListenerProps->lRoomHF = s->ReadSwap32();
|
||
|
fListenerProps->lRoomLF = s->ReadSwap32();
|
||
|
fListenerProps->flDecayTime = s->ReadSwapFloat();
|
||
|
fListenerProps->flDecayHFRatio = s->ReadSwapFloat();
|
||
|
fListenerProps->flDecayLFRatio = s->ReadSwapFloat();
|
||
|
fListenerProps->lReflections = s->ReadSwap32();
|
||
|
fListenerProps->flReflectionsDelay = s->ReadSwapFloat();
|
||
|
//fListenerProps->vReflectionsPan; // early reflections panning vector
|
||
|
fListenerProps->lReverb = s->ReadSwap32(); // late reverberation level relative to room effect
|
||
|
fListenerProps->flReverbDelay = s->ReadSwapFloat();
|
||
|
//fListenerProps->vReverbPan; // late reverberation panning vector
|
||
|
fListenerProps->flEchoTime = s->ReadSwapFloat();
|
||
|
fListenerProps->flEchoDepth = s->ReadSwapFloat();
|
||
|
fListenerProps->flModulationTime = s->ReadSwapFloat();
|
||
|
fListenerProps->flModulationDepth = s->ReadSwapFloat();
|
||
|
fListenerProps->flAirAbsorptionHF = s->ReadSwapFloat();
|
||
|
fListenerProps->flHFReference = s->ReadSwapFloat();
|
||
|
fListenerProps->flLFReference = s->ReadSwapFloat();
|
||
|
fListenerProps->flRoomRolloffFactor = s->ReadSwapFloat();
|
||
|
fListenerProps->ulFlags = s->ReadSwap32();
|
||
|
|
||
|
// Done reading, time to tell the audio sys we exist
|
||
|
IRegister();
|
||
|
}
|
||
|
|
||
|
void plEAXListenerMod::Write( hsStream* s, hsResMgr* mgr )
|
||
|
{
|
||
|
plSingleModifier::Write( s, mgr );
|
||
|
|
||
|
// Write the soft region key
|
||
|
mgr->WriteKey( s, fSoftRegion );
|
||
|
|
||
|
// Write the listener params
|
||
|
s->WriteSwap32( fListenerProps->ulEnvironment );
|
||
|
s->WriteSwapFloat( fListenerProps->flEnvironmentSize );
|
||
|
s->WriteSwapFloat( fListenerProps->flEnvironmentDiffusion );
|
||
|
s->WriteSwap32( fListenerProps->lRoom );
|
||
|
s->WriteSwap32( fListenerProps->lRoomHF );
|
||
|
s->WriteSwap32( fListenerProps->lRoomLF );
|
||
|
s->WriteSwapFloat( fListenerProps->flDecayTime );
|
||
|
s->WriteSwapFloat( fListenerProps->flDecayHFRatio );
|
||
|
s->WriteSwapFloat( fListenerProps->flDecayLFRatio );
|
||
|
s->WriteSwap32( fListenerProps->lReflections );
|
||
|
s->WriteSwapFloat( fListenerProps->flReflectionsDelay );
|
||
|
//s->WriteSwapFloat( fListenerProps->vReflectionsPan; // early reflections panning vector
|
||
|
s->WriteSwap32( fListenerProps->lReverb ); // late reverberation level relative to room effect
|
||
|
s->WriteSwapFloat( fListenerProps->flReverbDelay );
|
||
|
//s->WriteSwapFloat( fListenerProps->vReverbPan; // late reverberation panning vector
|
||
|
s->WriteSwapFloat( fListenerProps->flEchoTime );
|
||
|
s->WriteSwapFloat( fListenerProps->flEchoDepth );
|
||
|
s->WriteSwapFloat( fListenerProps->flModulationTime );
|
||
|
s->WriteSwapFloat( fListenerProps->flModulationDepth );
|
||
|
s->WriteSwapFloat( fListenerProps->flAirAbsorptionHF );
|
||
|
s->WriteSwapFloat( fListenerProps->flHFReference );
|
||
|
s->WriteSwapFloat( fListenerProps->flLFReference );
|
||
|
s->WriteSwapFloat( fListenerProps->flRoomRolloffFactor );
|
||
|
s->WriteSwap32( fListenerProps->ulFlags );
|
||
|
}
|
||
|
|
||
|
|
||
|
void plEAXListenerMod::SetFromPreset( UInt32 preset )
|
||
|
{
|
||
13 years ago
|
#ifdef EAX_SDK_AVAILABLE
|
||
14 years ago
|
memcpy( fListenerProps, &REVERB_ORIGINAL_PRESETS[ preset ], sizeof( EAXREVERBPROPERTIES ) );
|
||
13 years ago
|
#endif
|
||
14 years ago
|
}
|
||
|
|
||
|
float plEAXListenerMod::GetStrength( void )
|
||
|
{
|
||
|
if( fSoftRegion == nil )
|
||
|
return 0.f;
|
||
|
|
||
|
return fSoftRegion->GetListenerStrength();
|
||
|
}
|