am a6dc4699: Merge "Fix issue 2913071." into gingerbread

Merge commit 'a6dc4699222a484222d1c54d5319f302a02e406b' into gingerbread-plus-aosp

* commit 'a6dc4699222a484222d1c54d5319f302a02e406b':
  Fix issue 2913071.
This commit is contained in:
Eric Laurent
2010-09-21 15:59:23 -07:00
committed by Android Git Automerger
2 changed files with 28 additions and 7 deletions

View File

@@ -218,13 +218,16 @@ public class Visualizer {
public int setEnabled(boolean enabled) public int setEnabled(boolean enabled)
throws IllegalStateException { throws IllegalStateException {
synchronized (mStateLock) { synchronized (mStateLock) {
if ((enabled && mState != STATE_INITIALIZED) || if (mState == STATE_UNINITIALIZED) {
(!enabled && mState != STATE_ENABLED)) {
throw(new IllegalStateException("setEnabled() called in wrong state: "+mState)); throw(new IllegalStateException("setEnabled() called in wrong state: "+mState));
} }
int status = native_setEnabled(enabled); int status = SUCCESS;
if (status == SUCCESS) { if ((enabled && (mState == STATE_INITIALIZED)) ||
mState = enabled ? STATE_ENABLED : STATE_INITIALIZED; (!enabled && (mState == STATE_ENABLED))) {
status = native_setEnabled(enabled);
if (status == SUCCESS) {
mState = enabled ? STATE_ENABLED : STATE_INITIALIZED;
}
} }
return status; return status;
} }

View File

@@ -239,6 +239,24 @@ extern "C" int Visualizer_process(
} }
// all code below assumes stereo 16 bit PCM output and input // 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 captIdx;
uint32_t inIdx; uint32_t inIdx;
uint8_t *buf = pContext->mCaptureBuf[pContext->mCurrentBuf]; uint8_t *buf = pContext->mCaptureBuf[pContext->mCurrentBuf];
@@ -246,7 +264,7 @@ extern "C" int Visualizer_process(
inIdx < inBuffer->frameCount && captIdx < pContext->mCaptureSize; inIdx < inBuffer->frameCount && captIdx < pContext->mCaptureSize;
inIdx++, captIdx++) { inIdx++, captIdx++) {
int32_t smp = inBuffer->s16[2 * inIdx] + inBuffer->s16[2 * inIdx + 1]; 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; buf[captIdx] = ((uint8_t)smp)^0x80;
} }
pContext->mCaptureIdx = captIdx; pContext->mCaptureIdx = captIdx;
@@ -369,7 +387,7 @@ extern "C" int Visualizer_command(effect_interface_t self, uint32_t cmdCode, uin
case VISU_CMD_CAPTURE: 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", LOGV("VISU_CMD_CAPTURE() error *replySize %d pContext->mCaptureSize %d",
*replySize, pContext->mCaptureSize); *replySize, pContext->mCaptureSize);
return -EINVAL; return -EINVAL;