|
From: <man...@us...> - 2013-04-27 22:28:33
|
Revision: 1986
http://sourceforge.net/p/modplug/code/1986
Author: manxorist
Date: 2013-04-27 22:28:24 +0000 (Sat, 27 Apr 2013)
Log Message:
-----------
[Ref] Apply final output gain for floating point output after the conversion to floating point to avoid underflow or clipping.
[Ref] Remove pModDoc parameter in CSoundFile::Create and remove CSoundFile::GetpModDoc() if !MODPLUG_TRACKER.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/Sndfile.cpp
trunk/OpenMPT/soundlib/Sndfile.h
trunk/OpenMPT/soundlib/Sndmix.cpp
Modified: trunk/OpenMPT/soundlib/Sndfile.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-27 18:59:25 UTC (rev 1985)
+++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-27 22:28:24 UTC (rev 1986)
@@ -514,8 +514,8 @@
{
m_pModDoc = pModDoc;
#else
-BOOL CSoundFile::Create(FileReader filereader, void*)
-//---------------------------------------------------
+BOOL CSoundFile::Create(FileReader filereader)
+//--------------------------------------------
{
#endif // MODPLUG_TRACKER
Modified: trunk/OpenMPT/soundlib/Sndfile.h
===================================================================
--- trunk/OpenMPT/soundlib/Sndfile.h 2013-04-27 18:59:25 UTC (rev 1985)
+++ trunk/OpenMPT/soundlib/Sndfile.h 2013-04-27 22:28:24 UTC (rev 1986)
@@ -406,11 +406,13 @@
#ifdef MODPLUG_TRACKER
BOOL Create(FileReader filereader, CModDoc *pModDoc);
+#else
+ BOOL Create(FileReader filereader);
+#endif // MODPLUG_TRACKER
+
+#ifdef MODPLUG_TRACKER
// Get parent CModDoc. Can be nullptr if previewing from tree view, and is always nullptr if we're not actually compiling OpenMPT.
CModDoc *GetpModDoc() const { return m_pModDoc; }
-#else
- BOOL Create(FileReader filereader, void *pModDoc=nullptr);
- void *GetpModDoc() const { return nullptr; }
#endif // MODPLUG_TRACKER
BOOL Destroy();
@@ -747,6 +749,7 @@
#ifndef MODPLUG_TRACKER
void ApplyFinalOutputGain(int SoundBuffer[], int RearBuffer[], long lCount); // lCount meaning the number of frames, totally independet from the numer of channels
+ void ApplyFinalOutputGainFloat(float *beg, float *end);
#endif
// System-Dependant functions
Modified: trunk/OpenMPT/soundlib/Sndmix.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-04-27 18:59:25 UTC (rev 1985)
+++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-04-27 22:28:24 UTC (rev 1986)
@@ -320,7 +320,11 @@
nStat++;
#ifndef MODPLUG_TRACKER
- ApplyFinalOutputGain(MixSoundBuffer, MixRearBuffer, lCount);
+ if(!m_MixerSettings.IsFloatSampleFormat())
+ {
+ // Apply final output gain for non floating point output
+ ApplyFinalOutputGain(MixSoundBuffer, MixRearBuffer, lCount);
+ }
#endif
#ifndef NO_AGC
@@ -355,9 +359,22 @@
}
#endif
- // Perform clipping
+ #ifndef MODPLUG_TRACKER
+ LPBYTE buf_beg = lpBuffer;
+ #endif
+
+ // Convert to output sample format and optionally perform lipping if needed
lpBuffer += pCvt(lpBuffer, MixSoundBuffer, lTotalSampleCount);
+ #ifndef MODPLUG_TRACKER
+ LPBYTE buf_end = lpBuffer;
+ // Apply final output gain for floating point output after conversion so we do not suffer underflow or clipping
+ if(m_MixerSettings.IsFloatSampleFormat())
+ {
+ ApplyFinalOutputGainFloat(reinterpret_cast<float*>(buf_beg), reinterpret_cast<float*>(buf_end));
+ }
+ #endif
+
// Buffer ready
lRead -= lCount;
m_nBufferCount -= lCount;
@@ -2308,5 +2325,18 @@
}
}
}
+void CSoundFile::ApplyFinalOutputGainFloat(float *beg, float *end) {
+ if(m_MixerSettings.m_FinalOutputGain == (1<<16))
+ {
+ // nothing to do, gain == +/- 0dB
+ return;
+ }
+ // no clipping prevention is done here
+ float factor = static_cast<float>(m_MixerSettings.m_FinalOutputGain) * (1.0f / static_cast<float>(1<<16));
+ for(float *i = beg; i != end; ++i)
+ {
+ *i *= factor;
+ }
+}
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|