diff options
author | Eric Laurent <elaurent@google.com> | 2010-09-21 16:53:20 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-21 16:53:20 -0700 |
commit | dab59d1534e50f3c818c96f34f29389f818f077b (patch) | |
tree | ff1b6b58a770fcd89b6ad5394dbc403a82a833aa /media/libeffects | |
parent | 76f609118574a76b10cb90bcf061b15546bc38ee (diff) | |
parent | 6943b94b8f267c83060946bae0961efc30444dee (diff) | |
download | frameworks_base-dab59d1534e50f3c818c96f34f29389f818f077b.zip frameworks_base-dab59d1534e50f3c818c96f34f29389f818f077b.tar.gz frameworks_base-dab59d1534e50f3c818c96f34f29389f818f077b.tar.bz2 |
am 6943b94b: am a6dc4699: Merge "Fix issue 2913071." into gingerbread
Merge commit '6943b94b8f267c83060946bae0961efc30444dee'
* commit '6943b94b8f267c83060946bae0961efc30444dee':
Fix issue 2913071.
Diffstat (limited to 'media/libeffects')
-rw-r--r-- | media/libeffects/visualizer/EffectVisualizer.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp index 8ab57c93..03a6bbb 100644 --- a/media/libeffects/visualizer/EffectVisualizer.cpp +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -239,6 +239,24 @@ extern "C" int Visualizer_process( } // all code below assumes stereo 16 bit PCM output and input + + // derive capture scaling factor from peak value in current buffer + // this gives more interesting captures for display. + int32_t shift = 32; + for (size_t i = 0; i < inBuffer->frameCount; i++) { + int32_t smp = inBuffer->s16[i]; + if (smp < 0) smp = -smp; + int32_t clz = __builtin_clz(smp); + if (shift > clz) shift = clz; + } + // never scale by less than 8 to avoid returning unaltered PCM signal. + // add one to combine the division by 2 needed after summing left and right channels below + if (20 > shift) { + shift = (31 - 8 + 1) - shift; + } else { + shift = (3 + 1); + } + uint32_t captIdx; uint32_t inIdx; uint8_t *buf = pContext->mCaptureBuf[pContext->mCurrentBuf]; @@ -246,7 +264,7 @@ extern "C" int Visualizer_process( inIdx < inBuffer->frameCount && captIdx < pContext->mCaptureSize; inIdx++, captIdx++) { int32_t smp = inBuffer->s16[2 * inIdx] + inBuffer->s16[2 * inIdx + 1]; - smp = (smp + (1 << 8)) >> 9; + smp = (smp + (1 << (shift - 1))) >> shift; buf[captIdx] = ((uint8_t)smp)^0x80; } pContext->mCaptureIdx = captIdx; @@ -369,7 +387,7 @@ extern "C" int Visualizer_command(effect_interface_t self, uint32_t cmdCode, uin case VISU_CMD_CAPTURE: - if (pReplyData == NULL || *replySize != (int)pContext->mCaptureSize) { + if (pReplyData == NULL || *replySize != pContext->mCaptureSize) { LOGV("VISU_CMD_CAPTURE() error *replySize %d pContext->mCaptureSize %d", *replySize, pContext->mCaptureSize); return -EINVAL; |