diff options
author | Eric Laurent <elaurent@google.com> | 2010-07-30 09:52:40 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-07-30 09:52:40 -0700 |
commit | e67332f879b3f97baaac2252b53ac64686aebdbb (patch) | |
tree | c6fa56d7d0d2f7cd23c4b9c2dc47000e4d005241 /media | |
parent | 85673d91681e6b5dede0c72f36ed3b81f5c4bb0d (diff) | |
parent | 92e847ed8e455dca3b2d33d92999e3960404d9af (diff) | |
download | frameworks_base-e67332f879b3f97baaac2252b53ac64686aebdbb.zip frameworks_base-e67332f879b3f97baaac2252b53ac64686aebdbb.tar.gz frameworks_base-e67332f879b3f97baaac2252b53ac64686aebdbb.tar.bz2 |
am 92e847ed: Audio effects: aligned Equalizer API argument types on OpenSL ES SLEqualizerItf.
Merge commit '92e847ed8e455dca3b2d33d92999e3960404d9af' into gingerbread-plus-aosp
* commit '92e847ed8e455dca3b2d33d92999e3960404d9af':
Audio effects: aligned Equalizer API argument types on OpenSL ES SLEqualizerItf.
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/Equalizer.java | 60 | ||||
-rw-r--r-- | media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp | 58 | ||||
-rw-r--r-- | media/libeffects/testlibs/EffectEqualizer.cpp | 69 |
3 files changed, 124 insertions, 63 deletions
diff --git a/media/java/android/media/Equalizer.java b/media/java/android/media/Equalizer.java index 21c37bb..b062b64 100644 --- a/media/java/android/media/Equalizer.java +++ b/media/java/android/media/Equalizer.java @@ -182,9 +182,9 @@ public class Equalizer extends AudioEffect { } int[] param = new int[1]; param[0] = PARAM_NUM_BANDS; - short[] value = new short[1]; - checkStatus(getParameter(param, value)); - mNumBands = value[0]; + short[] result = new short[1]; + checkStatus(getParameter(param, result)); + mNumBands = result[0]; return mNumBands; } @@ -199,16 +199,8 @@ public class Equalizer extends AudioEffect { */ public short[] getBandLevelRange() throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { - int[] param = new int[1]; - int[] value = new int[2]; - param[0] = PARAM_LEVEL_RANGE; - checkStatus(getParameter(param, value)); - short[] result = new short[2]; - - result[0] = (short)value[0]; - result[1] = (short)value[1]; - + checkStatus(getParameter(PARAM_LEVEL_RANGE, result)); return result; } @@ -222,14 +214,14 @@ public class Equalizer extends AudioEffect { * @throws IllegalArgumentException * @throws UnsupportedOperationException */ - public void setBandLevel(int band, short level) + public void setBandLevel(short band, short level) throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { int[] param = new int[2]; - int[] value = new int[1]; + short[] value = new short[1]; param[0] = PARAM_BAND_LEVEL; - param[1] = band; - value[0] = (int)level; + param[1] = (int)band; + value[0] = level; checkStatus(setParameter(param, value)); } @@ -242,16 +234,16 @@ public class Equalizer extends AudioEffect { * @throws IllegalArgumentException * @throws UnsupportedOperationException */ - public short getBandLevel(int band) + public short getBandLevel(short band) throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { int[] param = new int[2]; - int[] result = new int[1]; + short[] result = new short[1]; param[0] = PARAM_BAND_LEVEL; - param[1] = band; + param[1] = (int)band; checkStatus(getParameter(param, result)); - return (short)result[0]; + return result[0]; } @@ -264,13 +256,13 @@ public class Equalizer extends AudioEffect { * @throws IllegalArgumentException * @throws UnsupportedOperationException */ - public int getCenterFreq(int band) + public int getCenterFreq(short band) throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { int[] param = new int[2]; int[] result = new int[1]; param[0] = PARAM_CENTER_FREQ; - param[1] = band; + param[1] = (int)band; checkStatus(getParameter(param, result)); return result[0]; @@ -286,12 +278,12 @@ public class Equalizer extends AudioEffect { * @throws IllegalArgumentException * @throws UnsupportedOperationException */ - public int[] getBandFreqRange(int band) + public int[] getBandFreqRange(short band) throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { int[] param = new int[2]; int[] result = new int[2]; param[0] = PARAM_BAND_FREQ_RANGE; - param[1] = band; + param[1] = (int)band; checkStatus(getParameter(param, result)); return result; @@ -305,10 +297,10 @@ public class Equalizer extends AudioEffect { * @throws IllegalArgumentException * @throws UnsupportedOperationException */ - public int getBand(int frequency) + public short getBand(int frequency) throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { int[] param = new int[2]; - int[] result = new int[1]; + short[] result = new short[1]; param[0] = PARAM_GET_BAND; param[1] = frequency; @@ -326,11 +318,9 @@ public class Equalizer extends AudioEffect { */ public short getCurrentPreset() throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { - int[] param = new int[1]; - param[0] = PARAM_CURRENT_PRESET; - short[] value = new short[1]; - checkStatus(getParameter(param, value)); - return value[0]; + short[] result = new short[1]; + checkStatus(getParameter(PARAM_CURRENT_PRESET, result)); + return result[0]; } /** @@ -356,11 +346,9 @@ public class Equalizer extends AudioEffect { */ public short getNumberOfPresets() throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { - int[] param = new int[1]; - param[0] = PARAM_GET_NUM_OF_PRESETS; - short[] value = new short[1]; - checkStatus(getParameter(param, value)); - return value[0]; + short[] result = new short[1]; + checkStatus(getParameter(PARAM_GET_NUM_OF_PRESETS, result)); + return result[0]; } /** diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp index 4c3ebca..a70bdff 100644 --- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp @@ -1848,6 +1848,8 @@ int Equalizer_getParameter(EffectContext *pContext, case EQ_PARAM_NUM_BANDS: case EQ_PARAM_CUR_PRESET: case EQ_PARAM_GET_NUM_OF_PRESETS: + case EQ_PARAM_BAND_LEVEL: + case EQ_PARAM_GET_BAND: if (*pValueSize < sizeof(int16_t)) { LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); return -EINVAL; @@ -1856,6 +1858,13 @@ int Equalizer_getParameter(EffectContext *pContext, break; case EQ_PARAM_LEVEL_RANGE: + if (*pValueSize < 2 * sizeof(int16_t)) { + LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2 %d", *pValueSize); + return -EINVAL; + } + *pValueSize = 2 * sizeof(int16_t); + break; + case EQ_PARAM_BAND_FREQ_RANGE: if (*pValueSize < 2 * sizeof(int32_t)) { LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2 %d", *pValueSize); @@ -1863,8 +1872,7 @@ int Equalizer_getParameter(EffectContext *pContext, } *pValueSize = 2 * sizeof(int32_t); break; - case EQ_PARAM_BAND_LEVEL: - case EQ_PARAM_GET_BAND: + case EQ_PARAM_CENTER_FREQ: if (*pValueSize < sizeof(int32_t)) { LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); @@ -1891,13 +1899,13 @@ int Equalizer_getParameter(EffectContext *pContext, switch (param) { case EQ_PARAM_NUM_BANDS: - *(int16_t *)pValue = FIVEBAND_NUMBANDS; + *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS; //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); break; case EQ_PARAM_LEVEL_RANGE: - *(int32_t *)pValue = -1500; - *((int32_t *)pValue + 1) = 1500; + *(int16_t *)pValue = -1500; + *((int16_t *)pValue + 1) = 1500; //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", // *(int32_t *)pValue, *((int32_t *)pValue + 1)); break; @@ -1908,7 +1916,7 @@ int Equalizer_getParameter(EffectContext *pContext, status = -EINVAL; break; } - *(int32_t *)pValue = EqualizerGetBandLevel(pContext, param2); + *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2); //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", // param2, *(int32_t *)pValue); break; @@ -1937,18 +1945,18 @@ int Equalizer_getParameter(EffectContext *pContext, case EQ_PARAM_GET_BAND: param2 = *pParam; - *(int32_t *)pValue = EqualizerGetBand(pContext, param2); + *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2); //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", // param2, *(int32_t *)pValue); break; case EQ_PARAM_CUR_PRESET: - *(int16_t *)pValue = EqualizerGetPreset(pContext); + *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext); //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); break; case EQ_PARAM_GET_NUM_OF_PRESETS: - *(int16_t *)pValue = EqualizerGetNumPresets(); + *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets(); //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); break; @@ -1968,12 +1976,12 @@ int Equalizer_getParameter(EffectContext *pContext, break; case EQ_PARAM_PROPERTIES: { - uint16_t *p = (uint16_t *)pValue; + int16_t *p = (int16_t *)pValue; LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES"); - p[0] = EqualizerGetPreset(pContext); - p[1] = FIVEBAND_NUMBANDS; + p[0] = (int16_t)EqualizerGetPreset(pContext); + p[1] = (int16_t)FIVEBAND_NUMBANDS; for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { - p[2 + i] = EqualizerGetBandLevel(pContext, i); + p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i); } } break; @@ -2011,7 +2019,7 @@ int Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pVal //LOGV("\tEqualizer_setParameter start"); switch (param) { case EQ_PARAM_CUR_PRESET: - preset = *(int16_t *)pValue; + preset = (int32_t)(*(uint16_t *)pValue); //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset); if ((preset >= EqualizerGetNumPresets())||(preset < 0)) { @@ -2022,7 +2030,7 @@ int Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pVal break; case EQ_PARAM_BAND_LEVEL: band = *pParam; - level = *(int32_t *)pValue; + level = (int32_t)(*(int16_t *)pValue); //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); if (band >= FIVEBAND_NUMBANDS) { status = -EINVAL; @@ -2030,8 +2038,28 @@ int Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pVal } EqualizerSetBandLevel(pContext, band, level); break; + case EQ_PARAM_PROPERTIES: { + //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES"); + int16_t *p = (int16_t *)pValue; + if ((int)p[0] >= EqualizerGetNumPresets()) { + status = -EINVAL; + break; + } + if (p[0] >= 0) { + EqualizerSetPreset(pContext, (int)p[0]); + } else { + if ((int)p[1] != FIVEBAND_NUMBANDS) { + status = -EINVAL; + break; + } + for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { + EqualizerSetBandLevel(pContext, i, (int)p[2 + i]); + } + } + } break; default: LOGV("\tLVM_ERROR : setParameter() invalid param %d", param); + status = -EINVAL; break; } diff --git a/media/libeffects/testlibs/EffectEqualizer.cpp b/media/libeffects/testlibs/EffectEqualizer.cpp index a71f236..f8e4357 100644 --- a/media/libeffects/testlibs/EffectEqualizer.cpp +++ b/media/libeffects/testlibs/EffectEqualizer.cpp @@ -350,6 +350,8 @@ int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t case EQ_PARAM_NUM_BANDS: case EQ_PARAM_CUR_PRESET: case EQ_PARAM_GET_NUM_OF_PRESETS: + case EQ_PARAM_BAND_LEVEL: + case EQ_PARAM_GET_BAND: if (*pValueSize < sizeof(int16_t)) { return -EINVAL; } @@ -357,14 +359,19 @@ int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t break; case EQ_PARAM_LEVEL_RANGE: + if (*pValueSize < 2 * sizeof(int16_t)) { + return -EINVAL; + } + *pValueSize = 2 * sizeof(int16_t); + break; + case EQ_PARAM_BAND_FREQ_RANGE: if (*pValueSize < 2 * sizeof(int32_t)) { return -EINVAL; } *pValueSize = 2 * sizeof(int32_t); break; - case EQ_PARAM_BAND_LEVEL: - case EQ_PARAM_GET_BAND: + case EQ_PARAM_CENTER_FREQ: if (*pValueSize < sizeof(int32_t)) { return -EINVAL; @@ -375,19 +382,26 @@ int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t case EQ_PARAM_GET_PRESET_NAME: break; + case EQ_PARAM_PROPERTIES: + if (*pValueSize < (2 + kNumBands) * sizeof(uint16_t)) { + return -EINVAL; + } + *pValueSize = (2 + kNumBands) * sizeof(uint16_t); + break; + default: return -EINVAL; } switch (param) { case EQ_PARAM_NUM_BANDS: - *(int16_t *)pValue = kNumBands; + *(uint16_t *)pValue = (uint16_t)kNumBands; LOGV("Equalizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); break; case EQ_PARAM_LEVEL_RANGE: - *(int32_t *)pValue = -9600; - *((int32_t *)pValue + 1) = 4800; + *(int16_t *)pValue = -9600; + *((int16_t *)pValue + 1) = 4800; LOGV("Equalizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", *(int32_t *)pValue, *((int32_t *)pValue + 1)); break; @@ -397,7 +411,7 @@ int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t status = -EINVAL; break; } - *(int32_t *)pValue = pEqualizer->getGain(param2); + *(int16_t *)pValue = (int16_t)pEqualizer->getGain(param2); LOGV("Equalizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", param2, *(int32_t *)pValue); break; @@ -423,17 +437,17 @@ int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t case EQ_PARAM_GET_BAND: param2 = *pParam; - *(int32_t *)pValue = pEqualizer->getMostRelevantBand(param2); + *(uint16_t *)pValue = (uint16_t)pEqualizer->getMostRelevantBand(param2); LOGV("Equalizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", param2, *(int32_t *)pValue); break; case EQ_PARAM_CUR_PRESET: - *(int16_t *)pValue = pEqualizer->getPreset(); + *(uint16_t *)pValue = (uint16_t)pEqualizer->getPreset(); LOGV("Equalizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); break; case EQ_PARAM_GET_NUM_OF_PRESETS: - *(int16_t *)pValue = pEqualizer->getNumPresets(); + *(uint16_t *)pValue = (uint16_t)pEqualizer->getNumPresets(); LOGV("Equalizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); break; @@ -450,6 +464,16 @@ int Equalizer_getParameter(AudioEqualizer * pEqualizer, int32_t *pParam, size_t LOGV("Equalizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d", param2, gEqualizerPresets[param2].name, *pValueSize); break; + case EQ_PARAM_PROPERTIES: { + int16_t *p = (int16_t *)pValue; + LOGV("Equalizer_getParameter() EQ_PARAM_PROPERTIES"); + p[0] = (int16_t)pEqualizer->getPreset(); + p[1] = (int16_t)kNumBands; + for (int i = 0; i < kNumBands; i++) { + p[2 + i] = (int16_t)pEqualizer->getGain(i); + } + } break; + default: LOGV("Equalizer_getParameter() invalid param %d", param); status = -EINVAL; @@ -489,10 +513,10 @@ int Equalizer_setParameter (AudioEqualizer * pEqualizer, int32_t *pParam, void * switch (param) { case EQ_PARAM_CUR_PRESET: - preset = *(int16_t *)pValue; + preset = (int32_t)(*(uint16_t *)pValue); LOGV("setParameter() EQ_PARAM_CUR_PRESET %d", preset); - if (preset >= pEqualizer->getNumPresets()) { + if (preset < 0 || preset >= pEqualizer->getNumPresets()) { status = -EINVAL; break; } @@ -501,7 +525,7 @@ int Equalizer_setParameter (AudioEqualizer * pEqualizer, int32_t *pParam, void * break; case EQ_PARAM_BAND_LEVEL: band = *pParam; - level = *(int32_t *)pValue; + level = (int32_t)(*(int16_t *)pValue); LOGV("setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); if (band >= kNumBands) { status = -EINVAL; @@ -510,8 +534,29 @@ int Equalizer_setParameter (AudioEqualizer * pEqualizer, int32_t *pParam, void * pEqualizer->setGain(band, level); pEqualizer->commit(true); break; + case EQ_PARAM_PROPERTIES: { + LOGV("setParameter() EQ_PARAM_PROPERTIES"); + int16_t *p = (int16_t *)pValue; + if ((int)p[0] >= pEqualizer->getNumPresets()) { + status = -EINVAL; + break; + } + if (p[0] >= 0) { + pEqualizer->setPreset((int)p[0]); + } else { + if ((int)p[1] != kNumBands) { + status = -EINVAL; + break; + } + for (int i = 0; i < kNumBands; i++) { + pEqualizer->setGain(i, (int32_t)p[2 + i]); + } + } + pEqualizer->commit(true); + } break; default: LOGV("setParameter() invalid param %d", param); + status = -EINVAL; break; } |