Difference between revisions of "Creating dynamic sounds with FMOD"

From Heroes of Hammerwatch wiki
Jump to: navigation, search
(page created.)
 
(Controlling the parameter in your mod scripts)
Line 20: Line 20:
 
==Controlling the parameter in your mod scripts==
 
==Controlling the parameter in your mod scripts==
  
WIP hold on getting some code example goin'.
+
You will need to use you own sValue parameter rather than the standard ones. For example: If you want to have a dynamic shoot sound, do not use the "shoot-snd" parameter because this used by the base projectile classes and would be difficult to alter how it is controlled.
 +
 
 +
BAD:
 +
 
 +
<string name="shoot-snd">{5567e7f1-bf44-420c-a7b8-fc8c1ee2f628}</string>
 +
 
 +
GOOD:
 +
 
 +
<string name="custom-shoot-snd">{5567e7f1-bf44-420c-a7b8-fc8c1ee2f628}</string>
 +
 
 +
Continuing with the dynamic shoot sound example, you would need to have a custom projectile script that extends the desired type of projectile. Load in your sound sVal parameter, override the Initialize method, call the base class' Initialize method, then play your sound by calling PlaySound3D with a dictionary of your parameter:
 +
 
 +
class DynamicSoundBeam : BeamProjectile
 +
{
 +
SoundEvent@ customShootSound;
 +
 +
DynamicSoundBeam(UnitPtr unit, SValue& params)
 +
{
 +
super(unit, params);
 +
 +
@customShootSound = Resources::GetSoundEvent(GetParamString(unit, params, "custom-shoot-snd", false));
 +
}
 +
 +
void Initialize(Actor@ owner, vec2 dir, float intensity, bool husk, Actor@ target, uint weapon) override
 +
{
 +
BeamProjectile::Initialize(owner, dir, intensity, husk, target, weapon);
 +
 +
m_pos = xy(m_unit.GetPosition());
 +
 +
float paramValue = 0.7 // <---- your beautiful dynamic parameter logic here
 +
 +
dictionary params = { { "MyParameter", paramValue } };
 +
PlaySound3D(customShootSound, m_unit.GetPosition(), params);
 +
}
 +
}

Revision as of 06:17, 7 November 2020

It is possible to create dynamic sounds and music for you mod using parameters in FMOD.

This page assumes you already have FMOD set up for you Heroes of Hammerwatch mod. See Adding custom sounds and music for more information.

Adding a parameter to your sound event in FMOD

Open your event in FMOD use the "+" tab above the tracks to add a new parameter.

AddingFmodParameter.png

If you haven't created the effect that you want to be dynamic, go ahead and do that now.

AddingFmodEffect.png

Right-click on the knob that you want to be dynamically controlled, and select "Add Automation". Your should now see a track for that setting in the track deck.

In the new tab for your parameter, add you desired control points to determine how the setting is changed based on the parameter. There is a scale above the tracks showing the range of your parameter, and above that is a knob for your parameter to test how different values sound. you can also set a default value by right clicking on your parameter knob.

ParameterTabExample.png

Controlling the parameter in your mod scripts

You will need to use you own sValue parameter rather than the standard ones. For example: If you want to have a dynamic shoot sound, do not use the "shoot-snd" parameter because this used by the base projectile classes and would be difficult to alter how it is controlled.

BAD:

<string name="shoot-snd">{5567e7f1-bf44-420c-a7b8-fc8c1ee2f628}</string>

GOOD:

<string name="custom-shoot-snd">{5567e7f1-bf44-420c-a7b8-fc8c1ee2f628}</string>

Continuing with the dynamic shoot sound example, you would need to have a custom projectile script that extends the desired type of projectile. Load in your sound sVal parameter, override the Initialize method, call the base class' Initialize method, then play your sound by calling PlaySound3D with a dictionary of your parameter:

class DynamicSoundBeam : BeamProjectile
{
	SoundEvent@ customShootSound;
	
	DynamicSoundBeam(UnitPtr unit, SValue& params)
	{
		super(unit, params);
		
		@customShootSound = Resources::GetSoundEvent(GetParamString(unit, params, "custom-shoot-snd", false));
	}
	
	void Initialize(Actor@ owner, vec2 dir, float intensity, bool husk, Actor@ target, uint weapon) override
	{
		BeamProjectile::Initialize(owner, dir, intensity, husk, target, weapon);
		
		m_pos = xy(m_unit.GetPosition());

		float paramValue = 0.7 // <---- your beautiful dynamic parameter logic here

		dictionary params = { { "MyParameter", paramValue } };
		PlaySound3D(customShootSound, m_unit.GetPosition(), params);	
	}
}