From: <man...@us...> - 2013-03-25 16:48:22
|
Revision: 1672 http://sourceforge.net/p/modplug/code/1672 Author: manxorist Date: 2013-03-25 16:48:14 +0000 (Mon, 25 Mar 2013) Log Message: ----------- [Ref] Properly encapsulate Surround, MegaBass and NoiseReduction into a seperate class CDSP and remove a lot of global variables while at it. CSoundFile::m_DSP is still global though at the moment. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/sounddsp/DSP.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Added Paths: ----------- trunk/OpenMPT/sounddsp/DSP.h Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-03-25 16:48:14 UTC (rev 1672) @@ -510,9 +510,9 @@ // Bass Expansion m_SbXBassDepth.SetRange(0,4); - m_SbXBassDepth.SetPos(8-CSoundFile::m_nXBassDepth); + m_SbXBassDepth.SetPos(8-CSoundFile::m_DSP.m_Settings.m_nXBassDepth); m_SbXBassRange.SetRange(0,4); - m_SbXBassRange.SetPos(4 - (CSoundFile::m_nXBassRange - 1) / 5); + m_SbXBassRange.SetPos(4 - (CSoundFile::m_DSP.m_Settings.m_nXBassRange - 1) / 5); // Reverb m_SbReverbDepth.SetRange(1, 16); m_SbReverbDepth.SetPos(CSoundFile::m_nReverbDepth); @@ -539,13 +539,13 @@ } // Surround { - UINT n = CSoundFile::m_nProLogicDepth; + UINT n = CSoundFile::m_DSP.m_Settings.m_nProLogicDepth; if (n < 1) n = 1; if (n > 16) n = 16; m_SbSurroundDepth.SetRange(1, 16); m_SbSurroundDepth.SetPos(n); m_SbSurroundDelay.SetRange(0, 8); - m_SbSurroundDelay.SetPos((CSoundFile::m_nProLogicDelay-5)/5); + m_SbSurroundDelay.SetPos((CSoundFile::m_DSP.m_Settings.m_nProLogicDelay-5)/5); } //rewbs.resamplerConf OnResamplerChanged(); @@ -670,8 +670,8 @@ UINT nXBassRange = (4-m_SbXBassRange.GetPos()) * 5 + 1; if (nXBassRange < 5) nXBassRange = 5; if (nXBassRange > 21) nXBassRange = 21; - CSoundFile::m_nXBassDepth = nXBassDepth; - CSoundFile::m_nXBassRange = nXBassRange; + CSoundFile::m_DSP.m_Settings.m_nXBassDepth = nXBassDepth; + CSoundFile::m_DSP.m_Settings.m_nXBassRange = nXBassRange; } // Reverb { @@ -683,8 +683,8 @@ { UINT nProLogicDepth = m_SbSurroundDepth.GetPos(); UINT nProLogicDelay = 5 + (m_SbSurroundDelay.GetPos() * 5); - CSoundFile::m_nProLogicDepth = nProLogicDepth; - CSoundFile::m_nProLogicDelay = nProLogicDelay; + CSoundFile::m_DSP.m_Settings.m_nProLogicDepth = nProLogicDepth; + CSoundFile::m_DSP.m_Settings.m_nProLogicDelay = nProLogicDelay; } // Notify CMainFrame CMainFrame *pParent = CMainFrame::GetMainFrame(); Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-03-25 16:48:14 UTC (rev 1672) @@ -416,12 +416,12 @@ // Effects Settings - CSoundFile::m_nXBassDepth = CMainFrame::GetPrivateProfileLong("Effects", "XBassDepth", CSoundFile::m_nXBassDepth, iniFile); - CSoundFile::m_nXBassRange = CMainFrame::GetPrivateProfileLong("Effects", "XBassRange", CSoundFile::m_nXBassRange, iniFile); + CSoundFile::m_DSP.m_Settings.m_nXBassDepth = CMainFrame::GetPrivateProfileLong("Effects", "XBassDepth", CSoundFile::m_DSP.m_Settings.m_nXBassDepth, iniFile); + CSoundFile::m_DSP.m_Settings.m_nXBassRange = CMainFrame::GetPrivateProfileLong("Effects", "XBassRange", CSoundFile::m_DSP.m_Settings.m_nXBassRange, iniFile); CSoundFile::m_nReverbDepth = CMainFrame::GetPrivateProfileLong("Effects", "ReverbDepth", CSoundFile::m_nReverbDepth, iniFile); CSoundFile::gnReverbType = CMainFrame::GetPrivateProfileLong("Effects", "ReverbType", CSoundFile::gnReverbType, iniFile); - CSoundFile::m_nProLogicDepth = CMainFrame::GetPrivateProfileLong("Effects", "ProLogicDepth", CSoundFile::m_nProLogicDepth, iniFile); - CSoundFile::m_nProLogicDelay = CMainFrame::GetPrivateProfileLong("Effects", "ProLogicDelay", CSoundFile::m_nProLogicDelay, iniFile); + CSoundFile::m_DSP.m_Settings.m_nProLogicDepth = CMainFrame::GetPrivateProfileLong("Effects", "ProLogicDepth", CSoundFile::m_DSP.m_Settings.m_nProLogicDepth, iniFile); + CSoundFile::m_DSP.m_Settings.m_nProLogicDelay = CMainFrame::GetPrivateProfileLong("Effects", "ProLogicDelay", CSoundFile::m_DSP.m_Settings.m_nProLogicDelay, iniFile); // EQ Settings @@ -561,12 +561,12 @@ dwSZSIZE = sizeof(m_szKbdFile); RegQueryValueEx(key, "Key_Config_File", NULL, &dwREG_SZ, (LPBYTE)m_szKbdFile, &dwSZSIZE); - RegQueryValueEx(key, "XBassDepth", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nXBassDepth, &dwDWORDSize); - RegQueryValueEx(key, "XBassRange", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nXBassRange, &dwDWORDSize); + RegQueryValueEx(key, "XBassDepth", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_DSP.m_Settings.m_nXBassDepth, &dwDWORDSize); + RegQueryValueEx(key, "XBassRange", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_DSP.m_Settings.m_nXBassRange, &dwDWORDSize); RegQueryValueEx(key, "ReverbDepth", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nReverbDepth, &dwDWORDSize); RegQueryValueEx(key, "ReverbType", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::gnReverbType, &dwDWORDSize); - RegQueryValueEx(key, "ProLogicDepth", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nProLogicDepth, &dwDWORDSize); - RegQueryValueEx(key, "ProLogicDelay", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nProLogicDelay, &dwDWORDSize); + RegQueryValueEx(key, "ProLogicDepth", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_DSP.m_Settings.m_nProLogicDepth, &dwDWORDSize); + RegQueryValueEx(key, "ProLogicDelay", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_DSP.m_Settings.m_nProLogicDelay, &dwDWORDSize); RegQueryValueEx(key, "StereoSeparation", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nStereoSeparation, &dwDWORDSize); RegQueryValueEx(key, "MixChannels", NULL, &dwREG_DWORD, (LPBYTE)&CSoundFile::m_nMaxMixChannels, &dwDWORDSize); RegQueryValueEx(key, "WaveDevice", NULL, &dwREG_DWORD, (LPBYTE)&m_nWaveDevice, &dwDWORDSize); @@ -778,12 +778,12 @@ // Older versions of OpenMPT 1.18+ will look for this file if this entry is missing, so removing this entry after having read it is kind of backwards compatible. WritePrivateProfileString("Paths", "Key_Config_File", nullptr, iniFile); - CMainFrame::WritePrivateProfileLong("Effects", "XBassDepth", CSoundFile::m_nXBassDepth, iniFile); - CMainFrame::WritePrivateProfileLong("Effects", "XBassRange", CSoundFile::m_nXBassRange, iniFile); + CMainFrame::WritePrivateProfileLong("Effects", "XBassDepth", CSoundFile::m_DSP.m_Settings.m_nXBassDepth, iniFile); + CMainFrame::WritePrivateProfileLong("Effects", "XBassRange", CSoundFile::m_DSP.m_Settings.m_nXBassRange, iniFile); CMainFrame::WritePrivateProfileLong("Effects", "ReverbDepth", CSoundFile::m_nReverbDepth, iniFile); CMainFrame::WritePrivateProfileLong("Effects", "ReverbType", CSoundFile::gnReverbType, iniFile); - CMainFrame::WritePrivateProfileLong("Effects", "ProLogicDepth", CSoundFile::m_nProLogicDepth, iniFile); - CMainFrame::WritePrivateProfileLong("Effects", "ProLogicDelay", CSoundFile::m_nProLogicDelay, iniFile); + CMainFrame::WritePrivateProfileLong("Effects", "ProLogicDepth", CSoundFile::m_DSP.m_Settings.m_nProLogicDepth, iniFile); + CMainFrame::WritePrivateProfileLong("Effects", "ProLogicDelay", CSoundFile::m_DSP.m_Settings.m_nProLogicDelay, iniFile); WritePrivateProfileStruct("Effects", "EQ_Settings", &m_EqSettings, sizeof(EQPreset), iniFile); WritePrivateProfileStruct("Effects", "EQ_User1", &CEQSetupDlg::gUserPresets[0], sizeof(EQPreset), iniFile); Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-03-25 16:48:14 UTC (rev 1672) @@ -1055,6 +1055,10 @@ > </File> <File + RelativePath="..\sounddsp\DSP.h" + > + </File> + <File RelativePath="..\soundlib\SoundFilePlayConfig.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-03-25 16:48:14 UTC (rev 1672) @@ -404,6 +404,7 @@ <ClInclude Include="..\common\Reporting.h" /> <ClInclude Include="..\common\StringFixer.h" /> <ClInclude Include="..\common\typedefs.h" /> + <ClInclude Include="..\sounddsp\DSP.h" /> <ClInclude Include="..\soundlib\ChunkReader.h" /> <ClInclude Include="..\soundlib\FileReader.h" /> <ClInclude Include="..\soundlib\ITCompression.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-03-25 16:48:14 UTC (rev 1672) @@ -765,6 +765,9 @@ <ClInclude Include="..\common\mptString.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\sounddsp\DSP.h"> + <Filter>Header Files\sounddsp</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/sounddsp/DSP.cpp =================================================================== --- trunk/OpenMPT/sounddsp/DSP.cpp 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/sounddsp/DSP.cpp 2013-03-25 16:48:14 UTC (rev 1672) @@ -18,65 +18,18 @@ #define DEFAULT_XBASS_RANGE 14 // (x+2)*20 Hz (320Hz) #define DEFAULT_XBASS_DEPTH 6 // 1+(3>>(x-4)) (+6dB) -// Buffer Sizes -#define XBASSBUFFERSIZE 64 // 2 ms at 50KHz -#define SURROUNDBUFFERSIZE 2048 // 50ms @ 48kHz -// DSP Effects: PUBLIC members -UINT CSoundFile::m_nXBassDepth = DEFAULT_XBASS_DEPTH; -UINT CSoundFile::m_nXBassRange = DEFAULT_XBASS_RANGE; -UINT CSoundFile::m_nProLogicDepth = 12; -UINT CSoundFile::m_nProLogicDelay = 20; - //////////////////////////////////////////////////////////////////// // DSP Effects internal state -// Noise Reduction: simple low-pass filter -static LONG nLeftNR = 0; -static LONG nRightNR = 0; -// Surround Encoding: 1 delay line + low-pass filter + high-pass filter -static LONG nSurroundSize = 0; -static LONG nSurroundPos = 0; -static LONG nDolbyDepth = 0; -// Surround Biquads -static LONG nDolbyHP_Y1 = 0; -static LONG nDolbyHP_X1 = 0; -static LONG nDolbyLP_Y1 = 0; -static LONG nDolbyHP_B0 = 0; -static LONG nDolbyHP_B1 = 0; -static LONG nDolbyHP_A1 = 0; -static LONG nDolbyLP_B0 = 0; -static LONG nDolbyLP_B1 = 0; -static LONG nDolbyLP_A1 = 0; -// Bass Expansion: low-pass filter -static LONG nXBassFlt_Y1 = 0; -static LONG nXBassFlt_X1 = 0; -static LONG nXBassFlt_B0 = 0; -static LONG nXBassFlt_B1 = 0; -static LONG nXBassFlt_A1 = 0; +extern VOID MPPASMCALL X86_InitMixBuffer(int *pBuffer, UINT nSamples); -// DC Removal Biquad -static LONG nDCRFlt_Y1l = 0; -static LONG nDCRFlt_X1l = 0; -static LONG nDCRFlt_Y1r = 0; -static LONG nDCRFlt_X1r = 0; +static VOID MPPASMCALL X86_StereoDCRemoval(int *, UINT count, LONG *nDCRFlt_Y1l, LONG *nDCRFlt_X1l, LONG *nDCRFlt_Y1r, LONG *nDCRFlt_X1r); +static VOID MPPASMCALL X86_MonoDCRemoval(int *, UINT count, LONG *nDCRFlt_Y1l, LONG *nDCRFlt_X1l); - -static LONG SurroundBuffer[SURROUNDBUFFERSIZE]; - - -// Access the main temporary mix buffer directly: avoids an extra pointer -extern int MixSoundBuffer[MIXBUFFERSIZE * 4]; -extern int MixRearBuffer[MIXBUFFERSIZE * 2]; - -extern VOID MPPASMCALL X86_InitMixBuffer(int *pBuffer, UINT nSamples); -extern VOID MPPASMCALL X86_StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs); -extern VOID MPPASMCALL X86_StereoDCRemoval(int *, UINT count); -extern VOID MPPASMCALL X86_MonoDCRemoval(int *, UINT count); - /////////////////////////////////////////////////////////////////////////////////// // // Biquad setup @@ -84,8 +37,8 @@ #define PI 3.14159265358979323f -inline FLOAT Sgn(FLOAT x) { return (x >= 0) ? 1.0f : -1.0f; } -VOID ShelfEQ(LONG scale, +static inline FLOAT Sgn(FLOAT x) { return (x >= 0) ? 1.0f : -1.0f; } +static VOID ShelfEQ(LONG scale, LONG *outA1, LONG *outB0, LONG *outB1, LONG F_c, LONG F_s, FLOAT gainDC, FLOAT gainFT, FLOAT gainPI) { @@ -153,10 +106,56 @@ } -void CSoundFile::InitializeDSP(BOOL bReset) -//----------------------------------------- +CDSPSettings::CDSPSettings() : m_nXBassDepth(DEFAULT_XBASS_DEPTH), m_nXBassRange(DEFAULT_XBASS_RANGE), m_nProLogicDepth(12), m_nProLogicDelay(20) +//----------------------------------------------------------------------------------------------------------------------------------------------- { - if (!m_nProLogicDelay) m_nProLogicDelay = 20; + +} + + +CDSP::CDSP() +{ + // Noise Reduction: simple low-pass filter + nLeftNR = 0; + nRightNR = 0; + + // Surround Encoding: 1 delay line + low-pass filter + high-pass filter + nSurroundSize = 0; + nSurroundPos = 0; + nDolbyDepth = 0; + + // Surround Biquads + nDolbyHP_Y1 = 0; + nDolbyHP_X1 = 0; + nDolbyLP_Y1 = 0; + nDolbyHP_B0 = 0; + nDolbyHP_B1 = 0; + nDolbyHP_A1 = 0; + nDolbyLP_B0 = 0; + nDolbyLP_B1 = 0; + nDolbyLP_A1 = 0; + + // Bass Expansion: low-pass filter + nXBassFlt_Y1 = 0; + nXBassFlt_X1 = 0; + nXBassFlt_B0 = 0; + nXBassFlt_B1 = 0; + nXBassFlt_A1 = 0; + + // DC Removal Biquad + nDCRFlt_Y1l = 0; + nDCRFlt_X1l = 0; + nDCRFlt_Y1r = 0; + nDCRFlt_X1r = 0; + + MemsetZero(SurroundBuffer); + +} + +void CDSP::Initialize(BOOL bReset, DWORD MixingFreq, DWORD SoundSetupFlags) +//------------------------------------------------------------------------- +{ + if (!m_Settings.m_nProLogicDelay) m_Settings.m_nProLogicDelay = 20; if (bReset) { // Noise Reduction @@ -164,17 +163,17 @@ } // Pro-Logic Surround nSurroundPos = nSurroundSize = 0; - if (gdwSoundSetup & SNDMIX_SURROUND) + if (SoundSetupFlags & SNDMIX_SURROUND) { memset(SurroundBuffer, 0, sizeof(SurroundBuffer)); - nSurroundSize = (gdwMixingFreq * m_nProLogicDelay) / 1000; + nSurroundSize = (MixingFreq * m_Settings.m_nProLogicDelay) / 1000; if (nSurroundSize > SURROUNDBUFFERSIZE) nSurroundSize = SURROUNDBUFFERSIZE; - nDolbyDepth = m_nProLogicDepth; + nDolbyDepth = m_Settings.m_nProLogicDepth; if (nDolbyDepth < 1) nDolbyDepth = 1; if (nDolbyDepth > 16) nDolbyDepth = 16; // Setup biquad filters - ShelfEQ(1024, &nDolbyHP_A1, &nDolbyHP_B0, &nDolbyHP_B1, 200, gdwMixingFreq, 0, 0.5f, 1); - ShelfEQ(1024, &nDolbyLP_A1, &nDolbyLP_B0, &nDolbyLP_B1, 7000, gdwMixingFreq, 1, 0.75f, 0); + ShelfEQ(1024, &nDolbyHP_A1, &nDolbyHP_B0, &nDolbyHP_B1, 200, MixingFreq, 0, 0.5f, 1); + ShelfEQ(1024, &nDolbyLP_A1, &nDolbyLP_B0, &nDolbyLP_B1, 7000, MixingFreq, 1, 0.75f, 0); nDolbyHP_X1 = nDolbyHP_Y1 = 0; nDolbyLP_Y1 = 0; // Surround Level @@ -185,14 +184,14 @@ nDolbyLP_B1 *= 2; } // Bass Expansion Reset - if (gdwSoundSetup & SNDMIX_MEGABASS) + if (SoundSetupFlags & SNDMIX_MEGABASS) { LONG a1 = 0, b0 = 1024, b1 = 0; - int nXBassCutOff = 50 + (m_nXBassRange+2) * 20; - int nXBassGain = m_nXBassDepth; + int nXBassCutOff = 50 + (m_Settings.m_nXBassRange+2) * 20; + int nXBassGain = m_Settings.m_nXBassDepth; Limit(nXBassGain, 2, 8); Limit(nXBassCutOff, 60, 600); - ShelfEQ(1024, &a1, &b0, &b1, nXBassCutOff, gdwMixingFreq, + ShelfEQ(1024, &a1, &b0, &b1, nXBassCutOff, MixingFreq, 1.0f + (1.0f/16.0f) * (0x300 >> nXBassGain), 1.0f, 0.0000001f); @@ -219,8 +218,8 @@ // 2-channel surround -static void ProcessStereoSurround(int count) -//------------------------------------------ +void CDSP::ProcessStereoSurround(int * MixSoundBuffer, int count) +//--------------------------------------------------------------- { int *pr = MixSoundBuffer, hy1 = nDolbyHP_Y1; for (int r=count; r; r--) @@ -246,8 +245,8 @@ // 4-channels surround -static void ProcessQuadSurround(int count) -//---------------------------------------- +void CDSP::ProcessQuadSurround(int * MixSoundBuffer, int * MixRearBuffer, int count) +//---------------------------------------------------------------------------------- { int *pr = MixSoundBuffer, hy1 = nDolbyHP_Y1; for (int r=count; r; r--) @@ -276,22 +275,28 @@ } -void CSoundFile::ProcessStereoDSP(int count) -//------------------------------------------ +void CDSP::Process(int * MixSoundBuffer, int * MixRearBuffer, int count, DWORD SoundSetupFlags, UINT nChannels) +//------------------------------------------------------------------------------------------------------------- { + + + if(nChannels >= 2) + { + + // Dolby Pro-Logic Surround - if (gdwSoundSetup & SNDMIX_SURROUND) + if (SoundSetupFlags & SNDMIX_SURROUND) { - if (gnChannels > 2) ProcessQuadSurround(count); else - ProcessStereoSurround(count); + if (nChannels > 2) ProcessQuadSurround(MixSoundBuffer, MixRearBuffer, count); else + ProcessStereoSurround(MixSoundBuffer, count); } // DC Removal - if (gdwSoundSetup & SNDMIX_MEGABASS) + if (SoundSetupFlags & SNDMIX_MEGABASS) { - X86_StereoDCRemoval(MixSoundBuffer, count); + X86_StereoDCRemoval(MixSoundBuffer, count, &nDCRFlt_Y1l, &nDCRFlt_X1l, &nDCRFlt_Y1r, &nDCRFlt_X1r); } // Bass Expansion - if (gdwSoundSetup & SNDMIX_MEGABASS) + if (SoundSetupFlags & SNDMIX_MEGABASS) { int *px = MixSoundBuffer; int x1 = nXBassFlt_X1; @@ -311,7 +316,7 @@ nXBassFlt_Y1 = y1; } // Noise Reduction - if (gdwSoundSetup & SNDMIX_NOISEREDUCTION) + if (SoundSetupFlags & SNDMIX_NOISEREDUCTION) { int n1 = nLeftNR, n2 = nRightNR; int *pnr = MixSoundBuffer; @@ -328,19 +333,19 @@ nLeftNR = n1; nRightNR = n2; } -} + + } else + { -void CSoundFile::ProcessMonoDSP(int count) -//---------------------------------------- -{ + // DC Removal - if (gdwSoundSetup & SNDMIX_MEGABASS) + if (SoundSetupFlags & SNDMIX_MEGABASS) { - X86_MonoDCRemoval(MixSoundBuffer, count); + X86_MonoDCRemoval(MixSoundBuffer, count, &nDCRFlt_Y1l, &nDCRFlt_X1l); } // Bass Expansion - if (gdwSoundSetup & SNDMIX_MEGABASS) + if (SoundSetupFlags & SNDMIX_MEGABASS) { int *px = MixSoundBuffer; int x1 = nXBassFlt_X1; @@ -359,7 +364,7 @@ nXBassFlt_Y1 = y1; } // Noise Reduction - if (gdwSoundSetup & SNDMIX_NOISEREDUCTION) + if (SoundSetupFlags & SNDMIX_NOISEREDUCTION) { int n = nLeftNR; int *pnr = MixSoundBuffer; @@ -371,6 +376,11 @@ } nLeftNR = n; } + + + } + + } @@ -382,10 +392,10 @@ #define DCR_AMOUNT 9 -VOID MPPASMCALL X86_StereoDCRemoval(int *pBuffer, UINT nSamples) +static VOID MPPASMCALL X86_StereoDCRemoval(int *pBuffer, UINT nSamples, LONG *nDCRFlt_Y1l, LONG *nDCRFlt_X1l, LONG *nDCRFlt_Y1r, LONG *nDCRFlt_X1r) { - int y1l=nDCRFlt_Y1l, x1l=nDCRFlt_X1l; - int y1r=nDCRFlt_Y1r, x1r=nDCRFlt_X1r; + int y1l=*nDCRFlt_Y1l, x1l=*nDCRFlt_X1l; + int y1r=*nDCRFlt_Y1r, x1r=*nDCRFlt_X1r; _asm { mov esi, pBuffer @@ -421,20 +431,21 @@ mov y1r, edx jnz stereodcr } - nDCRFlt_Y1l = y1l; - nDCRFlt_X1l = x1l; - nDCRFlt_Y1r = y1r; - nDCRFlt_X1r = x1r; + *nDCRFlt_Y1l = y1l; + *nDCRFlt_X1l = x1l; + *nDCRFlt_Y1r = y1r; + *nDCRFlt_X1r = x1r; } -VOID MPPASMCALL X86_MonoDCRemoval(int *pBuffer, UINT nSamples) +static VOID MPPASMCALL X86_MonoDCRemoval(int *pBuffer, UINT nSamples, LONG *nDCRFlt_Y1l, LONG *nDCRFlt_X1l) { + int y1l=*nDCRFlt_Y1l, x1l=*nDCRFlt_X1l; _asm { mov esi, pBuffer mov ecx, nSamples - mov edx, nDCRFlt_X1l - mov edi, nDCRFlt_Y1l + mov edx, x1l + mov edi, y1l stereodcr: mov eax, [esi] mov ebx, edx @@ -452,9 +463,11 @@ dec ecx mov edi, eax jnz stereodcr - mov nDCRFlt_X1l, edx - mov nDCRFlt_Y1l, edi + mov x1l, edx + mov y1l, edi } + *nDCRFlt_Y1l = y1l; + *nDCRFlt_X1l = x1l; } @@ -465,34 +478,33 @@ // Clean DSP Effects interface // [XBass level 0(quiet)-100(loud)], [cutoff in Hz 20-100] -BOOL CSoundFile::SetXBassParameters(UINT nDepth, UINT nRange) -//----------------------------------------------------------- +BOOL CDSP::SetXBassParameters(UINT nDepth, UINT nRange) +//----------------------------------------------------- { if (nDepth > 100) nDepth = 100; UINT gain = nDepth / 20; if (gain > 4) gain = 4; - m_nXBassDepth = 8 - gain; // filter attenuation 1/256 .. 1/16 + m_Settings.m_nXBassDepth = 8 - gain; // filter attenuation 1/256 .. 1/16 UINT range = nRange / 5; if (range > 5) range -= 5; else range = 0; if (nRange > 16) nRange = 16; - m_nXBassRange = 21 - range; // filter average on 0.5-1.6ms + m_Settings.m_nXBassRange = 21 - range; // filter average on 0.5-1.6ms return TRUE; } // [Surround level 0(quiet)-100(heavy)] [delay in ms, usually 5-50ms] -BOOL CSoundFile::SetSurroundParameters(UINT nDepth, UINT nDelay) -//-------------------------------------------------------------- +BOOL CDSP::SetSurroundParameters(UINT nDepth, UINT nDelay) +//-------------------------------------------------------- { UINT gain = (nDepth * 16) / 100; if (gain > 16) gain = 16; if (gain < 1) gain = 1; - m_nProLogicDepth = gain; + m_Settings.m_nProLogicDepth = gain; if (nDelay < 4) nDelay = 4; if (nDelay > 50) nDelay = 50; - m_nProLogicDelay = nDelay; + m_Settings.m_nProLogicDelay = nDelay; return TRUE; } - Added: trunk/OpenMPT/sounddsp/DSP.h =================================================================== --- trunk/OpenMPT/sounddsp/DSP.h (rev 0) +++ trunk/OpenMPT/sounddsp/DSP.h 2013-03-25 16:48:14 UTC (rev 1672) @@ -0,0 +1,91 @@ +/* + * DSP.h + * ----- + * Purpose: Mixing code for various DSPs (EQ, Mega-Bass, ...) + * Notes : Ugh... This should really be removed at some point. + * Authors: Olivier Lapicque + * OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + + +// Buffer Sizes +#define SURROUNDBUFFERSIZE 2048 // 50ms @ 48kHz + + +//================ +class CDSPSettings +//================ +{ +public: + UINT m_nXBassDepth; + UINT m_nXBassRange; + UINT m_nProLogicDepth; + UINT m_nProLogicDelay; +public: + CDSPSettings(); +}; + + +//======== +class CDSP +//======== +{ +public: + CDSPSettings m_Settings; +private: + + // Noise Reduction: simple low-pass filter + LONG nLeftNR; + LONG nRightNR; + + // Surround Encoding: 1 delay line + low-pass filter + high-pass filter + LONG nSurroundSize; + LONG nSurroundPos; + LONG nDolbyDepth; + + // Surround Biquads + LONG nDolbyHP_Y1; + LONG nDolbyHP_X1; + LONG nDolbyLP_Y1; + LONG nDolbyHP_B0; + LONG nDolbyHP_B1; + LONG nDolbyHP_A1; + LONG nDolbyLP_B0; + LONG nDolbyLP_B1; + LONG nDolbyLP_A1; + + // Bass Expansion: low-pass filter + LONG nXBassFlt_Y1; + LONG nXBassFlt_X1; + LONG nXBassFlt_B0; + LONG nXBassFlt_B1; + LONG nXBassFlt_A1; + + // DC Removal Biquad + LONG nDCRFlt_Y1l; + LONG nDCRFlt_X1l; + LONG nDCRFlt_Y1r; + LONG nDCRFlt_X1r; + + LONG SurroundBuffer[SURROUNDBUFFERSIZE]; + +public: + CDSP(); + ~CDSP() {} +public: + void SetSettings(const CDSPSettings &settings) { m_Settings = settings; } + // [XBass level 0(quiet)-100(loud)], [cutoff in Hz 10-100] + BOOL SetXBassParameters(UINT nDepth, UINT nRange); + // [Surround level 0(quiet)-100(heavy)] [delay in ms, usually 5-40ms] + BOOL SetSurroundParameters(UINT nDepth, UINT nDelay); + void Initialize(BOOL bReset, DWORD MixingFreq, DWORD SoundSetupFlags); + void Process(int * MixSoundBuffer, int * MixRearBuffer, int count, DWORD SoundSetupFlags, UINT nChannels); +private: + void ProcessStereoSurround(int * MixSoundBuffer, int count); + void ProcessQuadSurround(int * MixSoundBuffer, int * MixRearBuffer, int count); +}; + Property changes on: trunk/OpenMPT/sounddsp/DSP.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-03-25 16:48:14 UTC (rev 1672) @@ -32,6 +32,8 @@ #include "plugins/PlugInterface.h" #include "RowVisitor.h" +#include "../sounddsp/DSP.h" + // ----------------------------------------------------------------------------------------- // MODULAR ModInstrument FIELD ACCESS : body content at the (near) top of Sndfile.cpp !!! // ----------------------------------------------------------------------------------------- @@ -227,9 +229,8 @@ bool m_bITBidiMode; // Process bidi loops like Impulse Tracker (see Fastmix.cpp for an explanation) public: // Static Members - static UINT m_nXBassDepth, m_nXBassRange; + static CDSP m_DSP; static UINT m_nReverbDepth, gnReverbType; - static UINT m_nProLogicDepth, m_nProLogicDelay; static UINT m_nStereoSeparation; static UINT m_nMaxMixChannels; static DWORD gdwSysInfo, gdwSoundSetup, gdwMixingFreq, gnBitsPerSample, gnChannels; @@ -486,16 +487,8 @@ static void SetAGC(BOOL b); static void ResetAGC(); static void ProcessAGC(int count); - // DSP Effects - static void InitializeDSP(BOOL bReset); - static void ProcessStereoDSP(int count); - static void ProcessMonoDSP(int count); // [Reverb level 0(quiet)-100(loud)], [REVERBTYPE_XXXX] static BOOL SetReverbParameters(UINT nDepth, UINT nType); - // [XBass level 0(quiet)-100(loud)], [cutoff in Hz 10-100] - static BOOL SetXBassParameters(UINT nDepth, UINT nRange); - // [Surround level 0(quiet)-100(heavy)] [delay in ms, usually 5-40ms] - static BOOL SetSurroundParameters(UINT nDepth, UINT nDelay); #ifdef ENABLE_EQ // EQ static void InitializeEQ(BOOL bReset=TRUE); Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-03-25 16:43:54 UTC (rev 1671) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-03-25 16:48:14 UTC (rev 1672) @@ -35,6 +35,7 @@ DWORD CSoundFile::gdwMixingFreq = 44100; DWORD CSoundFile::gnBitsPerSample = 16; // Mixing data initialized in +CDSP CSoundFile::m_DSP; UINT CSoundFile::gnAGC = AGC_UNITY; double CSoundFile::gdWFIRCutoff = 0.97; //default value BYTE CSoundFile::gbWFIRType = 7; //WFIR_KAISER4T; //default value @@ -168,7 +169,7 @@ #ifndef NO_REVERB InitializeReverb(bReset); #endif - InitializeDSP(bReset); + m_DSP.Initialize(bReset, gdwMixingFreq, gdwSoundSetup); #ifdef ENABLE_EQ InitializeEQ(bReset); #endif @@ -313,8 +314,6 @@ { ApplyGlobalVolume(MixSoundBuffer, MixRearBuffer, lSampleCount); } - - ProcessStereoDSP(lCount); } else { m_nMixStat += CreateStereoMix(lCount); @@ -331,10 +330,10 @@ { ApplyGlobalVolume(MixSoundBuffer, nullptr, lSampleCount); } - - ProcessMonoDSP(lCount); } + m_DSP.Process(MixSoundBuffer, MixRearBuffer, lCount, gdwSoundSetup, gnChannels); + #ifdef ENABLE_EQ // Graphic Equalizer if (gdwSoundSetup & SNDMIX_EQ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |