14be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi/*
24be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * Copyright (C) 2010 The Android Open Source Project
34be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi *
44be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
54be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * you may not use this file except in compliance with the License.
64be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * You may obtain a copy of the License at
74be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi *
84be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
94be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi *
104be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
114be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
124be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * See the License for the specific language governing permissions and
144be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi * limitations under the License.
154be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi */
164be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
174be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
184be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi#include "sles_allinclusive.h"
194be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi#include "math.h"
204be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi#include "utils/RefBase.h"
212523b697aa1fda376c2ccd72680394d359acbd3fSvet Ganov#include "utils/String16.h"
222523b697aa1fda376c2ccd72680394d359acbd3fSvet Ganov
235639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_bassboost.h>
245639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_equalizer.h>
255639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_environmentalreverb.h>
265639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_presetreverb.h>
275639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_virtualizer.h>
285639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov
295639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_aec.h>
305639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_agc.h>
315639df9d17ff8ae0ab83f1a31187a284044689d7Mikhail Naganov#include <system/audio_effects/effect_ns.h>
32f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
3310a3840407ac3ed61e7873ee7b86d664ccc6149fDima Zavin#include <system/audio.h>
344be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
354be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivistatic const int EQUALIZER_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t)
364be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        + EFFECT_STRING_LEN_MAX;
374be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
389cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivistatic const int BASSBOOST_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t);
399cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
40f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivistatic const int VIRTUALIZER_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t);
41f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
42f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivistatic const int ENVREVERB_PARAM_SIZE_MAX_SINGLE = sizeof(effect_param_t) + 2 * sizeof(int32_t);
43f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
44f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivistatic const int ENVREVERB_PARAM_SIZE_MAX_ALL = sizeof(effect_param_t) + sizeof(int32_t)
45f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        + sizeof(s_reverb_settings);
46f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
474e1412ba1d9e74e51a01d34b1c588166d68e4332Glenn Kastenstatic const int PRESETREVERB_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t);
484e1412ba1d9e74e51a01d34b1c588166d68e4332Glenn Kasten
495b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivistatic inline SLuint32 KEY_FROM_GUID(SLInterfaceID pUuid) {
505b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    return pUuid->time_low;
515b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi}
525b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi
534be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
544be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi//-----------------------------------------------------------------------------
5504e38178473bb0ffdb4759956db60dd86aa7e732Glenn Kastenstatic
569cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Triviuint32_t eq_paramSize(int32_t param) {
574be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    uint32_t size;
584be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
594be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    switch (param) {
604be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_NUM_BANDS:
614be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_LEVEL_RANGE:
624be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_CUR_PRESET:
634be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_GET_NUM_OF_PRESETS:
644be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = sizeof(int32_t);
654be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
664be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_BAND_LEVEL:
674be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_CENTER_FREQ:
684be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_BAND_FREQ_RANGE:
694be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_GET_BAND:
704be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_GET_PRESET_NAME:
714be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = 2 * sizeof(int32_t);
724be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
734be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    default:
744be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = 2 * sizeof(int32_t);
754be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        SL_LOGE("Trying to use an unknown EQ parameter %d", param);
764be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
774be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
784be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    return size;
794be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi}
804be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
8104e38178473bb0ffdb4759956db60dd86aa7e732Glenn Kastenstatic
829cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Triviuint32_t eq_valueSize(int32_t param) {
834be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    uint32_t size;
844be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
854be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    switch (param) {
864be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_NUM_BANDS:
874be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_CUR_PRESET:
884be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_GET_NUM_OF_PRESETS:
894be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_BAND_LEVEL:
904be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_GET_BAND:
91b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent        size = sizeof(int16_t);
92b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent        break;
93b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent    case EQ_PARAM_LEVEL_RANGE:
94b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent        size = 2 * sizeof(int16_t);
95b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent        break;
964be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_CENTER_FREQ:
974be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = sizeof(int32_t);
984be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
994be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_BAND_FREQ_RANGE:
1004be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = 2 * sizeof(int32_t);
1014be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
1024be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    case EQ_PARAM_GET_PRESET_NAME:
1034be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = EFFECT_STRING_LEN_MAX;
1044be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
1054be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    default:
1064be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        size = sizeof(int32_t);
1074be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        SL_LOGE("Trying to access an unknown EQ parameter %d", param);
1084be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        break;
1094be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
1104be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    return size;
1114be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi}
1124be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
1139cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi//-----------------------------------------------------------------------------
1149cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi/**
115f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi * returns the size in bytes of the value of each bass boost parameter
1169cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi */
11704e38178473bb0ffdb4759956db60dd86aa7e732Glenn Kastenstatic
118f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Triviuint32_t bb_valueSize(int32_t param) {
1199cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    uint32_t size;
1209cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
1219cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    switch (param) {
1229cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
1239cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        size = sizeof(int32_t);
1249cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        break;
125f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    case BASSBOOST_PARAM_STRENGTH:
126f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        size = sizeof(int16_t);
127f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        break;
1289cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    default:
1299cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        size = sizeof(int32_t);
130f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        SL_LOGE("Trying to access an unknown BassBoost parameter %d", param);
1319cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        break;
1329cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    }
1339cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
1349cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    return size;
1359cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi}
1369cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
137f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
1389cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi/**
139f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi * returns the size in bytes of the value of each virtualizer parameter
1409cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi */
14104e38178473bb0ffdb4759956db60dd86aa7e732Glenn Kastenstatic
142f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Triviuint32_t virt_valueSize(int32_t param) {
1439cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    uint32_t size;
1449cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
1459cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    switch (param) {
146f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
1479cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        size = sizeof(int32_t);
1489cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        break;
149f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    case VIRTUALIZER_PARAM_STRENGTH:
1509cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        size = sizeof(int16_t);
1519cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        break;
1529cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    default:
1539cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        size = sizeof(int32_t);
154f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        SL_LOGE("Trying to access an unknown Virtualizer parameter %d", param);
1559cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        break;
1569cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    }
1579cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
1589cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    return size;
1599cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi}
1609cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
1614be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi//-----------------------------------------------------------------------------
162f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi/**
163f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi * returns the size in bytes of the value of each environmental reverb parameter
164f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi */
16504e38178473bb0ffdb4759956db60dd86aa7e732Glenn Kastenstatic
166f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Triviuint32_t erev_valueSize(int32_t param) {
167f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    uint32_t size;
168f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
169f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    switch (param) {
170f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_ROOM_LEVEL:
171f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_ROOM_HF_LEVEL:
172f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_REFLECTIONS_LEVEL:
173f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_REVERB_LEVEL:
174f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        size = sizeof(int16_t); // millibel
175f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        break;
176f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_DECAY_TIME:
177f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_REFLECTIONS_DELAY:
178f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_REVERB_DELAY:
179f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        size = sizeof(uint32_t); // milliseconds
180f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        break;
181f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_DECAY_HF_RATIO:
182f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_DIFFUSION:
183f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_DENSITY:
184f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        size = sizeof(int16_t); // permille
185f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        break;
186f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    case REVERB_PARAM_PROPERTIES:
187f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        size = sizeof(s_reverb_settings); // struct of all reverb properties
188f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        break;
189f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    default:
190f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        size = sizeof(int32_t);
191f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        SL_LOGE("Trying to access an unknown Environmental Reverb parameter %d", param);
192f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        break;
193f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    }
194f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
195f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    return size;
196f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi}
197f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
198f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi//-----------------------------------------------------------------------------
1999bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_eq_getParam(const android::sp<android::AudioEffect>& pFx,
2004be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        int32_t param, int32_t param2, void *pValue)
2014be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi{
2024be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     android::status_t status;
2034be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     uint32_t buf32[(EQUALIZER_PARAM_SIZE_MAX - 1) / sizeof(uint32_t) + 1];
2044be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     effect_param_t *p = (effect_param_t *)buf32;
2054be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2064be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     p->psize = eq_paramSize(param);
2074be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     *(int32_t *)p->data = param;
2084be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     if (p->psize == 2 * sizeof(int32_t)) {
2094be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi         *((int32_t *)p->data + 1) = param2;
2104be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     }
2114be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     p->vsize = eq_valueSize(param);
2124be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     status = pFx->getParameter(p);
2134be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     if (android::NO_ERROR == status) {
2144be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi         status = p->status;
2154be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi         if (android::NO_ERROR == status) {
2164be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi             memcpy(pValue, p->data + p->psize, p->vsize);
2174be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi         }
2184be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     }
2194be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2204be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi     return status;
2214be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi }
2224be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2234be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2244be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi//-----------------------------------------------------------------------------
2259bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_eq_setParam(const android::sp<android::AudioEffect>& pFx,
2264be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        int32_t param, int32_t param2, void *pValue)
2274be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi{
2284be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    android::status_t status;
2294be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    uint32_t buf32[(EQUALIZER_PARAM_SIZE_MAX - 1) / sizeof(uint32_t) + 1];
2304be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    effect_param_t *p = (effect_param_t *)buf32;
2314be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2324be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    p->psize = eq_paramSize(param);
2334be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    *(int32_t *)p->data = param;
2344be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    if (p->psize == 2 * sizeof(int32_t)) {
2354be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        *((int32_t *)p->data + 1) = param2;
2364be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
2374be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    p->vsize = eq_valueSize(param);
2384be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    memcpy(p->data + p->psize, pValue, p->vsize);
2394be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    status = pFx->setParameter(p);
2404be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    if (android::NO_ERROR == status) {
2414be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        status = p->status;
2424be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
2434be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2444be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    return status;
2454be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi}
2464be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2479cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi//-----------------------------------------------------------------------------
2489bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_bb_setParam(const android::sp<android::AudioEffect>& pFx,
2499cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        int32_t param, void *pValue) {
2509cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
251f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return android_fx_setParam(pFx, param, BASSBOOST_PARAM_SIZE_MAX,
252f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            pValue, bb_valueSize(param));
2539cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi}
2549cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
2559cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi//-----------------------------------------------------------------------------
2569bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_bb_getParam(const android::sp<android::AudioEffect>& pFx,
2579cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        int32_t param, void *pValue) {
2589cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
259f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return android_fx_getParam(pFx, param, BASSBOOST_PARAM_SIZE_MAX,
260f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            pValue, bb_valueSize(param));
2619cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi}
2629cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
2639cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi//-----------------------------------------------------------------------------
264213c31153b9bda7b5a091f2996da7b655c8ed451Glenn Kastenvoid android_bb_init(audio_session_t sessionId, IBassBoost* ibb) {
2659cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    SL_LOGV("session %d", sessionId);
2669cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
267172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    if (!android_fx_initEffectObj(sessionId, ibb->mBassBoostEffect,
26800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi            &ibb->mBassBoostDescriptor.type))
269f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    {
270f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        SL_LOGE("BassBoost effect initialization failed");
2719cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi        return;
2729cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    }
2739cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi
274f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    // initialize strength
2759cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    int16_t strength;
276172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    if (android::NO_ERROR == android_bb_getParam(ibb->mBassBoostEffect,
2779cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi            BASSBOOST_PARAM_STRENGTH, &strength)) {
278172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        ibb->mStrength = (SLpermille) strength;
2799cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi    }
2809cd3c9e7a2395647b92c32f33c06cf9fd546b22fJean-Michel Trivi}
2814be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2827e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi
2834be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi//-----------------------------------------------------------------------------
284213c31153b9bda7b5a091f2996da7b655c8ed451Glenn Kastenvoid android_eq_init(audio_session_t sessionId, IEqualizer* ieq) {
285a013b478c73d494afc668909ec52f578f2bc966dJean-Michel Trivi    SL_LOGV("android_eq_init on session %d", sessionId);
2864be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
28700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    if (!android_fx_initEffectObj(sessionId, ieq->mEqEffect, &ieq->mEqDescriptor.type)) {
288f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        SL_LOGE("Equalizer effect initialization failed");
2894be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        return;
2904be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
2914be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
2927e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    // initialize number of bands, band level range, and number of presets
293b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent    uint16_t num = 0;
2947e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect, EQ_PARAM_NUM_BANDS, 0, &num)) {
2957e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi        ieq->mNumBands = num;
2964be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
297b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent    int16_t range[2] = {0, 0};
2987e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect, EQ_PARAM_LEVEL_RANGE, 0, range)) {
2997e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi        ieq->mBandLevelRangeMin = range[0];
3007e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi        ieq->mBandLevelRangeMax = range[1];
3014be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
3024be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
3037e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    SL_LOGV(" EQ init: num bands = %u, band range=[%d %d]mB", num, range[0], range[1]);
3044be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
3057e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    // FIXME don't store presets names, they can be queried each time they're needed
3064be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    // initialize preset number and names, store in IEngine
307b3b757daa7d162b6f66590d917c1f84f3ba73c70Eric Laurent    uint16_t numPresets = 0;
3087e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect,
3094be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi            EQ_PARAM_GET_NUM_OF_PRESETS, 0, &numPresets)) {
3107e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi        ieq->mThis->mEngine->mEqNumPresets = numPresets;
3117e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi        ieq->mNumPresets = numPresets;
3124be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
3137e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi
314b0ab2dee391dd2cb257faeaba252ee6ecccc5f03Glenn Kasten    object_lock_exclusive(&ieq->mThis->mEngine->mObject);
3154be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    char name[EFFECT_STRING_LEN_MAX];
3167e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi    if ((0 < numPresets) && (NULL == ieq->mThis->mEngine->mEqPresetNames)) {
3177e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi        ieq->mThis->mEngine->mEqPresetNames = (char **)new char *[numPresets];
3184be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        for(uint32_t i = 0 ; i < numPresets ; i++) {
3197e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi            if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect,
3204be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi                    EQ_PARAM_GET_PRESET_NAME, i, name)) {
3217e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi                ieq->mThis->mEngine->mEqPresetNames[i] = new char[strlen(name) + 1];
3227e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi                strcpy(ieq->mThis->mEngine->mEqPresetNames[i], name);
3237e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi                SL_LOGV(" EQ init: presets = %u is %s", i, ieq->mThis->mEngine->mEqPresetNames[i]);
3244be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi            }
3254be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        }
3264be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
327b0ab2dee391dd2cb257faeaba252ee6ecccc5f03Glenn Kasten    object_unlock_exclusive(&ieq->mThis->mEngine->mObject);
3287e01bc6208fb5b4a2a0019d67bf74373f8ee9428Jean-Michel Trivi
3294be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi}
3304be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
331f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
332f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
333213c31153b9bda7b5a091f2996da7b655c8ed451Glenn Kastenvoid android_virt_init(audio_session_t sessionId, IVirtualizer* ivi) {
334a013b478c73d494afc668909ec52f578f2bc966dJean-Michel Trivi    SL_LOGV("android_virt_init on session %d", sessionId);
335f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
336172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    if (!android_fx_initEffectObj(sessionId, ivi->mVirtualizerEffect,
33700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi            &ivi->mVirtualizerDescriptor.type)) {
338f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        SL_LOGE("Virtualizer effect initialization failed");
339f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        return;
340f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    }
341f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
342f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    // initialize strength
343f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    int16_t strength;
344172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    if (android::NO_ERROR == android_virt_getParam(ivi->mVirtualizerEffect,
345f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            VIRTUALIZER_PARAM_STRENGTH, &strength)) {
346172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        ivi->mStrength = (SLpermille) strength;
347f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    }
348f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi}
349f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
350f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
3519bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_virt_setParam(const android::sp<android::AudioEffect>& pFx,
352f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        int32_t param, void *pValue) {
353f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
354f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return android_fx_setParam(pFx, param, VIRTUALIZER_PARAM_SIZE_MAX,
355f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            pValue, virt_valueSize(param));
356f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi}
357f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
358f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
3599bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_virt_getParam(const android::sp<android::AudioEffect>& pFx,
360f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        int32_t param, void *pValue) {
361f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
362f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return android_fx_getParam(pFx, param, VIRTUALIZER_PARAM_SIZE_MAX,
363f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            pValue, virt_valueSize(param));
364f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi}
365f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
366172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
367172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi//-----------------------------------------------------------------------------
368172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivivoid android_prev_init(IPresetReverb* ipr) {
369ca39f4b4dbeb920a5b97bd65be73f2f7cac77431Dima Zavin    SL_LOGV("session is implicitly %d (aux effect)", AUDIO_SESSION_OUTPUT_MIX);
370172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
371ca39f4b4dbeb920a5b97bd65be73f2f7cac77431Dima Zavin    if (!android_fx_initEffectObj(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/,
37200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi            ipr->mPresetReverbEffect, &ipr->mPresetReverbDescriptor.type)) {
373172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        SL_LOGE("PresetReverb effect initialization failed");
374172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        return;
375172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    }
376172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
377172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    // initialize preset
378172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    uint16_t preset;
379172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    if (android::NO_ERROR == android_prev_getPreset(ipr->mPresetReverbEffect, &preset)) {
380172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        ipr->mPreset = preset;
381e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten        // enable the effect if it has a preset loaded
38200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi        ipr->mPresetReverbEffect->setEnabled(SL_REVERBPRESET_NONE != preset);
383172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    }
384172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi}
385172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
386172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi//-----------------------------------------------------------------------------
3879bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_prev_setPreset(const android::sp<android::AudioEffect>& pFx, uint16_t preset) {
3884e1412ba1d9e74e51a01d34b1c588166d68e4332Glenn Kasten    android::status_t status = android_fx_setParam(pFx, REVERB_PARAM_PRESET,
3894e1412ba1d9e74e51a01d34b1c588166d68e4332Glenn Kasten            PRESETREVERB_PARAM_SIZE_MAX, &preset, sizeof(uint16_t));
39000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    // enable the effect if the preset is different from SL_REVERBPRESET_NONE
39100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    pFx->setEnabled(SL_REVERBPRESET_NONE != preset);
39200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    return status;
393172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi}
394172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
395172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi//-----------------------------------------------------------------------------
3969bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_prev_getPreset(const android::sp<android::AudioEffect>& pFx, uint16_t* preset) {
3974e1412ba1d9e74e51a01d34b1c588166d68e4332Glenn Kasten    return android_fx_getParam(pFx, REVERB_PARAM_PRESET, PRESETREVERB_PARAM_SIZE_MAX, preset,
398172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi            sizeof(uint16_t));
399172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi}
400172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
401172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
402172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi//-----------------------------------------------------------------------------
403172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivivoid android_erev_init(IEnvironmentalReverb* ier) {
404ca39f4b4dbeb920a5b97bd65be73f2f7cac77431Dima Zavin    SL_LOGV("session is implicitly %d (aux effect)", AUDIO_SESSION_OUTPUT_MIX);
405172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
406ca39f4b4dbeb920a5b97bd65be73f2f7cac77431Dima Zavin    if (!android_fx_initEffectObj(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/,
40700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi            ier->mEnvironmentalReverbEffect, &ier->mEnvironmentalReverbDescriptor.type)) {
408172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        SL_LOGE("EnvironmentalReverb effect initialization failed");
409172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        return;
410172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    }
411172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
41200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    // enable env reverb: other SL ES effects have an explicit SetEnabled() function, and the
41300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    //  preset reverb state depends on the selected preset.
41400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi    ier->mEnvironmentalReverbEffect->setEnabled(true);
41500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi
416172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    // initialize reverb properties
417f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    SLEnvironmentalReverbSettings properties;
418f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    if (android::NO_ERROR == android_erev_getParam(ier->mEnvironmentalReverbEffect,
419f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi            REVERB_PARAM_PROPERTIES, &properties)) {
420f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        ier->mProperties = properties;
421f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    }
422f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi}
423f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
424f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi//-----------------------------------------------------------------------------
4259bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_erev_setParam(const android::sp<android::AudioEffect>& pFx,
426f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        int32_t param, void *pValue) {
427f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
428f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    // given the size difference between a single reverb property and the whole set of reverb
429f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    // properties, select which max size to pass to avoid allocating too much memory
430f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    if (param == REVERB_PARAM_PROPERTIES) {
431f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        return android_fx_setParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_ALL,
432f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi                pValue, erev_valueSize(param));
433f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    } else {
434f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        return android_fx_setParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_SINGLE,
435f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi                pValue, erev_valueSize(param));
436f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    }
437f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi}
438172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
439f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi//-----------------------------------------------------------------------------
4409bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_erev_getParam(const android::sp<android::AudioEffect>& pFx,
441f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        int32_t param, void *pValue) {
442f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi
443f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    // given the size difference between a single reverb property and the whole set of reverb
444f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    // properties, select which max size to pass to avoid allocating too much memory
445f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    if (param == REVERB_PARAM_PROPERTIES) {
446f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        return android_fx_getParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_ALL,
447f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi                pValue, erev_valueSize(param));
448f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    } else {
449f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi        return android_fx_getParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_SINGLE,
450f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi                pValue, erev_valueSize(param));
451f5afeef3bb2aafba9b4e7c25ab3b9dcf42ee8d65Jean-Michel Trivi    }
452172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi}
453172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
454677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent//-----------------------------------------------------------------------------
455677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurentvoid android_aec_init(audio_session_t sessionId, IAndroidAcousticEchoCancellation* iaec) {
456677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    SL_LOGV("android_aec_init on session %d", sessionId);
457677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent
458677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    if (!android_fx_initEffectObj(sessionId, iaec->mAECEffect,
459677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent            &iaec->mAECDescriptor.type)) {
460677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent        SL_LOGE("AEC effect initialization failed");
461677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent        return;
462677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    }
463677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent}
464677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent
465677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent//-----------------------------------------------------------------------------
466677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurentvoid android_agc_init(audio_session_t sessionId, IAndroidAutomaticGainControl* iagc) {
467677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    SL_LOGV("android_agc_init on session %d", sessionId);
468677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent
469677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    if (!android_fx_initEffectObj(sessionId, iagc->mAGCEffect,
470677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent            &iagc->mAGCDescriptor.type)) {
471677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent        SL_LOGE("AGC effect initialization failed");
472677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent        return;
473677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    }
474677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent}
475677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent
476677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent//-----------------------------------------------------------------------------
477677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurentvoid android_ns_init(audio_session_t sessionId, IAndroidNoiseSuppression* ins) {
478677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    SL_LOGV("android_ns_init on session %d", sessionId);
479677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent
480677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    if (!android_fx_initEffectObj(sessionId, ins->mNSEffect,
481677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent            &ins->mNSDescriptor.type)) {
482677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent        SL_LOGE("NS effect initialization failed");
483677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent        return;
484677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent    }
485677c796097b542e9ee6cf43a59e754f43c2370dcEric Laurent}
486172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
487172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi//-----------------------------------------------------------------------------
488e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten/**
489e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten * pre-condition:
490e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *    ap != NULL
491e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *    for media players:
492e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *      ap->mAPlayer != 0
49367213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi *      ap->mTrackPlayer->mAudioTrack == 0
494e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *    for buffer queue players:
495e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *      ap->mAPlayer == 0
49667213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi *      ap->mTrackPlayer->mAudioTrack != 0 is optional; if no track yet then the setting is deferred
497e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten */
498172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Triviandroid::status_t android_fxSend_attach(CAudioPlayer* ap, bool attach,
4999bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsieh        const android::sp<android::AudioEffect>& pFx, SLmillibel sendLevel) {
50000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi
501f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi    if (pFx == 0) {
502172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        return android::INVALID_OPERATION;
503172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    }
504172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
5053610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    // There are 3 cases:
5063610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    //  mAPlayer != 0 && mAudioTrack == 0 means playing decoded audio
5073610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    //  mAPlayer == 0 && mAudioTrack != 0 means playing PCM audio
5083610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    //  mAPlayer == 0 && mAudioTrack == 0 means player not fully configured yet
5093610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    // The asserts document and verify this.
5103610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    if (ap->mAPlayer != 0) {
51167213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi        assert(ap->mTrackPlayer->mAudioTrack == 0);
5123610785fa93586ce84a27a27530feb77b8035229Glenn Kasten        if (attach) {
5133610785fa93586ce84a27a27530feb77b8035229Glenn Kasten            ap->mAPlayer->attachAuxEffect(pFx->id());
5143610785fa93586ce84a27a27530feb77b8035229Glenn Kasten            ap->mAPlayer->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) );
5153610785fa93586ce84a27a27530feb77b8035229Glenn Kasten        } else {
5163610785fa93586ce84a27a27530feb77b8035229Glenn Kasten            ap->mAPlayer->attachAuxEffect(0);
5173610785fa93586ce84a27a27530feb77b8035229Glenn Kasten        }
5183610785fa93586ce84a27a27530feb77b8035229Glenn Kasten        return android::NO_ERROR;
5193610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    }
5203610785fa93586ce84a27a27530feb77b8035229Glenn Kasten
52167213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi    if (ap->mTrackPlayer->mAudioTrack == 0) {
522f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        // the player doesn't have an AudioTrack at the moment, so store this info to use it
523f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        // when the AudioTrack becomes available
524f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        if (attach) {
525f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi            ap->mAuxEffect = pFx;
526f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        } else {
527f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi            ap->mAuxEffect.clear();
528f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        }
529f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        // we keep track of the send level, independently of the current audio player level
530f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        ap->mAuxSendLevel = sendLevel - ap->mVolume.mLevel;
531f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        return android::NO_ERROR;
532f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi    }
533f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi
534172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    if (attach) {
53567213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi        android::status_t status = ap->mTrackPlayer->mAudioTrack->attachAuxEffect(pFx->id());
53600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi        //SL_LOGV("attachAuxEffect(%d) returned %d", pFx->id(), status);
537172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        if (android::NO_ERROR == status) {
538172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi            status =
53967213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi                ap->mTrackPlayer->mAudioTrack->setAuxEffectSendLevel(
54067213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi                        sles_to_android_amplification(sendLevel) );
541172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        }
542172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi        return status;
543172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    } else {
54467213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi        return ap->mTrackPlayer->mAudioTrack->attachAuxEffect(0);
545172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    }
546172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi}
547172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
548172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi//-----------------------------------------------------------------------------
549fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi/**
550fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi * pre-condition:
551fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi *    ap != NULL
552fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi *    ap->mOutputMix != NULL
553fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi */
554fef6033d852daec8d88060b252e72f322724dca1Jean-Michel TriviSLresult android_fxSend_attachToAux(CAudioPlayer* ap, SLInterfaceID pUuid, SLboolean attach,
555fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi        SLmillibel sendLevel) {
556f51dba65751107c930759938775b75531ec1f330Glenn Kasten    COutputMix *outputMix = CAudioPlayer_GetOutputMix(ap);
557f51dba65751107c930759938775b75531ec1f330Glenn Kasten    ssize_t index = outputMix->mAndroidEffect.mEffects->indexOfKey(KEY_FROM_GUID(pUuid));
558fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi
559fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi    if (0 > index) {
560fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi        SL_LOGE("invalid effect ID: no such effect attached to the OutputMix");
561fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
562fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi    }
563fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi
564aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent    android::sp<android::AudioEffect> pFx =
565aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent                          outputMix->mAndroidEffect.mEffects->valueAt(index);
566aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent    if (pFx == 0) {
567fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi        return SL_RESULT_RESOURCE_ERROR;
568fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi    }
569fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi    if (android::NO_ERROR == android_fxSend_attach( ap, (bool) attach, pFx, sendLevel) ) {
570fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi        return SL_RESULT_SUCCESS;
571fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi    } else {
572fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi        return SL_RESULT_RESOURCE_ERROR;
573fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi    }
574fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi
575fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi}
576fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi
577fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi//-----------------------------------------------------------------------------
578e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten/**
579e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten * pre-condition:
580e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *    ap != NULL
581e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *    for media players:
582e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *      ap->mAPlayer != 0
58367213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi *      ap->mTrackPlayer->mAudioTrack == 0
584e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *    for buffer queue players:
585e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten *      ap->mAPlayer == 0
58667213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi *      ap->mTrackPlayer->mAudioTrack != 0 is optional; if no track yet then the setting is deferred
587e2e8fa36bd7448b59fbcdf141e0b6d21e5401d91Glenn Kasten */
588172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Triviandroid::status_t android_fxSend_setSendLevel(CAudioPlayer* ap, SLmillibel sendLevel) {
589f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi    // we keep track of the send level, independently of the current audio player level
590f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi    ap->mAuxSendLevel = sendLevel - ap->mVolume.mLevel;
591f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi
5923610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    if (ap->mAPlayer != 0) {
59367213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi        assert(ap->mTrackPlayer->mAudioTrack == 0);
5943610785fa93586ce84a27a27530feb77b8035229Glenn Kasten        ap->mAPlayer->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) );
5953610785fa93586ce84a27a27530feb77b8035229Glenn Kasten        return android::NO_ERROR;
5963610785fa93586ce84a27a27530feb77b8035229Glenn Kasten    }
5973610785fa93586ce84a27a27530feb77b8035229Glenn Kasten
59867213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi    if (ap->mTrackPlayer->mAudioTrack == 0) {
599f7b852d914faa49d3e4b7d02bb5d9d254762c0b7Jean-Michel Trivi        return android::NO_ERROR;
600172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi    }
601172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
60267213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi    return ap->mTrackPlayer->mAudioTrack->setAuxEffectSendLevel(
60367213e9075e0c51ed39142553facae586295dcaaJean-Michel Trivi            sles_to_android_amplification(sendLevel) );
604172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi}
605172e4da556ad3cb1d2a06cfa019903310aa291d5Jean-Michel Trivi
606f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
6079bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_fx_setParam(const android::sp<android::AudioEffect>& pFx,
608f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        int32_t param, uint32_t paramSizeMax, void *pValue, uint32_t valueSize)
609f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi{
610f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
611f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    android::status_t status;
612f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    uint32_t buf32[(paramSizeMax - 1) / sizeof(uint32_t) + 1];
613f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    effect_param_t *p = (effect_param_t *)buf32;
614f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
615f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    p->psize = sizeof(int32_t);
616f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    *(int32_t *)p->data = param;
617f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    p->vsize = valueSize;
618f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    memcpy(p->data + p->psize, pValue, p->vsize);
619f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    status = pFx->setParameter(p);
620f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    if (android::NO_ERROR == status) {
621f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        status = p->status;
622f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    }
623f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return status;
624f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi}
625f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
626f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
627f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
6289bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_fx_getParam(const android::sp<android::AudioEffect>& pFx,
629f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        int32_t param, uint32_t paramSizeMax, void *pValue, uint32_t valueSize)
630f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi{
631f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    android::status_t status;
632f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    uint32_t buf32[(paramSizeMax - 1) / sizeof(uint32_t) + 1];
633f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    effect_param_t *p = (effect_param_t *)buf32;
634f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
635f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    p->psize = sizeof(int32_t);
636f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    *(int32_t *)p->data = param;
637f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    p->vsize = valueSize;
638f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    status = pFx->getParameter(p);
639f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    if (android::NO_ERROR == status) {
640f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        status = p->status;
641f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        if (android::NO_ERROR == status) {
642f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            memcpy(pValue, p->data + p->psize, p->vsize);
643f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        }
644f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    }
645f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
646f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return status;
647f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi}
648f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
649f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
6504be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi//-----------------------------------------------------------------------------
6514be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel TriviSLresult android_fx_statusToResult(android::status_t status) {
6524be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
6534be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    if ((android::INVALID_OPERATION == status) || (android::DEAD_OBJECT == status)) {
6544be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        return SL_RESULT_CONTROL_LOST;
6554be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    } else {
6564be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi        return SL_RESULT_SUCCESS;
6574be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi    }
6584be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi}
6594be7fe875758b42939719a1082ae9e6dbf37a1d7Jean-Michel Trivi
66067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
66167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
662213c31153b9bda7b5a091f2996da7b655c8ed451Glenn Kastenbool android_fx_initEffectObj(audio_session_t sessionId, android::sp<android::AudioEffect>& effect,
66300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi        const effect_uuid_t *type) {
664a013b478c73d494afc668909ec52f578f2bc966dJean-Michel Trivi    //SL_LOGV("android_fx_initEffectObj on session %d", sessionId);
665f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
6662523b697aa1fda376c2ccd72680394d359acbd3fSvet Ganov    effect = new android::AudioEffect(type, android::String16(), EFFECT_UUID_NULL,
667f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            0,// priority
668f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            0,// effect callback
669f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            0,// callback data
670f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            sessionId,// session ID
671f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi            0 );// output
672f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
673f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    android::status_t status = effect->initCheck();
674f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    if (android::NO_ERROR != status) {
675f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        effect.clear();
676f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        SL_LOGE("Effect initCheck() returned %d", status);
677f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi        return false;
678f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    }
679f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
680f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi    return true;
681f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi}
682f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
683f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi
684f4aebfe499998c11b31319afb1c7738d4801f7b1Jean-Michel Trivi//-----------------------------------------------------------------------------
685f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivibool android_fx_initEffectDescriptor(const SLInterfaceID effectId,
686f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        effect_descriptor_t* fxDescrLoc) {
687f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    uint32_t numEffects = 0;
688f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    effect_descriptor_t descriptor;
689f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    bool foundEffect = false;
690f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi
691f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    // any effects?
692f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    android::status_t res = android::AudioEffect::queryNumberEffects(&numEffects);
693f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    if (android::NO_ERROR != res) {
694f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        SL_LOGE("unable to find any effects.");
695f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        goto effectError;
696f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    }
697f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi
698f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    // request effect in the effects?
699f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    for (uint32_t i=0 ; i < numEffects ; i++) {
700f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        res = android::AudioEffect::queryEffect(i, &descriptor);
701f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        if ((android::NO_ERROR == res) &&
702f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi                (0 == memcmp(effectId, &descriptor.type, sizeof(effect_uuid_t)))) {
703f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi            SL_LOGV("found effect %d %s", i, descriptor.name);
704f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi            foundEffect = true;
705f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi            break;
706f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        }
707f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    }
708f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    if (foundEffect) {
709f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        memcpy(fxDescrLoc, &descriptor, sizeof(effect_descriptor_t));
710f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    } else {
711f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        SL_LOGE("unable to find an implementation for the requested effect.");
712f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi        goto effectError;
713f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    }
714f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi
715f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    return true;
716f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi
717f5fce95f98037ea4ab341b416c82444af595313dJean-Michel TrivieffectError:
718f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    // the requested effect wasn't found
719f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    memset(fxDescrLoc, 0, sizeof(effect_descriptor_t));
720f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi
721f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi    return false;
722f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi}
723f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi
724f5fce95f98037ea4ab341b416c82444af595313dJean-Michel Trivi//-----------------------------------------------------------------------------
72567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel TriviSLresult android_genericFx_queryNumEffects(SLuint32 *pNumSupportedAudioEffects) {
72667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
72767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    if (NULL == pNumSupportedAudioEffects) {
72867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
72967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
73067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
73167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    android::status_t status =
73267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            android::AudioEffect::queryNumberEffects((uint32_t*)pNumSupportedAudioEffects);
73367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
73467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
735ac28eca1df49f581d952ffbda5d3019f7e3b7be6Glenn Kasten    switch (status) {
73667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::NO_ERROR:
73767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_SUCCESS;
73867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
73967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::PERMISSION_DENIED:
74067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_PERMISSION_DENIED;
74167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
74267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::NO_INIT:
74367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_RESOURCE_ERROR;
74467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
74567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::BAD_VALUE:
74667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_PARAMETER_INVALID;
74767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
74867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        default:
74967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_INTERNAL_ERROR;
75067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            SL_LOGE("received invalid status %d from AudioEffect::queryNumberEffects()", status);
75167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
75267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
75367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    return result;
75467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
75567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
75667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
75767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
7585b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel TriviSLresult android_genericFx_queryEffect(SLuint32 index, effect_descriptor_t* pDescriptor) {
75967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
7605b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    if (NULL == pDescriptor) {
76167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
76267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
76367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
76467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    android::status_t status =
7655b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                android::AudioEffect::queryEffect(index, pDescriptor);
76667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
76767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
7685b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    if (android::NO_ERROR != status) {
769ac28eca1df49f581d952ffbda5d3019f7e3b7be6Glenn Kasten        switch (status) {
77067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::PERMISSION_DENIED:
77167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_PERMISSION_DENIED;
77267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
77367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::NO_INIT:
77467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::INVALID_OPERATION:
77567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_RESOURCE_ERROR;
77667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
77767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        case android::BAD_VALUE:
77867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_PARAMETER_INVALID;
77967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
78067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        default:
78167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            result = SL_RESULT_INTERNAL_ERROR;
78267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            SL_LOGE("received invalid status %d from AudioEffect::queryNumberEffects()", status);
78367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            break;
7845b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        }
7855b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        // an error occurred, reset the effect descriptor
7865b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        memset(pDescriptor, 0, sizeof(effect_descriptor_t));
78767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
7885b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi
78967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    return result;
79067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
79167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
79267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
79367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
794213c31153b9bda7b5a091f2996da7b655c8ed451Glenn KastenSLresult android_genericFx_createEffect(IAndroidEffect* iae, SLInterfaceID pUuid,
795213c31153b9bda7b5a091f2996da7b655c8ed451Glenn Kasten        audio_session_t sessionId)
796213c31153b9bda7b5a091f2996da7b655c8ed451Glenn Kasten{
79767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
79867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
79967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
8005b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    // does this effect already exist?
801ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent    if (0 <= iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid))) {
8025b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        return result;
8035b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    }
8045b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi
8055b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    // create new effect
806aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent    android::sp<android::AudioEffect> pFx = new android::AudioEffect(
80767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            NULL, // not using type to create effect
8082523b697aa1fda376c2ccd72680394d359acbd3fSvet Ganov            android::String16(),
80967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            (const effect_uuid_t*)pUuid,
81067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            0,// priority
81167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            0,// effect callback
81267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            0,// callback data
81367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            sessionId,
81467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi            0 );// output
81567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
8165b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    // verify effect was successfully created before storing it
8175b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    android::status_t status = pFx->initCheck();
81867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    if (android::NO_ERROR != status) {
8195b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        SL_LOGE("AudioEffect initCheck() returned %d, effect will not be stored", status);
82067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        result = SL_RESULT_RESOURCE_ERROR;
8215b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    } else {
8225b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        SL_LOGV("AudioEffect successfully created on session %d", sessionId);
823ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent        iae->mEffects->add(KEY_FROM_GUID(pUuid), pFx);
82467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
82567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
82667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    return result;
82767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
82867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
82967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
83067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
8315b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel TriviSLresult android_genericFx_releaseEffect(IAndroidEffect* iae, SLInterfaceID pUuid) {
83267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
833ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent    ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid));
8345b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi
8355b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    if (0 > index) {
83667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
8375b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    } else {
838ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent        iae->mEffects->removeItem(index);
8395b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        return SL_RESULT_SUCCESS;
84067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
84167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
84267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
84367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
84467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
8455b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel TriviSLresult android_genericFx_setEnabled(IAndroidEffect* iae, SLInterfaceID pUuid, SLboolean enabled) {
8465b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi
847ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent    ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid));
84867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
8495b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    if (0 > index) {
85067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
8515b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    } else {
852aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent        android::sp<android::AudioEffect> pFx = iae->mEffects->valueAt(index);
8535b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        android::status_t status = pFx->setEnabled(SL_BOOLEAN_TRUE == enabled);
8545b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        return android_fx_statusToResult(status);
85567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
85667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
85767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
85867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
85967bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
8605b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel TriviSLresult android_genericFx_isEnabled(IAndroidEffect* iae, SLInterfaceID pUuid, SLboolean *pEnabled)
8615b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi{
862ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent    ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid));
86367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
8645b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    if (0 > index) {
86567bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
8665b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    } else {
867aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent        android::sp<android::AudioEffect> pFx = iae->mEffects->valueAt(index);
8685b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        *pEnabled = (SLboolean) pFx->getEnabled();
8695b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        return SL_RESULT_SUCCESS;
87067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
87167bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
87267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
87367bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
87467bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi//-----------------------------------------------------------------------------
8755b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel TriviSLresult android_genericFx_sendCommand(IAndroidEffect* iae, SLInterfaceID pUuid,
8765b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        SLuint32 command, SLuint32 commandSize, void* pCommandData,
8775b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        SLuint32 *replySize, void *pReplyData) {
87867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
879ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent    ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid));
88067bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
8815b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    if (0 > index) {
88267bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
8835b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi    } else {
884aa08cb01d58f1da2d0a2b208aed3bf1730f8f63dEric Laurent        android::sp<android::AudioEffect> pFx = iae->mEffects->valueAt(index);
8855b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        android::status_t status = pFx->command(
8865b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                (uint32_t) command,
8875b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                (uint32_t) commandSize,
8885b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                pCommandData,
8895b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                (uint32_t*)replySize,
8905b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                pReplyData);
8915b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        if (android::BAD_VALUE == status) {
8925b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi                return SL_RESULT_PARAMETER_INVALID;
8935b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        } else {
8945b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi            return SL_RESULT_SUCCESS;
8955b09aa864215690580b18eb802927e8cc7eb4861Jean-Michel Trivi        }
89667bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi    }
89767bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi}
89867bdf8a2fbd1024ab50c4513e1504325475368e0Jean-Michel Trivi
899fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi//-----------------------------------------------------------------------------
900fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi/**
901fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi * returns true if the given effect id is present in the AndroidEffect interface
902fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi */
903fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivibool android_genericFx_hasEffect(IAndroidEffect* iae, SLInterfaceID pUuid) {
904ca533f4e1c67e9136044f25ca84b65102c8892fdEric Laurent    return( 0 <= iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid)));
905fef6033d852daec8d88060b252e72f322724dca1Jean-Michel Trivi}
906f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
907f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean//-----------------------------------------------------------------------------
908f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLeanstatic const int AEC_PARAM_SIZE_MAX = sizeof(effect_param_t) + (2 * sizeof(int32_t));
909f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean/**
910f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean * returns the size in bytes of the value of each acoustic echo cancellation parameter
911f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean */
912f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLeanuint32_t aec_valueSize(int32_t param) {
913f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    uint32_t size;
914f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    switch (param) {
915f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    case AEC_PARAM_ECHO_DELAY:
916f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(int32_t);
917f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
918f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    default:
919f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(int32_t);
920f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        SL_LOGE("Trying to access an unknown Acoustic Echo Cancellation parameter %d", param);
921f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
922f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    }
923f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
924f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return size;
925f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
926f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
9279bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_aec_setParam(const android::sp<android::AudioEffect>& pFx,
928f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        int32_t param, void *pValue) {
929f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return android_fx_setParam(pFx, param, AEC_PARAM_SIZE_MAX,
930f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean            pValue, aec_valueSize(param));
931f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
932f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
9339bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_aec_getParam(const android::sp<android::AudioEffect>& pFx,
934f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        int32_t param, void *pValue) {
935f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return android_fx_getParam(pFx, param, AEC_PARAM_SIZE_MAX,
936f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean            pValue, aec_valueSize(param));
937f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
938f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
939f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean//-----------------------------------------------------------------------------
940f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLeanstatic const int AGC_PARAM_SIZE_MAX = sizeof(effect_param_t) + (2 * sizeof(int16_t)) + sizeof(bool);
941f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean/**
942f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean * returns the size in bytes of the value of each automatic gain control parameter
943f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean */
944f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLeanuint32_t agc_valueSize(int32_t param) {
945f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    uint32_t size;
946f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    switch (param) {
947f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    case AGC_PARAM_TARGET_LEVEL:
948f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    case AGC_PARAM_COMP_GAIN:
949f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(int16_t);
950f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
951f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    case AGC_PARAM_LIMITER_ENA:
952f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(bool);
953f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
954f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    default:
955f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(int32_t);
956f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        SL_LOGE("Trying to access an unknown Automatic Gain Control parameter %d", param);
957f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
958f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    }
959f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
960f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return size;
961f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
962f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
9639bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_agc_setParam(const android::sp<android::AudioEffect>& pFx,
964f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        int32_t param, void *pValue) {
965f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return android_fx_setParam(pFx, param, AGC_PARAM_SIZE_MAX,
966f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean            pValue, agc_valueSize(param));
967f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
968f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
9699bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_agc_getParam(const android::sp<android::AudioEffect>& pFx,
970f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        int32_t param, void *pValue) {
971f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return android_fx_getParam(pFx, param, AGC_PARAM_SIZE_MAX,
972f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean            pValue, agc_valueSize(param));
973f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
974f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
975f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean//-----------------------------------------------------------------------------
976759687c36cbeaaa40408960eafa3ffd14e76cbc6Ji-Hwan Leestatic const int NS_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t);
977f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean/**
978f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean * returns the size in bytes of the value of each noise suppression parameter
979f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean */
980f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLeanuint32_t ns_valueSize(int32_t param) {
981f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    uint32_t size;
982f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    switch (param) {
983f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    case NS_PARAM_LEVEL:
984f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(int32_t);
985f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
986f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    default:
987f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        size = sizeof(int32_t);
988f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        SL_LOGE("Trying to access an unknown Noise suppression parameter %d", param);
989f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        break;
990f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    }
991f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
992f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return size;
993f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
994f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
9959bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_ns_setParam(const android::sp<android::AudioEffect>& pFx,
996f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        int32_t param, void *pValue)
997f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean{
998f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return android_fx_setParam(pFx, param, NS_PARAM_SIZE_MAX,
999f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean            pValue, ns_valueSize(param));
1000f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
1001f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean
10029bf773df2b8a0cf788f394c326960bc3a5af7c60Chih-Hung Hsiehandroid::status_t android_ns_getParam(const android::sp<android::AudioEffect>& pFx,
1003f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean        int32_t param, void *pValue)
1004f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean{
1005f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean    return android_fx_getParam(pFx, param, NS_PARAM_SIZE_MAX,
1006f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean            pValue, ns_valueSize(param));
1007f8b3141926967ba37d315cc8d3956d7214958e6bPaul McLean}
1008