diff options
author | v0lt <v0lt@users.sourceforge.net> | 2012-05-22 00:53:19 +0400 |
---|---|---|
committer | v0lt <v0lt@users.sourceforge.net> | 2012-05-22 00:53:19 +0400 |
commit | 1c2e0961acb02352ea6f504fd67dfcecec5ac94a (patch) | |
tree | d24c2983d1d3e87754dcfcfb5dec03722aa23b82 /src/filters/transform | |
parent | 44f1038f364d4c5bf0c05080832a268cf07f9fea (diff) |
MpaDecFilter: fixed cracking sound for PCM 32-bit output (ticket #2304)
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@4831 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters/transform')
-rw-r--r-- | src/filters/transform/MpaDecFilter/MpaDecFilter.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp b/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp index ef9485e8b..8a554e816 100644 --- a/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp +++ b/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp @@ -1592,35 +1592,38 @@ HRESULT CMpaDecFilter::Deliver(CAtlArray<float>& pBuff, DWORD nSamplesPerSec, WO float* pDataIn = pBuff.GetData();
+#define f16max (float(INT16_MAX)/INT16_PEAK)
+#define f24max (float(INT24_MAX)/INT24_PEAK)
+#define d32max (double(INT32_MAX)/INT32_PEAK)
+#define round_f(x) ((x) > 0 ? (x) + 0.5f : (x) - 0.5f)
+#define round_d(x) ((x) > 0 ? (x) + 0.5 : (x) - 0.5)
+
for (unsigned int i = 0, len = pBuff.GetCount(); i < len; i++) {
float f = *pDataIn++;
-
-#define f16max (float(INT16_MAX)/float(INT16_PEAK))
-#define f24max (float(INT24_MAX)/float(INT24_PEAK))
-#define f32max (float(INT32_MAX)/float(INT32_PEAK))
-#define round(x) ((x) > 0 ? (x) + 0.5 : (x) - 0.5)
-
+
if (f < -1) f = -1;
switch (sf) {
default:
case SF_PCM16:
if (f > f16max) f = f16max;
- *(int16_t*)pDataOut = (int16_t)round(f * INT16_PEAK);
+ *(int16_t*)pDataOut = (int16_t)round_f(f * INT16_PEAK);
pDataOut += sizeof(int16_t);
break;
case SF_PCM24: {
if (f > f24max) f = f24max;
- DWORD i24 = (DWORD)(int32_t)round((double)f * INT24_PEAK);
+ DWORD i24 = (DWORD)(int32_t)round_f(f * INT24_PEAK);
*pDataOut++ = (BYTE)(i24);
*pDataOut++ = (BYTE)(i24>>8);
*pDataOut++ = (BYTE)(i24>>16);
}
break;
- case SF_PCM32:
- if (f > f32max) f = f32max;
- *(int32_t*)pDataOut = (int32_t)round((double)f * INT32_PEAK);
+ case SF_PCM32: {
+ double d = (double)f;
+ if (d > d32max) d = d32max;
+ *(int32_t*)pDataOut = (int32_t)round_d(d * INT32_PEAK);
pDataOut += sizeof(int32_t);
- break;
+ }
+ break;
case SF_FLOAT32:
if (f > 1) f = 1;
*(float*)pDataOut = f;
|