summaryrefslogtreecommitdiffstats
path: root/media/libeffects/downmix
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2012-05-24 10:11:07 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2012-05-24 12:12:43 -0700
commitaea2715e65994e665a3732551880419ba1cecc0d (patch)
tree062b9c82f8d9ce4303467e46981c40d3b1fc1d8e /media/libeffects/downmix
parente737cda649acbfa43fc1b74612a83f2fac9aa449 (diff)
downloadframeworks_av-aea2715e65994e665a3732551880419ba1cecc0d.zip
frameworks_av-aea2715e65994e665a3732551880419ba1cecc0d.tar.gz
frameworks_av-aea2715e65994e665a3732551880419ba1cecc0d.tar.bz2
Prevent occurences of clipping in loud downmixed scenes
The downmixer effect is a mixer, wich, like the platform mixer, hard-clips. To prevent clipping during loud scenes across multiple chanels, apply a fixed attenuation on the result of the downmix. Note that this attenuation is lower the theoretical required attenuation (except for quad and surround) but is adequate for most content. Bug 4280902 Change-Id: Iec520e9f1367284d6102633f532429361717692d
Diffstat (limited to 'media/libeffects/downmix')
-rw-r--r--media/libeffects/downmix/EffectDownmix.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/media/libeffects/downmix/EffectDownmix.c b/media/libeffects/downmix/EffectDownmix.c
index 8735503..5bf052a 100644
--- a/media/libeffects/downmix/EffectDownmix.c
+++ b/media/libeffects/downmix/EffectDownmix.c
@@ -822,9 +822,9 @@ void Downmix_foldFromQuad(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool ac
if (accumulate) {
while (numFrames) {
// FL + RL
- pDst[0] = clamp16(pDst[0] + pSrc[0] + pSrc[2]);
+ pDst[0] = clamp16(pDst[0] + ((pSrc[0] + pSrc[2]) >> 1));
// FR + RR
- pDst[1] = clamp16(pDst[1] + pSrc[1] + pSrc[3]);
+ pDst[1] = clamp16(pDst[1] + ((pSrc[1] + pSrc[3]) >> 1));
pSrc += 4;
pDst += 2;
numFrames--;
@@ -832,9 +832,9 @@ void Downmix_foldFromQuad(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool ac
} else { // same code as above but without adding and clamping pDst[i] to itself
while (numFrames) {
// FL + RL
- pDst[0] = clamp16(pSrc[0] + pSrc[2]);
+ pDst[0] = clamp16((pSrc[0] + pSrc[2]) >> 1);
// FR + RR
- pDst[1] = clamp16(pSrc[1] + pSrc[3]);
+ pDst[1] = clamp16((pSrc[1] + pSrc[3]) >> 1);
pSrc += 4;
pDst += 2;
numFrames--;
@@ -877,8 +877,8 @@ void Downmix_foldFromSurround(int16_t *pSrc, int16_t*pDst, size_t numFrames, boo
// FR + centerPlusRearContrib
rt = (pSrc[1] << 12) + centerPlusRearContrib;
// accumulate in destination
- pDst[0] = clamp16(pDst[0] + (lt >> 12));
- pDst[1] = clamp16(pDst[1] + (rt >> 12));
+ pDst[0] = clamp16(pDst[0] + (lt >> 13));
+ pDst[1] = clamp16(pDst[1] + (rt >> 13));
pSrc += 4;
pDst += 2;
numFrames--;
@@ -892,8 +892,8 @@ void Downmix_foldFromSurround(int16_t *pSrc, int16_t*pDst, size_t numFrames, boo
// FR + centerPlusRearContrib
rt = (pSrc[1] << 12) + centerPlusRearContrib;
// store in destination
- pDst[0] = clamp16(lt >> 12); // differs from when accumulate is true above
- pDst[1] = clamp16(rt >> 12); // differs from when accumulate is true above
+ pDst[0] = clamp16(lt >> 13); // differs from when accumulate is true above
+ pDst[1] = clamp16(rt >> 13); // differs from when accumulate is true above
pSrc += 4;
pDst += 2;
numFrames--;
@@ -939,8 +939,8 @@ void Downmix_foldFrom5Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool
// FR + centerPlusLfeContrib + RR
rt = (pSrc[1] << 12) + centerPlusLfeContrib + (pSrc[5] << 12);
// accumulate in destination
- pDst[0] = clamp16(pDst[0] + (lt >> 12));
- pDst[1] = clamp16(pDst[1] + (rt >> 12));
+ pDst[0] = clamp16(pDst[0] + (lt >> 13));
+ pDst[1] = clamp16(pDst[1] + (rt >> 13));
pSrc += 6;
pDst += 2;
numFrames--;
@@ -955,8 +955,8 @@ void Downmix_foldFrom5Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool
// FR + centerPlusLfeContrib + RR
rt = (pSrc[1] << 12) + centerPlusLfeContrib + (pSrc[5] << 12);
// store in destination
- pDst[0] = clamp16(lt >> 12); // differs from when accumulate is true above
- pDst[1] = clamp16(rt >> 12); // differs from when accumulate is true above
+ pDst[0] = clamp16(lt >> 13); // differs from when accumulate is true above
+ pDst[1] = clamp16(rt >> 13); // differs from when accumulate is true above
pSrc += 6;
pDst += 2;
numFrames--;
@@ -1004,8 +1004,8 @@ void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool
// FR + centerPlusLfeContrib + SR + RR
rt = (pSrc[1] << 12) + centerPlusLfeContrib + (pSrc[7] << 12) + (pSrc[5] << 12);
//accumulate in destination
- pDst[0] = clamp16(pDst[0] + (lt >> 12));
- pDst[1] = clamp16(pDst[1] + (rt >> 12));
+ pDst[0] = clamp16(pDst[0] + (lt >> 13));
+ pDst[1] = clamp16(pDst[1] + (rt >> 13));
pSrc += 8;
pDst += 2;
numFrames--;
@@ -1020,8 +1020,8 @@ void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool
// FR + centerPlusLfeContrib + SR + RR
rt = (pSrc[1] << 12) + centerPlusLfeContrib + (pSrc[7] << 12) + (pSrc[5] << 12);
// store in destination
- pDst[0] = clamp16(lt >> 12); // differs from when accumulate is true above
- pDst[1] = clamp16(rt >> 12); // differs from when accumulate is true above
+ pDst[0] = clamp16(lt >> 13); // differs from when accumulate is true above
+ pDst[1] = clamp16(rt >> 13); // differs from when accumulate is true above
pSrc += 8;
pDst += 2;
numFrames--;
@@ -1130,8 +1130,8 @@ bool Downmix_foldGeneric(
lt += centersLfeContrib;
rt += centersLfeContrib;
// accumulate in destination
- pDst[0] = clamp16(pDst[0] + (lt >> 12));
- pDst[1] = clamp16(pDst[1] + (rt >> 12));
+ pDst[0] = clamp16(pDst[0] + (lt >> 13));
+ pDst[1] = clamp16(pDst[1] + (rt >> 13));
pSrc += numChan;
pDst += 2;
numFrames--;
@@ -1159,8 +1159,8 @@ bool Downmix_foldGeneric(
lt += centersLfeContrib;
rt += centersLfeContrib;
// store in destination
- pDst[0] = clamp16(lt >> 12); // differs from when accumulate is true above
- pDst[1] = clamp16(rt >> 12); // differs from when accumulate is true above
+ pDst[0] = clamp16(lt >> 13); // differs from when accumulate is true above
+ pDst[1] = clamp16(rt >> 13); // differs from when accumulate is true above
pSrc += numChan;
pDst += 2;
numFrames--;