|
From: <man...@us...> - 2013-06-07 18:08:26
|
Revision: 2313
http://sourceforge.net/p/modplug/code/2313
Author: manxorist
Date: 2013-06-07 18:08:18 +0000 (Fri, 07 Jun 2013)
Log Message:
-----------
[Ref] Add 1:1 bit-exact C translation of X86_Dither().
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Fastmix.cpp
trunk/OpenMPT/soundlib/Sndmix.cpp
trunk/OpenMPT/soundlib/Waveform.cpp
Modified: trunk/OpenMPT/soundlib/Fastmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-07 00:24:30 UTC (rev 2312)
+++ trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-07 18:08:18 UTC (rev 2313)
@@ -2089,6 +2089,7 @@
#ifdef ENABLE_X86
+
void X86_Dither(int *pBuffer, UINT nSamples, UINT nBits)
//------------------------------------------------------
{
@@ -2116,18 +2117,6 @@
mov edx, ebx
sar edx, cl
add eax, edx
-/*
- int a = 0, b = 0;
- for (UINT i=0; i<len; i++)
- {
- a = (a << 1) | (((DWORD)a) >> (BYTE)31);
- a ^= 0x10204080;
- a += 0x78649E7D + (b << 2);
- b += ((a << 16) | (a >> 16)) * 5;
- int c = a + b;
- p[i] = ((signed char)c ) >> 1;
- }
-*/
dec ebp
mov dword ptr [esi-4], eax
jnz noiseloop
@@ -2136,9 +2125,52 @@
mov gDitherB, ebx
}
}
-#endif
+#endif // ENABLE_X86
+
+static forceinline int32 dither_rand(uint32 &a, uint32 &b)
+//--------------------------------------------------------
+{
+ a = (a << 1) | (a >> 31);
+ a ^= 0x10204080u;
+ a += 0x78649E7Du + (b * 4);
+ b += ((a << 16 ) | (a >> 16)) * 5;
+ return (int32)b;
+}
+
+static void C_Dither(int *pBuffer, UINT nSamples, UINT nBits)
+//-----------------------------------------------------------
+{
+
+ static uint32 global_a = 0;
+ static uint32 global_b = 0;
+
+ uint32 a = global_a;
+ uint32 b = global_b;
+
+ while(nSamples--)
+ {
+ *pBuffer += dither_rand(a, b) >> (nBits + MIXING_ATTENUATION + 1);
+ pBuffer++;
+ }
+
+ global_a = a;
+ global_b = b;
+
+}
+
+void Dither(int *pBuffer, UINT nSamples, UINT nBits)
+//--------------------------------------------------
+{
+ #if defined(ENABLE_X86)
+ X86_Dither(pBuffer, nSamples, nBits);
+ #else
+ C_Dither(pBuffer, nSamples, nBits);
+ #endif
+}
+
+
#ifdef ENABLE_X86
static void X86_InterleaveFrontRear(int *pFrontBuf, int *pRearBuf, DWORD nFrames)
//-------------------------------------------------------------------------------
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-07 00:24:30 UTC (rev 2312)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-07 18:08:18 UTC (rev 2313)
@@ -62,9 +62,7 @@
-#ifdef ENABLE_X86
-extern VOID X86_Dither(int *pBuffer, UINT nSamples, UINT nBits);
-#endif
+extern void Dither(int *pBuffer, UINT nSamples, UINT nBits);
extern void InterleaveFrontRear(int *pFrontBuf, int *pRearBuf, DWORD nFrames);
extern void StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs);
extern void MonoFromStereo(int *pMixBuf, UINT nSamples);
@@ -364,14 +362,12 @@
lTotalSampleCount *= 2;
}
-#ifdef ENABLE_X86
// Noise Shaping
if (m_MixerSettings.GetBitsPerSample() <= 16)
{
if(m_Resampler.IsHQ())
- X86_Dither(MixSoundBuffer, lTotalSampleCount, m_MixerSettings.GetBitsPerSample());
+ Dither(MixSoundBuffer, lTotalSampleCount, m_MixerSettings.GetBitsPerSample());
}
-#endif
#ifdef MODPLUG_TRACKER
// Hook Function
Modified: trunk/OpenMPT/soundlib/Waveform.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Waveform.cpp 2013-06-07 00:24:30 UTC (rev 2312)
+++ trunk/OpenMPT/soundlib/Waveform.cpp 2013-06-07 18:08:18 UTC (rev 2313)
@@ -53,9 +53,7 @@
#endif
-#ifdef ENABLE_X86
-extern void X86_Dither(int *pBuffer, UINT nSamples, UINT nBits);
-#endif
+extern void Dither(int *pBuffer, UINT nSamples, UINT nBits);
extern DWORD Convert32To8(LPVOID lpBuffer, int *, DWORD nSamples);
extern DWORD Convert32To16(LPVOID lpBuffer, int *, DWORD nSamples);
extern DWORD Convert32To24(LPVOID lpBuffer, int *, DWORD nSamples);
@@ -70,7 +68,7 @@
{
int nbuf = (n > MIXBUFFERSIZE * 2) ? MIXBUFFERSIZE * 2 : n;
X86_Normalize24BitBuffer(pbuffer, nbuf, lmax24, tempbuf);
- X86_Dither(tempbuf, nbuf, 8 * dwByteInc);
+ Dither(tempbuf, nbuf, 8 * dwByteInc);
switch(dwByteInc)
{
case 2: Convert32To16(pbuffer, tempbuf, nbuf); break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|