deargui-vpl/ref/virtools/Samples/Behaviors/Sound/behaviors src/EqControl.cpp

90 lines
2.8 KiB
C++

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
//
// EqControl
//
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
#include "CKALL.h"
CKERROR CreateEqControlBehaviorProto(CKBehaviorPrototype **pproto);
int EqControl(const CKBehaviorContext& behcontext);
CKObjectDeclaration *FillBehaviorEqControlDecl()
{
CKObjectDeclaration *od = CreateCKObjectDeclaration("Tone Control");
od->SetDescription("Sets the tone of a sound, regardless of whether it is playing or not.");
/* rem:
<SPAN CLASS=in>In: </SPAN>triggers the process<BR>
<SPAN CLASS=out>Out: </SPAN>is activated when the process is completed.<BR>
<BR>
<SPAN CLASS=pin>Tone: </SPAN>sets the tonal equalization of a sound, in a range of 0.0 to 1.0, with 1.0 being the highest.<BR>
<BR>
"Tone Control" BB applies an equalization effect to the source. It is similar in effect to
a treble control on a stereo system and is completely independent of distance and gain. It
is low-pass only and doesn't allow high frequencies to be boosted.<BR>
If 0.0 < Eq < 1.0, high frequencies are attenuated more as Eq approaches 0.0. The
default setting of 1.0 means there is no additional high frequency attenuation applied to
sources.<BR>
This method is useful for simulating different environments. For example, "Tone" = 0.3
would make the source sound very muffled, as if it was underwater.<BR>
*/
/* warning:
- "Tone Control" BB will only work with sound cards which support the effect, such as Vortex or
Vortex2 based sound cards.<BR>
*/
od->SetCategory("Sounds/Control");
od->SetType(CKDLL_BEHAVIORPROTOTYPE);
od->SetGuid(CKGUID(0x28dd2fbc,0x7099589e));
od->SetAuthorGuid(VIRTOOLS_GUID);
od->SetAuthorName("Virtools");
od->SetVersion(0x00010000);
od->SetCreationFunction(CreateEqControlBehaviorProto);
od->SetCompatibleClassId(CKCID_WAVESOUND);
od->NeedManager(SOUND_MANAGER_GUID);
return od;
}
CKERROR CreateEqControlBehaviorProto(CKBehaviorPrototype **pproto)
{
CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Tone Control");
if(!proto) return CKERR_OUTOFMEMORY;
proto->DeclareInput("In");
proto->DeclareOutput("Out");
proto->DeclareInParameter("Tone",CKPGUID_FLOAT,"1.0");
proto->SetBehaviorFlags(CKBEHAVIOR_TARGETABLE);
proto->SetFlags(CK_BEHAVIORPROTOTYPE_OBSOLETE);
proto->SetFunction(EqControl);
*pproto = proto;
return CK_OK;
}
int EqControl(const CKBehaviorContext& behcontext)
{
CKBehavior *beh = behcontext.Behavior;
beh->ActivateInput(0,FALSE);
beh->ActivateOutput(0);
CKWaveSound *wave=(CKWaveSound*)beh->GetTarget();
if( !wave ) return CKBR_OK;
float Tone=1.0f;
beh->GetInputParameterValue(0,&Tone);
wave->SetEq(Tone);
return CKBR_OK;
}