diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2012-04-15 17:15:07 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2012-04-18 18:27:39 -0700 |
commit | 3476de62fb10e76412452ef4c6bd71936c9f7db1 (patch) | |
tree | 9c814922fd33670a7cdd23c9597cbd19ad5e1ef9 /media/libeffects/visualizer/EffectVisualizer.cpp | |
parent | fbe308d428e42fe249ec317f76e3d11feb3264d5 (diff) | |
download | frameworks_av-3476de62fb10e76412452ef4c6bd71936c9f7db1.zip frameworks_av-3476de62fb10e76412452ef4c6bd71936c9f7db1.tar.gz frameworks_av-3476de62fb10e76412452ef4c6bd71936c9f7db1.tar.bz2 |
Add support for scaling mode parameter
Support VISUALIZER_PARAM__SCALING_MODE parameter.
Modify process() function to use new volume scaling parameter,
used to set whether captured values are maximized by current
headroom in the buffer (default existing behaviora) or left
as is and thus affected by volume.
Modify AudioEffect to allow subclasses to override the following
events: control status changed, enable status changed, command
executed.
In Visualizer class (a subclass of AudioEffect), reset the
scaling mode and capture size on the actual effect
as cached when control is regained.
This will allow the effect to be properly
configured whenever Visualizers with different scaling
modes or capture sizes are released (e.g. from java
release() method).
Change-Id: I05cb9f925a296dceca91bafa9fe294ef2b2c2bd5
Diffstat (limited to 'media/libeffects/visualizer/EffectVisualizer.cpp')
-rw-r--r-- | media/libeffects/visualizer/EffectVisualizer.cpp | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp index bdb1a1c..44d05cd 100644 --- a/media/libeffects/visualizer/EffectVisualizer.cpp +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "Visualizer" +#define LOG_TAG "EffectVisualizer" //#define LOG_NDEBUG 0 #include <cutils/log.h> #include <assert.h> @@ -57,6 +57,7 @@ struct VisualizerContext { effect_config_t mConfig; uint32_t mCaptureIdx; uint32_t mCaptureSize; + uint32_t mScalingMode; uint8_t mState; uint8_t mCurrentBuf; uint8_t mLastBuf; @@ -164,6 +165,7 @@ int Visualizer_init(VisualizerContext *pContext) pContext->mConfig.outputCfg.mask = EFFECT_CONFIG_ALL; pContext->mCaptureSize = VISUALIZER_CAPTURE_SIZE_MAX; + pContext->mScalingMode = VISUALIZER_SCALING_MODE_NORMALIZED; Visualizer_setConfig(pContext, &pContext->mConfig); @@ -285,26 +287,32 @@ 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; - int len = inBuffer->frameCount * 2; - for (int i = 0; i < len; i++) { - int32_t smp = inBuffer->s16[i]; - if (smp < 0) smp = -smp - 1; // take care to keep the max negative in range - int32_t clz = __builtin_clz(smp); - if (shift > clz) shift = clz; - } - // A maximum amplitude signal will have 17 leading zeros, which we want to - // translate to a shift of 8 (for converting 16 bit to 8 bit) - shift = 25 - shift; - // Never scale by less than 8 to avoid returning unaltered PCM signal. - if (shift < 3) { - shift = 3; + int32_t shift; + + if (pContext->mScalingMode == VISUALIZER_SCALING_MODE_NORMALIZED) { + // derive capture scaling factor from peak value in current buffer + // this gives more interesting captures for display. + shift = 32; + int len = inBuffer->frameCount * 2; + for (int i = 0; i < len; i++) { + int32_t smp = inBuffer->s16[i]; + if (smp < 0) smp = -smp - 1; // take care to keep the max negative in range + int32_t clz = __builtin_clz(smp); + if (shift > clz) shift = clz; + } + // A maximum amplitude signal will have 17 leading zeros, which we want to + // translate to a shift of 8 (for converting 16 bit to 8 bit) + shift = 25 - shift; + // Never scale by less than 8 to avoid returning unaltered PCM signal. + if (shift < 3) { + shift = 3; + } + // add one to combine the division by 2 needed after summing left and right channels below + shift++; + } else { + assert(pContext->mScalingMode == VISUALIZER_SCALING_MODE_AS_PLAYED); + shift = 9; } - // add one to combine the division by 2 needed after summing left and right channels below - shift++; uint32_t captIdx; uint32_t inIdx; @@ -414,15 +422,26 @@ int Visualizer_command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize, effect_param_t *p = (effect_param_t *)pReplyData; p->status = 0; *replySize = sizeof(effect_param_t) + sizeof(uint32_t); - if (p->psize != sizeof(uint32_t) || - *(uint32_t *)p->data != VISUALIZER_PARAM_CAPTURE_SIZE) { + if (p->psize != sizeof(uint32_t)) { p->status = -EINVAL; break; } - ALOGV("get mCaptureSize = %d", pContext->mCaptureSize); - *((uint32_t *)p->data + 1) = pContext->mCaptureSize; - p->vsize = sizeof(uint32_t); - *replySize += sizeof(uint32_t); + switch (*(uint32_t *)p->data) { + case VISUALIZER_PARAM_CAPTURE_SIZE: + ALOGV("get mCaptureSize = %d", pContext->mCaptureSize); + *((uint32_t *)p->data + 1) = pContext->mCaptureSize; + p->vsize = sizeof(uint32_t); + *replySize += sizeof(uint32_t); + break; + case VISUALIZER_PARAM_SCALING_MODE: + ALOGV("get mScalingMode = %d", pContext->mScalingMode); + *((uint32_t *)p->data + 1) = pContext->mScalingMode; + p->vsize = sizeof(uint32_t); + *replySize += sizeof(uint32_t); + break; + default: + p->status = -EINVAL; + } } break; case EFFECT_CMD_SET_PARAM: { if (pCmdData == NULL || @@ -432,14 +451,22 @@ int Visualizer_command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize, } *(int32_t *)pReplyData = 0; effect_param_t *p = (effect_param_t *)pCmdData; - if (p->psize != sizeof(uint32_t) || - p->vsize != sizeof(uint32_t) || - *(uint32_t *)p->data != VISUALIZER_PARAM_CAPTURE_SIZE) { + if (p->psize != sizeof(uint32_t) || p->vsize != sizeof(uint32_t)) { + *(int32_t *)pReplyData = -EINVAL; + break; + } + switch (*(uint32_t *)p->data) { + case VISUALIZER_PARAM_CAPTURE_SIZE: + pContext->mCaptureSize = *((uint32_t *)p->data + 1); + ALOGV("set mCaptureSize = %d", pContext->mCaptureSize); + break; + case VISUALIZER_PARAM_SCALING_MODE: + pContext->mScalingMode = *((uint32_t *)p->data + 1); + ALOGV("set mScalingMode = %d", pContext->mScalingMode); + break; + default: *(int32_t *)pReplyData = -EINVAL; - break;; } - pContext->mCaptureSize = *((uint32_t *)p->data + 1); - ALOGV("set mCaptureSize = %d", pContext->mCaptureSize); } break; case EFFECT_CMD_SET_DEVICE: case EFFECT_CMD_SET_VOLUME: |