1 /* 2 * Copyright (C) 2004-2010 NXP Software 3 * Copyright (C) 2010 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /************************************************************************************/ 19 /* */ 20 /* Header file for the private layer interface of concert sound bundle */ 21 /* */ 22 /* This files includes all definitions, types, structures and function */ 23 /* prototypes required by the execution layer. */ 24 /* */ 25 /************************************************************************************/ 26 27 #ifndef __LVM_PRIVATE_H__ 28 #define __LVM_PRIVATE_H__ 29 30 /************************************************************************************/ 31 /* */ 32 /* Includes */ 33 /* */ 34 /************************************************************************************/ 35 36 #include <audio_utils/BiquadFilter.h> 37 #include "LVM.h" /* LifeVibes */ 38 #include "LVM_Common.h" /* LifeVibes common */ 39 #include "BIQUAD.h" /* Biquad library */ 40 #include "LVC_Mixer.h" /* Mixer library */ 41 #include "LVCS_Private.h" /* Concert Sound */ 42 #include "LVDBE_Private.h" /* Dynamic Bass Enhancement */ 43 #include "LVEQNB_Private.h" /* N-Band equaliser */ 44 #include "LVPSA_Private.h" /* Parametric Spectrum Analyzer */ 45 46 /************************************************************************************/ 47 /* */ 48 /* Defines */ 49 /* */ 50 /************************************************************************************/ 51 52 /* General */ 53 #define LVM_INVALID 0xFFFF /* Invalid init parameter */ 54 55 /* Memory */ 56 #define LVM_INSTANCE_ALIGN 4 /* 32-bit for structures */ 57 #define LVM_FIRSTCALL 0 /* First call to the buffer */ 58 #define LVM_MAXBLOCKCALL 1 /* Maximum block size calls to the buffer */ 59 #define LVM_LASTCALL 2 /* Last call to the buffer */ 60 #define LVM_FIRSTLASTCALL 3 /* Single call for small number of samples */ 61 62 /* Block Size */ 63 #define LVM_MIN_MAXBLOCKSIZE 16 /* Minimum MaxBlockSize Limit*/ 64 #define LVM_MANAGED_MAX_MAXBLOCKSIZE 8191 /* Maximum MaxBlockSzie Limit for Managed Buffer Mode*/ 65 #define LVM_UNMANAGED_MAX_MAXBLOCKSIZE \ 66 4096 /* Maximum MaxBlockSzie Limit for Unmanaged Buffer Mode */ 67 68 #define MAX_INTERNAL_BLOCKSIZE 8128 /* Maximum multiple of 64 below 8191*/ 69 70 #define MIN_INTERNAL_BLOCKSIZE 16 /* Minimum internal block size */ 71 #define MIN_INTERNAL_BLOCKSHIFT 4 /* Minimum internal block size as a power of 2 */ 72 #define MIN_INTERNAL_BLOCKMASK 0xFFF0 /* Minimum internal block size mask */ 73 74 #define LVM_PSA_DYNAMICRANGE 60 /* Spectral Dynamic range: used for offseting output*/ 75 #define LVM_PSA_BARHEIGHT 127 /* Spectral Bar Height*/ 76 77 #define LVM_TE_MIN_EFFECTLEVEL 0 /*TE Minimum EffectLevel*/ 78 #define LVM_TE_MAX_EFFECTLEVEL 15 /*TE Maximum Effect level*/ 79 80 #define LVM_VC_MIN_EFFECTLEVEL (-96) /*VC Minimum EffectLevel*/ 81 #define LVM_VC_MAX_EFFECTLEVEL 0 /*VC Maximum Effect level*/ 82 83 #define LVM_BE_MIN_EFFECTLEVEL 0 /*BE Minimum EffectLevel*/ 84 #define LVM_BE_MAX_EFFECTLEVEL 15 /*BE Maximum Effect level*/ 85 86 #define LVM_EQNB_MIN_BAND_FREQ 20 /*EQNB Minimum Band Frequency*/ 87 #define LVM_EQNB_MAX_BAND_FREQ 24000 /*EQNB Maximum Band Frequency*/ 88 #define LVM_EQNB_MIN_BAND_GAIN (-15) /*EQNB Minimum Band Frequency*/ 89 #define LVM_EQNB_MAX_BAND_GAIN 15 /*EQNB Maximum Band Frequency*/ 90 #define LVM_EQNB_MIN_QFACTOR 25 /*EQNB Minimum Q Factor*/ 91 #define LVM_EQNB_MAX_QFACTOR 1200 /*EQNB Maximum Q Factor*/ 92 #define LVM_EQNB_MIN_LPF_FREQ 1000 /*EQNB Minimum Low Pass Corner frequency*/ 93 #define LVM_EQNB_MIN_HPF_FREQ 20 /*EQNB Minimum High Pass Corner frequency*/ 94 #define LVM_EQNB_MAX_HPF_FREQ 1000 /*EQNB Maximum High Pass Corner frequency*/ 95 96 #define LVM_CS_MIN_EFFECT_LEVEL 0 /*CS Minimum Effect Level*/ 97 #define LVM_CS_MAX_REVERB_LEVEL 100 /*CS Maximum Reverb Level*/ 98 #define LVM_VIRTUALIZER_MAX_REVERB_LEVEL 100 /*Vitrualizer Maximum Reverb Level*/ 99 100 #define LVM_VC_MIXER_TIME 100 /*VC mixer time*/ 101 #define LVM_VC_BALANCE_MAX 96 /*VC balance max value*/ 102 #define LVM_VC_BALANCE_MIN (-96) /*VC balance min value*/ 103 104 /* Algorithm masks */ 105 #define LVM_CS_MASK 1 106 #define LVM_EQNB_MASK 2 107 #define LVM_DBE_MASK 4 108 #define LVM_VC_MASK 16 109 #define LVM_TE_MASK 32 110 #define LVM_PSA_MASK 2048 111 112 /************************************************************************************/ 113 /* */ 114 /* Structures */ 115 /* */ 116 /************************************************************************************/ 117 118 /* Buffer Management */ 119 typedef struct { 120 LVM_FLOAT* pScratch; /* Bundle scratch buffer */ 121 122 LVM_INT16 BufferState; /* Buffer status */ 123 LVM_FLOAT InDelayBuffer[3 * LVM_MAX_CHANNELS * MIN_INTERNAL_BLOCKSIZE]; 124 LVM_INT16 InDelaySamples; /* Number of samples in the input delay buffer */ 125 LVM_FLOAT OutDelayBuffer[LVM_MAX_CHANNELS * MIN_INTERNAL_BLOCKSIZE]; 126 LVM_INT16 OutDelaySamples; /* Number of samples in the output delay buffer, \ 127 left and right */ 128 LVM_INT16 SamplesToOutput; /* Samples to write to the output */ 129 } LVM_Buffer_t; 130 131 132 typedef struct { 133 /* Public parameters */ 134 LVM_ControlParams_t Params; /* Control parameters */ 135 LVM_InstParams_t InstParams; /* Instance parameters */ 136 137 /* Private parameters */ 138 LVM_UINT16 ControlPending; /* Control flag to indicate update pending */ 139 LVM_ControlParams_t NewParams; /* New control parameters pending update */ 140 141 /* Buffer control */ 142 LVM_INT16 InternalBlockSize; /* Maximum internal block size */ 143 LVM_Buffer_t* pBufferManagement; /* Buffer management variables */ 144 LVM_INT16 SamplesToProcess; /* Input samples left to process */ 145 LVM_FLOAT* pInputSamples; /* External input sample pointer */ 146 LVM_FLOAT* pOutputSamples; /* External output sample pointer */ 147 148 /* Configuration number */ 149 LVM_INT32 ConfigurationNumber; 150 LVM_INT32 BlickSizeMultiple; 151 152 /* DC removal */ 153 Biquad_FLOAT_Instance_t DC_RemovalInstance; /* DC removal filter instance */ 154 155 /* Concert Sound */ 156 LVCS_Handle_t hCSInstance; /* Concert Sound instance handle */ 157 LVCS_Instance_t CS_Instance; /* Concert Sound instance */ 158 LVM_INT16 CS_Active; /* Control flag */ 159 160 /* Equalizer */ 161 LVEQNB_Handle_t hEQNBInstance; /* N-Band Equaliser instance handle */ 162 LVEQNB_Instance_t EQNB_Instance; /* N-Band Equaliser instance */ 163 LVM_EQNB_BandDef_t* pEQNB_BandDefs; /* Local storage for new definitions */ 164 LVM_EQNB_BandDef_t* pEQNB_UserDefs; /* Local storage for the user's definitions */ 165 LVM_INT16 EQNB_Active; /* Control flag */ 166 167 /* Dynamic Bass Enhancement */ 168 LVDBE_Handle_t hDBEInstance; /* Dynamic Bass Enhancement instance handle */ 169 LVDBE_Instance_t DBE_Instance; /* Dynamic Bass Enhancement instance */ 170 LVM_INT16 DBE_Active; /* Control flag */ 171 172 /* Volume Control */ 173 LVMixer3_1St_FLOAT_st VC_Volume; /* Volume scaler */ 174 LVMixer3_2St_FLOAT_st VC_BalanceMix; /* VC balance mixer */ 175 LVM_INT16 VC_VolumedB; /* Gain in dB */ 176 LVM_INT16 VC_Active; /* Control flag */ 177 LVM_INT16 VC_AVLFixedVolume; /* AVL fixed volume */ 178 179 /* Treble Enhancement */ 180 std::unique_ptr<android::audio_utils::BiquadFilter<LVM_FLOAT>> 181 pTEBiquad; /* Biquad filter instance */ 182 LVM_INT16 TE_Active; /* Control flag */ 183 184 /* Headroom */ 185 LVM_HeadroomParams_t NewHeadroomParams; /* New headroom parameters pending update */ 186 LVM_HeadroomParams_t HeadroomParams; /* Headroom parameters */ 187 LVM_HeadroomBandDef_t* pHeadroom_BandDefs; /* Local storage for new definitions */ 188 LVM_HeadroomBandDef_t* pHeadroom_UserDefs; /* Local storage for the user's definitions */ 189 LVM_UINT16 Headroom; /* Value of the current headroom */ 190 191 /* Spectrum Analyzer */ 192 pLVPSA_Handle_t hPSAInstance; /* Spectrum Analyzer instance handle */ 193 LVPSA_InstancePr_t PSA_Instance; /* Spectrum Analyzer instance */ 194 LVPSA_InitParams_t PSA_InitParams; /* Spectrum Analyzer initialization parameters */ 195 LVPSA_ControlParams_t PSA_ControlParams; /* Spectrum Analyzer control parameters */ 196 LVM_INT16 PSA_GainOffset; /* Tone control flag */ 197 LVM_Callback CallBack; 198 LVM_FLOAT* pPSAInput; /* PSA input pointer */ 199 200 LVM_INT16 NoSmoothVolume; /* Enable or disable smooth volume changes*/ 201 202 LVM_INT16 NrChannels; 203 LVM_INT32 ChMask; 204 void* pScratch; /* Pointer to bundle scratch buffer*/ 205 206 } LVM_Instance_t; 207 208 /************************************************************************************/ 209 /* */ 210 /* Function Prototypes */ 211 /* */ 212 /************************************************************************************/ 213 214 LVM_ReturnStatus_en LVM_ApplyNewSettings(LVM_Handle_t hInstance); 215 216 void LVM_SetTrebleBoost(LVM_Instance_t* pInstance, LVM_ControlParams_t* pParams); 217 218 void LVM_SetVolume(LVM_Instance_t* pInstance, LVM_ControlParams_t* pParams); 219 220 LVM_INT32 LVM_VCCallBack(void* pBundleHandle, void* pGeneralPurpose, short CallBackParam); 221 222 void LVM_SetHeadroom(LVM_Instance_t* pInstance, LVM_ControlParams_t* pParams); 223 void LVM_BufferIn(LVM_Handle_t hInstance, const LVM_FLOAT* pInData, LVM_FLOAT** pToProcess, 224 LVM_FLOAT** pProcessed, LVM_UINT16* pNumSamples); 225 void LVM_BufferOut(LVM_Handle_t hInstance, LVM_FLOAT* pOutData, LVM_UINT16* pNumSamples); 226 227 LVM_INT32 LVM_AlgoCallBack(void* pBundleHandle, void* pData, LVM_INT16 callbackId); 228 229 #endif /* __LVM_PRIVATE_H__ */ 230