Home | History | Annotate | Download | only in libopensles
      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) && !defined(USE_BACKPORT)
     22 /**
     23  * returns true if this interface is not associated with an initialized PresetReverb effect
     24  */
     25 static inline bool NO_PRESETREVERB(IPresetReverb* ipr) {
     26     return (ipr->mPresetReverbEffect == 0);
     27 }
     28 #endif
     29 
     30 static SLresult IPresetReverb_SetPreset(SLPresetReverbItf self, SLuint16 preset)
     31 {
     32     SL_ENTER_INTERFACE
     33 
     34     IPresetReverb *this = (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_poke(this);
     44         this->mPreset = preset;
     45 #if !defined(ANDROID) || defined(USE_BACKPORT)
     46         result = SL_RESULT_SUCCESS;
     47 #else
     48         if (NO_PRESETREVERB(this)) {
     49             result = SL_RESULT_CONTROL_LOST;
     50         } else {
     51             android::status_t status = android_prev_setPreset(this->mPresetReverbEffect, preset);
     52             result = android_fx_statusToResult(status);
     53         }
     54 #endif
     55         interface_unlock_poke(this);
     56         break;
     57     default:
     58         result = SL_RESULT_PARAMETER_INVALID;
     59         break;
     60     }
     61 
     62     SL_LEAVE_INTERFACE
     63 }
     64 
     65 static 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 *this = (IPresetReverb *) self;
     73         interface_lock_peek(this);
     74         SLuint16 preset = SL_REVERBPRESET_NONE;
     75 #if !defined(ANDROID) || defined(USE_BACKPORT)
     76         preset = this->mPreset;
     77         result = SL_RESULT_SUCCESS;
     78 #else
     79         if (NO_PRESETREVERB(this)) {
     80             result = SL_RESULT_CONTROL_LOST;
     81         } else {
     82             android::status_t status = android_prev_getPreset(this->mPresetReverbEffect, &preset);
     83             result = android_fx_statusToResult(status);
     84         }
     85 #endif
     86         interface_unlock_peek(this);
     87         *pPreset = preset;
     88     }
     89 
     90     SL_LEAVE_INTERFACE
     91 }
     92 
     93 static const struct SLPresetReverbItf_ IPresetReverb_Itf = {
     94     IPresetReverb_SetPreset,
     95     IPresetReverb_GetPreset
     96 };
     97 
     98 void IPresetReverb_init(void *self)
     99 {
    100     IPresetReverb *this = (IPresetReverb *) self;
    101     this->mItf = &IPresetReverb_Itf;
    102     this->mPreset = SL_REVERBPRESET_NONE;
    103 #if defined(ANDROID) && !defined(USE_BACKPORT)
    104     memset(&this->mPresetReverbDescriptor, 0, sizeof(effect_descriptor_t));
    105     // placement new (explicit constructor)
    106     (void) new (&this->mPresetReverbEffect) android::sp<android::AudioEffect>();
    107 #endif
    108 }
    109 
    110 void IPresetReverb_deinit(void *self)
    111 {
    112 #if defined(ANDROID) && !defined(USE_BACKPORT)
    113     IPresetReverb *this = (IPresetReverb *) self;
    114     // explicit destructor
    115     this->mPresetReverbEffect.~sp();
    116 #endif
    117 }
    118 
    119 bool IPresetReverb_Expose(void *self)
    120 {
    121 #if defined(ANDROID) && !defined(USE_BACKPORT)
    122     IPresetReverb *this = (IPresetReverb *) self;
    123     if (!android_fx_initEffectDescriptor(SL_IID_PRESETREVERB, &this->mPresetReverbDescriptor)) {
    124         SL_LOGE("PresetReverb initialization failed.");
    125         return false;
    126     }
    127 #endif
    128     return true;
    129 }
    130