|
From: <man...@us...> - 2013-05-24 20:01:49
|
Revision: 2182
http://sourceforge.net/p/modplug/code/2182
Author: manxorist
Date: 2013-05-24 20:01:34 +0000 (Fri, 24 May 2013)
Log Message:
-----------
[Mod] Remove rather questionable frequency rounding in TransposeToFrequency which was inherited from the modplug codebase.
[Mod] Remove other questionable rounding and frequency clamping in ReadNote(). Hope that nothing breaks.
[Ref] Remove inline asm in really not performance cirtical codepaths (TransposeToFrequency, FrequencyToTranspose, PatchFreqToNote) and replace it with a readable c++ implementation.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/ModSample.cpp
trunk/OpenMPT/soundlib/SampleFormats.cpp
trunk/OpenMPT/soundlib/Sndmix.cpp
Modified: trunk/OpenMPT/soundlib/ModSample.cpp
===================================================================
--- trunk/OpenMPT/soundlib/ModSample.cpp 2013-05-24 12:42:41 UTC (rev 2181)
+++ trunk/OpenMPT/soundlib/ModSample.cpp 2013-05-24 20:01:34 UTC (rev 2182)
@@ -185,45 +185,10 @@
/////////////////////////////////////////////////////////////
// Transpose <-> Frequency conversions
-// returns 8363*2^((transp*128+ftune)/(12*128))
uint32 ModSample::TransposeToFrequency(int transpose, int finetune)
//-----------------------------------------------------------------
{
- // return (unsigned int) (8363.0 * pow(2, (transp * 128.0 + ftune) / 1536.0));
- const float _fbase = 8363;
- const float _factor = 1.0f / (12.0f * 128.0f);
- uint32 freq;
-
-#if defined(ENABLE_X86)
- int result;
- transpose = (transpose << 7) + finetune;
- _asm
- {
- fild transpose
- fld _factor
- fmulp st(1), st(0)
- fist result
- fisub result
- f2xm1
- fild result
- fld _fbase
- fscale
- fstp st(1)
- fmul st(1), st(0)
- faddp st(1), st(0)
- fistp freq
- }
-#else // !ENABLE_X86
- freq = static_cast<uint32>(std::pow(2.0f, (transpose * 128 + finetune) * _factor) * _fbase);
-#endif // ENABLE_X86
-
- uint32 derr = freq % 11025;
- if(derr <= 8) freq -= derr;
- if(derr >= 11015) freq += 11025 - derr;
- derr = freq % 1000;
- if(derr <= 5) freq -= derr;
- if(derr >= 995) freq += 1000 - derr;
- return freq;
+ return Util::Round<uint32>(std::pow(2.0f, (transpose * 128.0f + finetune) * (1.0f / (12.0f * 128.0f))) * 8363.0f);
}
@@ -234,36 +199,11 @@
}
-// returns 12*128*log2(freq/8363)
int ModSample::FrequencyToTranspose(uint32 freq)
//----------------------------------------------
{
- // return (int) (1536.0 * (log(freq / 8363.0) / log(2)));
-
- const float _f1_8363 = 1.0f / 8363.0f;
- const float _factor = 128 * 12;
- int result;
-
- if(!freq)
- {
- return 0;
- }
-
-#if defined(ENABLE_X86)
- _asm
- {
- fld _factor
- fild freq
- fld _f1_8363
- fmulp st(1), st(0)
- fyl2x
- fistp result
- }
-#else // !ENABLE_X86
const float inv_log_2 = 1.44269504089f; // 1.0f/std::log(2.0f)
- result = std::log(freq * _f1_8363) * (_factor * inv_log_2);
-#endif // ENABLE_X86
- return result;
+ return Util::Round<int>(std::log(freq * (1.0f / 8363.0f)) * (12.0f * 128.0f * inv_log_2));
}
Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp
===================================================================
--- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-05-24 12:42:41 UTC (rev 2181)
+++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-05-24 20:01:34 UTC (rev 2182)
@@ -677,28 +677,12 @@
#pragma pack(pop)
#endif
-// returns 12*Log2(nFreq/2044)
-LONG PatchFreqToNote(ULONG nFreq)
-//-------------------------------
+static int32 PatchFreqToNote(uint32 nFreq)
+//----------------------------------------
{
- const float k_base = 1.0f / 2044.0f;
- const float k_12 = 12;
- LONG result;
- if (nFreq < 1) return 0;
-#if defined(ENABLE_X86)
- _asm {
- fld k_12
- fild nFreq
- fld k_base
- fmulp ST(1), ST(0)
- fyl2x
- fistp result
- }
-#else // !ENABLE_X86
const float inv_log_2 = 1.44269504089f; // 1.0f/std::log(2.0f)
- result = std::log(nFreq * k_base) * (k_12 * inv_log_2);
-#endif // ENABLE_X86
- return result;
+ const float base = 1.0f / 2044.0f;
+ return Util::Round<int32>(std::log(nFreq * base) * (12.0f * inv_log_2));
}
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-05-24 12:42:41 UTC (rev 2181)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-05-24 20:01:34 UTC (rev 2182)
@@ -1906,13 +1906,15 @@
pChn->nCalcVolume = 0;
}
- int32 ninc = Util::muldiv(freq, 0x10000, m_MixerSettings.gdwMixingFreq << FREQ_FRACBITS);
- if ((ninc >= 0xFFB0) && (ninc <= 0x10090)) ninc = 0x10000;
+ uint32 ninc = Util::muldivr(freq, 0x10000, m_MixerSettings.gdwMixingFreq << FREQ_FRACBITS);
#ifndef MODPLUG_TRACKER
ninc = Util::muldivr(ninc, m_nFreqFactor, 128);
#endif // !MODPLUG_TRACKER
- Limit(ninc, 3, 0xFF0000);
- pChn->nInc = (ninc + 1) & ~3;
+ if(ninc == 0)
+ {
+ ninc = 1;
+ }
+ pChn->nInc = ninc;
} else
{
// Avoid nasty noises...
@@ -2008,27 +2010,19 @@
//if (pChn->nNewRightVol > 0xFFFF) pChn->nNewRightVol = 0xFFFF;
//if (pChn->nNewLeftVol > 0xFFFF) pChn->nNewLeftVol = 0xFFFF;
- ResamplingMode resamplingMode = m_Resampler.m_Settings.SrcMode; // default to global mixer settings
- if(pChn->pModInstrument && IsKnownResamplingMode(pChn->pModInstrument->nResampling))
- {
- // for defined resampling modes, use per-instrument resampling modes if set
- resamplingMode = (ResamplingMode)pChn->pModInstrument->nResampling;
- }
- // disable interpolation in certain cases
if(pChn->nInc == 0x10000)
{
// exact samplerate match, do not resample at all, regardless of selected resampler
- resamplingMode = SRCMODE_NEAREST;
- } else if(resamplingMode == SRCMODE_LINEAR)
+ pChn->resamplingMode = SRCMODE_NEAREST;
+ } else if(pChn->pModInstrument && IsKnownResamplingMode(pChn->pModInstrument->nResampling))
{
- if(((pChn->nInc >= 0xFF00) && (pChn->nInc < 0x10100)))
- {
- // disable interpolation if rates are too close
- resamplingMode = SRCMODE_NEAREST;
- }
+ // for defined resampling modes, use per-instrument resampling mode if set
+ pChn->resamplingMode = (ResamplingMode)pChn->pModInstrument->nResampling;
+ } else
+ {
+ // default to global mixer settings
+ pChn->resamplingMode = m_Resampler.m_Settings.SrcMode;
}
- // store for the mixer
- pChn->resamplingMode = (uint8)resamplingMode;
/*if (m_pConfig->getUseGlobalPreAmp())
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|