diff options
author | 2010-07-09 13:34:17 -0700 | |
---|---|---|
committer | 2010-07-13 12:27:18 -0700 | |
commit | 7d850f23c857fe0c0deec9b9ea593d3029665a16 (patch) | |
tree | c5b885b890b6707a42a0f54cb4f2e3d4b7e6eacd /media/libeffects/EffectEqualizer.cpp | |
parent | e339464f1c8efe7e53b761cf44ff5be6e537ecad (diff) |
Modifications in audio effect engine state management.
- Separate the updating of effect engine state from the process call in EffectModule so that the state
of all effects in the same effect chain is updated simultaneusly before all process functions are called.
- Added a mechanism for the effect engine to continue being called for processing after receiving the disable
commands untils it considers that the framework can stop calling the process function without causing
a glitch or loosing some effect tail.
- Updated test reverb and equalizer to support this new feature
Change-Id: Icb56ae2c84c076d4dbad6cf733b1a62f823febe7
Diffstat (limited to 'media/libeffects/EffectEqualizer.cpp')
-rw-r--r-- | media/libeffects/EffectEqualizer.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/media/libeffects/EffectEqualizer.cpp b/media/libeffects/EffectEqualizer.cpp index d19c6b9fdbcb..af0c411aa725 100644 --- a/media/libeffects/EffectEqualizer.cpp +++ b/media/libeffects/EffectEqualizer.cpp @@ -30,6 +30,12 @@ // effect_interface_t interface implementation for equalizer effect extern "C" const struct effect_interface_s gEqualizerInterface; +enum equalizer_state_e { + EQUALIZER_STATE_UNINITIALIZED, + EQUALIZER_STATE_INITIALIZED, + EQUALIZER_STATE_ACTIVE, +}; + namespace android { namespace { @@ -100,6 +106,7 @@ struct EqualizerContext { effect_config_t config; FormatAdapter adapter; AudioEqualizer * pEqualizer; + uint32_t state; }; //--- local function prototypes @@ -151,6 +158,7 @@ extern "C" int EffectCreate(effect_uuid_t *uuid, pContext->itfe = &gEqualizerInterface; pContext->pEqualizer = NULL; + pContext->state = EQUALIZER_STATE_UNINITIALIZED; ret = Equalizer_init(pContext); if (ret < 0) { @@ -160,6 +168,7 @@ extern "C" int EffectCreate(effect_uuid_t *uuid, } *pInterface = (effect_interface_t)pContext; + pContext->state = EQUALIZER_STATE_INITIALIZED; LOGV("EffectLibCreateEffect %p, size %d", pContext, AudioEqualizer::GetInstanceSize(kNumBands)+sizeof(EqualizerContext)); @@ -175,6 +184,7 @@ extern "C" int EffectRelease(effect_interface_t interface) { return -EINVAL; } + pContext->state = EQUALIZER_STATE_UNINITIALIZED; pContext->pEqualizer->free(); delete pContext; @@ -528,6 +538,13 @@ extern "C" int Equalizer_process(effect_interface_t self, audio_buffer_t *inBuff return -EINVAL; } + if (pContext->state == EQUALIZER_STATE_UNINITIALIZED) { + return -EINVAL; + } + if (pContext->state == EQUALIZER_STATE_INITIALIZED) { + return -ENODATA; + } + pContext->adapter.process(inBuffer->raw, outBuffer->raw, outBuffer->frameCount); return 0; @@ -539,7 +556,7 @@ extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSi android::EqualizerContext * pContext = (android::EqualizerContext *) self; int retsize; - if (pContext == NULL) { + if (pContext == NULL || pContext->state == EQUALIZER_STATE_UNINITIALIZED) { return -EINVAL; } @@ -594,10 +611,25 @@ extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSi p->data + p->psize); } break; case EFFECT_CMD_ENABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + if (pContext->state != EQUALIZER_STATE_INITIALIZED) { + return -ENOSYS; + } + pContext->state = EQUALIZER_STATE_ACTIVE; + LOGV("EFFECT_CMD_ENABLE() OK"); + *(int *)pReplyData = 0; + break; case EFFECT_CMD_DISABLE: if (pReplyData == NULL || *replySize != sizeof(int)) { return -EINVAL; } + if (pContext->state != EQUALIZER_STATE_ACTIVE) { + return -ENOSYS; + } + pContext->state = EQUALIZER_STATE_INITIALIZED; + LOGV("EFFECT_CMD_DISABLE() OK"); *(int *)pReplyData = 0; break; case EFFECT_CMD_SET_DEVICE: |