|
From: <sag...@us...> - 2014-11-07 21:13:17
|
Revision: 4558
http://sourceforge.net/p/modplug/code/4558
Author: saga-games
Date: 2014-11-07 21:13:10 +0000 (Fri, 07 Nov 2014)
Log Message:
-----------
[Ref] Convert InstrumentEnvelope::GetValueFromPosition back to using fixed point integer (fix possible performance loss on CPUs without hard floats, since this function may be called somewhat frequently in the mixer, and we really don't need floats here)
Modified Paths:
--------------
trunk/OpenMPT/soundlib/ModInstrument.cpp
trunk/OpenMPT/soundlib/ModInstrument.h
trunk/OpenMPT/soundlib/Snd_fx.cpp
trunk/OpenMPT/soundlib/Sndmix.cpp
Modified: trunk/OpenMPT/soundlib/ModInstrument.cpp
===================================================================
--- trunk/OpenMPT/soundlib/ModInstrument.cpp 2014-11-07 10:55:50 UTC (rev 4557)
+++ trunk/OpenMPT/soundlib/ModInstrument.cpp 2014-11-07 21:13:10 UTC (rev 4558)
@@ -49,7 +49,7 @@
if(Ticks[nLoopEnd] - 1 > Ticks[nLoopEnd - 1])
{
// Insert an interpolated point just before the loop point.
- uint8 interpolatedValue = Util::Round<uint8>(GetValueFromPosition(Ticks[nLoopEnd] - 1) * 64.0f);
+ uint8 interpolatedValue = static_cast<uint8>(GetValueFromPosition(Ticks[nLoopEnd] - 1, 64));
if(nNodes + 1 < MAX_ENVPOINTS)
@@ -77,10 +77,11 @@
// Get envelope value at a given tick. Returns value in range [0.0, 1.0].
-float InstrumentEnvelope::GetValueFromPosition(int position, int range) const
-//---------------------------------------------------------------------------
+int32 InstrumentEnvelope::GetValueFromPosition(int position, int32 rangeOut, int32 rangeIn) const
+//-----------------------------------------------------------------------------------------------
{
uint32 pt = nNodes - 1u;
+ const int32 ENV_PRECISION = 1 << 16;
// Checking where current 'tick' is relative to the envelope points.
for(uint32 i = 0; i < nNodes - 1u; i++)
@@ -93,12 +94,12 @@
}
int x2 = Ticks[pt];
- float value = 0.0f;
+ int32 value = 0;
if(position >= x2)
{
// Case: current 'tick' is on a envelope point.
- value = static_cast<float>(Values[pt]) / float(range);
+ value = Values[pt] * ENV_PRECISION / rangeIn;
} else
{
// Case: current 'tick' is between two envelope points.
@@ -107,7 +108,7 @@
if(pt)
{
// Get previous node's value and tick.
- value = static_cast<float>(Values[pt - 1]) / float(range);
+ value = Values[pt - 1] * ENV_PRECISION / rangeIn;
x1 = Ticks[pt - 1];
}
@@ -115,11 +116,12 @@
{
// Linear approximation between the points;
// f(x + d) ~ f(x) + f'(x) * d, where f'(x) = (y2 - y1) / (x2 - x1)
- value += ((position - x1) * (static_cast<float>(Values[pt]) / float(range) - value)) / (x2 - x1);
+ value += ((position - x1) * (Values[pt] * ENV_PRECISION / rangeIn - value)) / (x2 - x1);
}
}
- return Clamp(value, 0.0f, 1.0f);
+ Limit(value, 0, ENV_PRECISION);
+ return (value * rangeOut + ENV_PRECISION / 2) / ENV_PRECISION;
}
Modified: trunk/OpenMPT/soundlib/ModInstrument.h
===================================================================
--- trunk/OpenMPT/soundlib/ModInstrument.h 2014-11-07 10:55:50 UTC (rev 4557)
+++ trunk/OpenMPT/soundlib/ModInstrument.h 2014-11-07 21:13:10 UTC (rev 4558)
@@ -44,8 +44,9 @@
// Convert envelope data between various formats.
void Convert(MODTYPE fromType, MODTYPE toType);
- // Get envelope value at a given tick. Returns value in range [0.0, 1.0].
- float GetValueFromPosition(int position, int range = ENVELOPE_MAX) const;
+ // Get envelope value at a given tick. Assumes that the envelope data is in rage [0, rangeIn],
+ // returns value in range [0, rangeOut].
+ int32 GetValueFromPosition(int position, int32 rangeOut, int32 rangeIn = ENVELOPE_MAX) const;
};
Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Snd_fx.cpp 2014-11-07 10:55:50 UTC (rev 4557)
+++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2014-11-07 21:13:10 UTC (rev 4558)
@@ -4773,7 +4773,7 @@
if (pIns->VolEnv.nReleaseNode != ENV_RELEASE_NODE_UNSET)
{
- pChn->VolEnv.nEnvValueAtReleaseJump = Util::Round<int32>(pIns->VolEnv.GetValueFromPosition(pChn->VolEnv.nEnvPosition) * 256.0f);
+ pChn->VolEnv.nEnvValueAtReleaseJump = pIns->VolEnv.GetValueFromPosition(pChn->VolEnv.nEnvPosition, 256);
pChn->VolEnv.nEnvPosition = pIns->VolEnv.Ticks[pIns->VolEnv.nReleaseNode];
}
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2014-11-07 10:55:50 UTC (rev 4557)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2014-11-07 21:13:10 UTC (rev 4558)
@@ -816,7 +816,7 @@
}
const int envpos = pChn->VolEnv.nEnvPosition - (IsCompatibleMode(TRK_IMPULSETRACKER) ? 1 : 0);
// Get values in [0, 256]
- int envval = Util::Round<int>(pIns->VolEnv.GetValueFromPosition(envpos) * 256.0f);
+ int envval = pIns->VolEnv.GetValueFromPosition(envpos, 256);
// if we are in the release portion of the envelope,
// rescale envelope factor so that it is proportional to the release point
@@ -858,7 +858,7 @@
const int envpos = pChn->PanEnv.nEnvPosition - (IsCompatibleMode(TRK_IMPULSETRACKER) ? 1 : 0);
// Get values in [-32, 32]
- const int envval = Util::Round<int>((pIns->PanEnv.GetValueFromPosition(envpos) - 0.5f) * 64.0f);
+ const int envval = pIns->PanEnv.GetValueFromPosition(envpos, 64) - 32;
int pan = pChn->nRealPan;
if(pan >= 128)
@@ -890,15 +890,15 @@
const int envpos = pChn->PitchEnv.nEnvPosition - (IsCompatibleMode(TRK_IMPULSETRACKER) ? 1 : 0);
// Get values in [-256, 256]
#ifdef MODPLUG_TRACKER
- const int range = ENVELOPE_MAX;
- const float amp = 512.0f;
+ const int32 range = ENVELOPE_MAX;
+ const int32 amp = 512;
#else
// TODO: AMS2 envelopes behave differently when linear slides are off - emulate with 15 * (-128...127) >> 6
// Copy over vibrato behaviour for that?
- const int range = GetType() == MOD_TYPE_AMS2 ? uint8_max : ENVELOPE_MAX;
- const float amp = GetType() == MOD_TYPE_AMS2 ? 64.0f : 512.0f;
+ const int32 range = GetType() == MOD_TYPE_AMS2 ? uint8_max : ENVELOPE_MAX;
+ const int32 amp = GetType() == MOD_TYPE_AMS2 ? 64 : 512;
#endif
- const int envval = Util::Round<int>((pIns->PitchEnv.GetValueFromPosition(envpos, range) - 0.5f) * amp);
+ const int envval = pIns->PitchEnv.GetValueFromPosition(envpos, amp, range) - amp / 2;
if(pChn->PitchEnv.flags[ENV_FILTER])
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|