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 #ifndef ANDROID_EFFECTBUNDLE_H_ 18 #define ANDROID_EFFECTBUNDLE_H_ 19 20 #include <audio_effects/effect_bassboost.h> 21 #include <audio_effects/effect_equalizer.h> 22 #include <audio_effects/effect_virtualizer.h> 23 #include <LVM.h> 24 #include <limits.h> 25 26 #define FIVEBAND_NUMBANDS 5 27 #define MAX_NUM_BANDS 5 28 #define MAX_CALL_SIZE 256 29 #define LVM_MAX_SESSIONS 32 30 #define LVM_UNUSED_SESSION INT_MAX 31 #define BASS_BOOST_CUP_LOAD_ARM9E 150 // Expressed in 0.1 MIPS 32 #define VIRTUALIZER_CUP_LOAD_ARM9E 120 // Expressed in 0.1 MIPS 33 #define EQUALIZER_CUP_LOAD_ARM9E 220 // Expressed in 0.1 MIPS 34 #define VOLUME_CUP_LOAD_ARM9E 0 // Expressed in 0.1 MIPS 35 #define BUNDLE_MEM_USAGE 25 // Expressed in kB 36 37 #ifndef OPENSL_ES_H_ 38 static const effect_uuid_t SL_IID_VOLUME_ = { 39 0x09e8ede0, 0xddde, 0x11db, 0xb4f6, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}; 40 const effect_uuid_t* const SL_IID_VOLUME = &SL_IID_VOLUME_; 41 #endif // OPENSL_ES_H_ 42 43 typedef enum { LVM_BASS_BOOST, LVM_VIRTUALIZER, LVM_EQUALIZER, LVM_VOLUME } lvm_effect_en; 44 45 // Preset configuration. 46 struct PresetConfig { 47 // Human-readable name. 48 const char* name; 49 // An array of size nBands where each element is a configuration for the 50 // corresponding band. 51 // const BandConfig * bandConfigs; 52 }; 53 54 /* BundledEffectContext : One per session */ 55 struct BundledEffectContext { 56 LVM_Handle_t hInstance; /* Instance handle */ 57 int SessionNo; /* Current session number */ 58 int SessionId; /* Current session id */ 59 bool bVolumeEnabled; /* Flag for Volume */ 60 bool bEqualizerEnabled; /* Flag for EQ */ 61 bool bBassEnabled; /* Flag for Bass */ 62 bool bBassTempDisabled; /* Flag for Bass to be re-enabled */ 63 bool bVirtualizerEnabled; /* Flag for Virtualizer */ 64 bool bVirtualizerTempDisabled; /* Flag for effect to be re-enabled */ 65 audio_devices_t nOutputDevice; /* Output device for the effect */ 66 audio_devices_t nVirtualizerForcedDevice; /* Forced device virtualization mode*/ 67 int NumberEffectsEnabled; /* Effects in this session */ 68 int NumberEffectsCalled; /* Effects called so far */ 69 bool firstVolume; /* No smoothing on first Vol change */ 70 // Saved parameters for each effect */ 71 // Bass Boost 72 int BassStrengthSaved; /* Conversion between Get/Set */ 73 // Equalizer 74 int CurPreset; /* Current preset being used */ 75 // Virtualzer 76 int VirtStrengthSaved; /* Conversion between Get/Set */ 77 // Volume 78 int levelSaved; /* for when mute is set, level must be saved */ 79 int positionSaved; 80 bool bMuteEnabled; /* Must store as mute = -96dB level */ 81 bool bStereoPositionEnabled; 82 LVM_Fs_en SampleRate; 83 int SamplesPerSecond; 84 int SamplesToExitCountEq; 85 int SamplesToExitCountBb; 86 int SamplesToExitCountVirt; 87 effect_buffer_t* workBuffer; 88 int frameCount; 89 int32_t bandGaindB[FIVEBAND_NUMBANDS]; 90 int volume; 91 LVM_INT32 ChMask; 92 93 /* Bitmask whether drain is in progress due to disabling the effect. 94 The corresponding bit to an effect is set by 1 << lvm_effect_en. */ 95 int effectInDrain; 96 97 /* Bitmask whether process() was called for a particular effect. 98 The corresponding bit to an effect is set by 1 << lvm_effect_en. */ 99 int effectProcessCalled; 100 }; 101 102 /* SessionContext : One session */ 103 struct SessionContext { 104 bool bBundledEffectsEnabled; 105 bool bVolumeInstantiated; 106 bool bEqualizerInstantiated; 107 bool bBassInstantiated; 108 bool bVirtualizerInstantiated; 109 BundledEffectContext* pBundledContext; 110 }; 111 112 struct EffectContext { 113 const struct effect_interface_s* itfe; 114 effect_config_t config; 115 lvm_effect_en EffectType; 116 BundledEffectContext* pBundledContext; 117 }; 118 119 /* enumerated parameter settings for Volume effect */ 120 typedef enum { 121 VOLUME_PARAM_LEVEL, // type SLmillibel = typedef SLuint16 (set & get) 122 VOLUME_PARAM_MAXLEVEL, // type SLmillibel = typedef SLuint16 (get) 123 VOLUME_PARAM_MUTE, // type SLboolean = typedef SLuint32 (set & get) 124 VOLUME_PARAM_ENABLESTEREOPOSITION, // type SLboolean = typedef SLuint32 (set & get) 125 VOLUME_PARAM_STEREOPOSITION, // type SLpermille = typedef SLuint16 (set & get) 126 } t_volume_params; 127 128 static const int PRESET_CUSTOM = -1; 129 130 static const uint32_t bandFreqRange[FIVEBAND_NUMBANDS][2] = {{30000, 120000}, 131 {120001, 460000}, 132 {460001, 1800000}, 133 {1800001, 7000000}, 134 {7000001, 20000000}}; 135 136 // Note: If these frequencies change, please update LimitLevel values accordingly. 137 static const LVM_UINT16 EQNB_5BandPresetsFrequencies[] = {60, /* Frequencies in Hz */ 138 230, 910, 3600, 14000}; 139 140 static const LVM_UINT16 EQNB_5BandPresetsQFactors[] = {96, /* Q factor multiplied by 100 */ 141 96, 96, 96, 96}; 142 143 static const LVM_INT16 EQNB_5BandNormalPresets[] = {3, 0, 0, 0, 3, /* Normal Preset */ 144 8, 5, -3, 5, 6, /* Classical Preset */ 145 15, -6, 7, 13, 10, /* Dance Preset */ 146 0, 0, 0, 0, 0, /* Flat Preset */ 147 6, -2, -2, 6, -3, /* Folk Preset */ 148 8, -8, 13, -1, -4, /* Heavy Metal Preset */ 149 10, 6, -4, 5, 8, /* Hip Hop Preset */ 150 8, 5, -4, 5, 9, /* Jazz Preset */ 151 -6, 4, 9, 4, -5, /* Pop Preset */ 152 10, 6, -1, 8, 10}; /* Rock Preset */ 153 154 static const LVM_INT16 EQNB_5BandSoftPresets[] = {3, 0, 0, 0, 3, /* Normal Preset */ 155 5, 3, -2, 4, 4, /* Classical Preset */ 156 6, 0, 2, 4, 1, /* Dance Preset */ 157 0, 0, 0, 0, 0, /* Flat Preset */ 158 3, 0, 0, 2, -1, /* Folk Preset */ 159 4, 1, 9, 3, 0, /* Heavy Metal Preset */ 160 5, 3, 0, 1, 3, /* Hip Hop Preset */ 161 4, 2, -2, 2, 5, /* Jazz Preset */ 162 -1, 2, 5, 1, -2, /* Pop Preset */ 163 5, 3, -1, 3, 5}; /* Rock Preset */ 164 165 static const PresetConfig gEqualizerPresets[] = {{"Normal"}, {"Classical"}, {"Dance"}, {"Flat"}, 166 {"Folk"}, {"Heavy Metal"}, {"Hip Hop"}, {"Jazz"}, 167 {"Pop"}, {"Rock"}}; 168 169 /* The following tables have been computed using the actual levels measured by the output of 170 * white noise or pink noise (IEC268-1) for the EQ and BassBoost Effects. These are estimates of 171 * the actual energy that 'could' be present in the given band. 172 * If the frequency values in EQNB_5BandPresetsFrequencies change, these values might need to be 173 * updated. 174 */ 175 176 static const float LimitLevel_bandEnergyCoefficient[FIVEBAND_NUMBANDS] = {7.56, 9.69, 9.59, 7.37, 177 2.88}; 178 179 static const float LimitLevel_bandEnergyCrossCoefficient[FIVEBAND_NUMBANDS - 1] = {126.0, 115.0, 180 125.0, 104.0}; 181 182 static const float LimitLevel_bassBoostEnergyCrossCoefficient[FIVEBAND_NUMBANDS] = { 183 221.21, 208.10, 28.16, 0.0, 0.0}; 184 185 static const float LimitLevel_bassBoostEnergyCoefficient = 9.00; 186 187 static const float LimitLevel_virtualizerContribution = 1.9; 188 189 #endif /*ANDROID_EFFECTBUNDLE_H_*/ 190