IPresetReverb.c revision b566926611b2105a46c4ff98238ad06aca54104d
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17/* PresetReverb implementation */ 18 19#include "sles_allinclusive.h" 20 21#if defined(ANDROID) 22/** 23 * returns true if this interface is not associated with an initialized PresetReverb effect 24 */ 25static inline bool NO_PRESETREVERB(IPresetReverb* ipr) { 26 return (ipr->mPresetReverbEffect == 0); 27} 28#endif 29 30static SLresult IPresetReverb_SetPreset(SLPresetReverbItf self, SLuint16 preset) 31{ 32 SL_ENTER_INTERFACE 33 34 IPresetReverb *thiz = (IPresetReverb *) self; 35 switch (preset) { 36 case SL_REVERBPRESET_NONE: 37 case SL_REVERBPRESET_SMALLROOM: 38 case SL_REVERBPRESET_MEDIUMROOM: 39 case SL_REVERBPRESET_LARGEROOM: 40 case SL_REVERBPRESET_MEDIUMHALL: 41 case SL_REVERBPRESET_LARGEHALL: 42 case SL_REVERBPRESET_PLATE: 43 interface_lock_exclusive(thiz); 44 thiz->mPreset = preset; 45#if !defined(ANDROID) 46 result = SL_RESULT_SUCCESS; 47#else 48 if (NO_PRESETREVERB(thiz)) { 49 result = SL_RESULT_CONTROL_LOST; 50 } else { 51 android::status_t status = android_prev_setPreset(thiz->mPresetReverbEffect, preset); 52 result = android_fx_statusToResult(status); 53 } 54#endif 55 interface_unlock_exclusive(thiz); 56 break; 57 default: 58 result = SL_RESULT_PARAMETER_INVALID; 59 break; 60 } 61 62 SL_LEAVE_INTERFACE 63} 64 65static SLresult IPresetReverb_GetPreset(SLPresetReverbItf self, SLuint16 *pPreset) 66{ 67 SL_ENTER_INTERFACE 68 69 if (NULL == pPreset) { 70 result = SL_RESULT_PARAMETER_INVALID; 71 } else { 72 IPresetReverb *thiz = (IPresetReverb *) self; 73 interface_lock_shared(thiz); 74 SLuint16 preset = SL_REVERBPRESET_NONE; 75#if !defined(ANDROID) 76 preset = thiz->mPreset; 77 result = SL_RESULT_SUCCESS; 78#else 79 if (NO_PRESETREVERB(thiz)) { 80 result = SL_RESULT_CONTROL_LOST; 81 } else { 82 android::status_t status = android_prev_getPreset(thiz->mPresetReverbEffect, &preset); 83 result = android_fx_statusToResult(status); 84 } 85#endif 86 interface_unlock_shared(thiz); 87 *pPreset = preset; 88 } 89 90 SL_LEAVE_INTERFACE 91} 92 93static const struct SLPresetReverbItf_ IPresetReverb_Itf = { 94 IPresetReverb_SetPreset, 95 IPresetReverb_GetPreset 96}; 97 98void IPresetReverb_init(void *self) 99{ 100 IPresetReverb *thiz = (IPresetReverb *) self; 101 thiz->mItf = &IPresetReverb_Itf; 102 thiz->mPreset = SL_REVERBPRESET_NONE; 103#if defined(ANDROID) 104 memset(&thiz->mPresetReverbDescriptor, 0, sizeof(effect_descriptor_t)); 105 // placement new (explicit constructor) 106 (void) new (&thiz->mPresetReverbEffect) android::sp<android::AudioEffect>(); 107#endif 108} 109 110void IPresetReverb_deinit(void *self) 111{ 112#if defined(ANDROID) 113 IPresetReverb *thiz = (IPresetReverb *) self; 114 // explicit destructor 115 thiz->mPresetReverbEffect.~sp(); 116#endif 117} 118 119bool IPresetReverb_Expose(void *self) 120{ 121#if defined(ANDROID) 122 IPresetReverb *thiz = (IPresetReverb *) self; 123 if (!android_fx_initEffectDescriptor(SL_IID_PRESETREVERB, &thiz->mPresetReverbDescriptor)) { 124 SL_LOGE("PresetReverb initialization failed."); 125 return false; 126 } 127#endif 128 return true; 129} 130