Home | History | Annotate | Download | only in src
      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 #ifdef __cplusplus
     31 extern "C" {
     32 #endif /* __cplusplus */
     33 
     34 
     35 /************************************************************************************/
     36 /*                                                                                  */
     37 /*  Includes                                                                        */
     38 /*                                                                                  */
     39 /************************************************************************************/
     40 
     41 #include "LVM.h"                                /* LifeVibes */
     42 #include "LVM_Common.h"                         /* LifeVibes common */
     43 #include "BIQUAD.h"                             /* Biquad library */
     44 #include "LVC_Mixer.h"                          /* Mixer library */
     45 #include "LVCS_Private.h"                       /* Concert Sound */
     46 #include "LVDBE_Private.h"                      /* Dynamic Bass Enhancement */
     47 #include "LVEQNB_Private.h"                     /* N-Band equaliser */
     48 #include "LVPSA_Private.h"                      /* Parametric Spectrum Analyzer */
     49 
     50 
     51 /************************************************************************************/
     52 /*                                                                                  */
     53 /*  Defines                                                                         */
     54 /*                                                                                  */
     55 /************************************************************************************/
     56 
     57 /* General */
     58 #define LVM_INVALID                     0xFFFF    /* Invalid init parameter */
     59 
     60 /* Memory */
     61 #define LVM_INSTANCE_ALIGN              4         /* 32-bit for structures */
     62 #define LVM_FIRSTCALL                   0         /* First call to the buffer */
     63 #define LVM_MAXBLOCKCALL                1         /* Maximum block size calls to the buffer */
     64 #define LVM_LASTCALL                    2         /* Last call to the buffer */
     65 #define LVM_FIRSTLASTCALL               3         /* Single call for small number of samples */
     66 
     67 /* Block Size */
     68 #define LVM_MIN_MAXBLOCKSIZE            16        /* Minimum MaxBlockSize Limit*/
     69 #define LVM_MANAGED_MAX_MAXBLOCKSIZE    8191      /* Maximum MaxBlockSzie Limit for Managed Buffer Mode*/
     70 #define LVM_UNMANAGED_MAX_MAXBLOCKSIZE  4096      /* Maximum MaxBlockSzie Limit for Unmanaged Buffer Mode */
     71 
     72 #define MAX_INTERNAL_BLOCKSIZE          8128      /* Maximum multiple of 64  below 8191*/
     73 
     74 #define MIN_INTERNAL_BLOCKSIZE          16        /* Minimum internal block size */
     75 #define MIN_INTERNAL_BLOCKSHIFT         4         /* Minimum internal block size as a power of 2 */
     76 #define MIN_INTERNAL_BLOCKMASK          0xFFF0    /* Minimum internal block size mask */
     77 
     78 #define LVM_PSA_DYNAMICRANGE            60        /* Spectral Dynamic range: used for offseting output*/
     79 #define LVM_PSA_BARHEIGHT               127       /* Spectral Bar Height*/
     80 
     81 #define LVM_TE_MIN_EFFECTLEVEL          0         /*TE Minimum EffectLevel*/
     82 #define LVM_TE_MAX_EFFECTLEVEL          15        /*TE Maximum Effect level*/
     83 
     84 #define LVM_VC_MIN_EFFECTLEVEL          (-96)     /*VC Minimum EffectLevel*/
     85 #define LVM_VC_MAX_EFFECTLEVEL          0         /*VC Maximum Effect level*/
     86 
     87 #define LVM_BE_MIN_EFFECTLEVEL          0         /*BE Minimum EffectLevel*/
     88 #define LVM_BE_MAX_EFFECTLEVEL          15        /*BE Maximum Effect level*/
     89 
     90 #define LVM_EQNB_MIN_BAND_FREQ          20        /*EQNB Minimum Band Frequency*/
     91 #define LVM_EQNB_MAX_BAND_FREQ          24000     /*EQNB Maximum Band Frequency*/
     92 #define LVM_EQNB_MIN_BAND_GAIN          (-15)     /*EQNB Minimum Band Frequency*/
     93 #define LVM_EQNB_MAX_BAND_GAIN          15        /*EQNB Maximum Band Frequency*/
     94 #define LVM_EQNB_MIN_QFACTOR            25        /*EQNB Minimum Q Factor*/
     95 #define LVM_EQNB_MAX_QFACTOR            1200      /*EQNB Maximum Q Factor*/
     96 #define LVM_EQNB_MIN_LPF_FREQ           1000      /*EQNB Minimum Low Pass Corner frequency*/
     97 #define LVM_EQNB_MIN_HPF_FREQ           20        /*EQNB Minimum High Pass Corner frequency*/
     98 #define LVM_EQNB_MAX_HPF_FREQ           1000      /*EQNB Maximum High Pass Corner frequency*/
     99 
    100 #define LVM_CS_MIN_EFFECT_LEVEL         0         /*CS Minimum Effect Level*/
    101 #define LVM_CS_MAX_REVERB_LEVEL         100       /*CS Maximum Reverb Level*/
    102 #define LVM_VIRTUALIZER_MAX_REVERB_LEVEL 100      /*Vitrualizer Maximum Reverb Level*/
    103 
    104 #define LVM_VC_MIXER_TIME              100       /*VC mixer time*/
    105 #define LVM_VC_BALANCE_MAX             96        /*VC balance max value*/
    106 #define LVM_VC_BALANCE_MIN             (-96)     /*VC balance min value*/
    107 
    108 /* Algorithm masks */
    109 #define LVM_CS_MASK                     1
    110 #define LVM_EQNB_MASK                   2
    111 #define LVM_DBE_MASK                    4
    112 #define LVM_VC_MASK                     16
    113 #define LVM_TE_MASK                     32
    114 #define LVM_PSA_MASK                    2048
    115 
    116 
    117 /************************************************************************************/
    118 /*                                                                                  */
    119 /*  Structures                                                                      */
    120 /*                                                                                  */
    121 /************************************************************************************/
    122 
    123 /* Memory region definition */
    124 typedef struct
    125 {
    126     LVM_UINT32              Size;               /* Region size in bytes */
    127     LVM_UINT16              Alignment;          /* Byte alignment */
    128     LVM_MemoryTypes_en      Type;               /* Region type */
    129     void                    *pBaseAddress;      /* Pointer to the region base address */
    130 } LVM_IntMemoryRegion_t;
    131 
    132 
    133 /* Memory table containing the region definitions */
    134 typedef struct
    135 {
    136     LVM_IntMemoryRegion_t   Region[LVM_NR_MEMORY_REGIONS];  /* One definition for each region */
    137 } LVM_IntMemTab_t;
    138 
    139 
    140 /* Buffer Management */
    141 typedef struct
    142 {
    143     LVM_INT16               *pScratch;          /* Bundle scratch buffer */
    144 
    145     LVM_INT16               BufferState;        /* Buffer status */
    146     LVM_INT16               InDelayBuffer[6*MIN_INTERNAL_BLOCKSIZE]; /* Input buffer delay line, left and right */
    147     LVM_INT16               InDelaySamples;     /* Number of samples in the input delay buffer */
    148 
    149     LVM_INT16               OutDelayBuffer[2*MIN_INTERNAL_BLOCKSIZE]; /* Output buffer delay line */
    150     LVM_INT16               OutDelaySamples;    /* Number of samples in the output delay buffer, left and right */
    151     LVM_INT16               SamplesToOutput;    /* Samples to write to the output */
    152 } LVM_Buffer_t;
    153 
    154 
    155 /* Filter taps */
    156 typedef struct
    157 {
    158     Biquad_2I_Order1_Taps_t TrebleBoost_Taps;   /* Treble boost Taps */
    159 } LVM_TE_Data_t;
    160 
    161 
    162 /* Coefficients */
    163 typedef struct
    164 {
    165     Biquad_Instance_t       TrebleBoost_State;  /* State for the treble boost filter */
    166 } LVM_TE_Coefs_t;
    167 
    168 
    169 typedef struct
    170 {
    171     /* Public parameters */
    172     LVM_MemTab_t            MemoryTable;        /* Instance memory allocation table */
    173     LVM_ControlParams_t     Params;             /* Control parameters */
    174     LVM_InstParams_t        InstParams;         /* Instance parameters */
    175 
    176     /* Private parameters */
    177     LVM_UINT16              ControlPending;     /* Control flag to indicate update pending */
    178     LVM_ControlParams_t     NewParams;          /* New control parameters pending update */
    179 
    180     /* Buffer control */
    181     LVM_INT16               InternalBlockSize;  /* Maximum internal block size */
    182     LVM_Buffer_t            *pBufferManagement; /* Buffer management variables */
    183     LVM_INT16               SamplesToProcess;   /* Input samples left to process */
    184     LVM_INT16               *pInputSamples;     /* External input sample pointer */
    185     LVM_INT16               *pOutputSamples;    /* External output sample pointer */
    186 
    187     /* Configuration number */
    188     LVM_INT32               ConfigurationNumber;
    189     LVM_INT32               BlickSizeMultiple;
    190 
    191     /* DC removal */
    192     Biquad_Instance_t       DC_RemovalInstance; /* DC removal filter instance */
    193 
    194     /* Concert Sound */
    195     LVCS_Handle_t           hCSInstance;        /* Concert Sound instance handle */
    196     LVCS_Instance_t         CS_Instance;        /* Concert Sound instance */
    197     LVM_INT16               CS_Active;          /* Control flag */
    198 
    199     /* Equalizer */
    200     LVEQNB_Handle_t         hEQNBInstance;      /* N-Band Equaliser instance handle */
    201     LVEQNB_Instance_t       EQNB_Instance;      /* N-Band Equaliser instance */
    202     LVM_EQNB_BandDef_t      *pEQNB_BandDefs;    /* Local storage for new definitions */
    203     LVM_EQNB_BandDef_t      *pEQNB_UserDefs;    /* Local storage for the user's definitions */
    204     LVM_INT16               EQNB_Active;        /* Control flag */
    205 
    206     /* Dynamic Bass Enhancement */
    207     LVDBE_Handle_t          hDBEInstance;       /* Dynamic Bass Enhancement instance handle */
    208     LVDBE_Instance_t        DBE_Instance;       /* Dynamic Bass Enhancement instance */
    209     LVM_INT16               DBE_Active;         /* Control flag */
    210 
    211     /* Volume Control */
    212     LVMixer3_1St_st         VC_Volume;          /* Volume scaler */
    213     LVMixer3_2St_st         VC_BalanceMix;      /* VC balance mixer */
    214     LVM_INT16               VC_VolumedB;        /* Gain in dB */
    215     LVM_INT16               VC_Active;          /* Control flag */
    216     LVM_INT16               VC_AVLFixedVolume;  /* AVL fixed volume */
    217 
    218     /* Treble Enhancement */
    219     LVM_TE_Data_t           *pTE_Taps;          /* Treble boost Taps */
    220     LVM_TE_Coefs_t          *pTE_State;         /* State for the treble boost filter */
    221     LVM_INT16               TE_Active;          /* Control flag */
    222 
    223     /* Headroom */
    224     LVM_HeadroomParams_t    NewHeadroomParams;   /* New headroom parameters pending update */
    225     LVM_HeadroomParams_t    HeadroomParams;      /* Headroom parameters */
    226     LVM_HeadroomBandDef_t   *pHeadroom_BandDefs; /* Local storage for new definitions */
    227     LVM_HeadroomBandDef_t   *pHeadroom_UserDefs; /* Local storage for the user's definitions */
    228     LVM_UINT16              Headroom;            /* Value of the current headroom */
    229 
    230     /* Spectrum Analyzer */
    231     pLVPSA_Handle_t         hPSAInstance;       /* Spectrum Analyzer instance handle */
    232     LVPSA_InstancePr_t      PSA_Instance;       /* Spectrum Analyzer instance */
    233     LVPSA_InitParams_t      PSA_InitParams;     /* Spectrum Analyzer initialization parameters */
    234     LVPSA_ControlParams_t   PSA_ControlParams;  /* Spectrum Analyzer control parameters */
    235     LVM_INT16               PSA_GainOffset;     /* Tone control flag */
    236     LVM_Callback            CallBack;
    237     LVM_INT16               *pPSAInput;         /* PSA input pointer */
    238 
    239     LVM_INT16              NoSmoothVolume;      /* Enable or disable smooth volume changes*/
    240 
    241 } LVM_Instance_t;
    242 
    243 
    244 /************************************************************************************/
    245 /*                                                                                  */
    246 /*  Function Prototypes                                                             */
    247 /*                                                                                  */
    248 /************************************************************************************/
    249 
    250 LVM_ReturnStatus_en LVM_ApplyNewSettings(LVM_Handle_t       hInstance);
    251 
    252 void    LVM_SetTrebleBoost( LVM_Instance_t         *pInstance,
    253                             LVM_ControlParams_t    *pParams);
    254 
    255 void    LVM_SetVolume(  LVM_Instance_t         *pInstance,
    256                         LVM_ControlParams_t    *pParams);
    257 
    258 LVM_INT32    LVM_VCCallBack(void*   pBundleHandle,
    259                             void*   pGeneralPurpose,
    260                             short   CallBackParam);
    261 
    262 void    LVM_SetHeadroom(    LVM_Instance_t         *pInstance,
    263                             LVM_ControlParams_t    *pParams);
    264 
    265 void    LVM_BufferIn(   LVM_Handle_t      hInstance,
    266                         const LVM_INT16   *pInData,
    267                         LVM_INT16         **pToProcess,
    268                         LVM_INT16         **pProcessed,
    269                         LVM_UINT16        *pNumSamples);
    270 
    271 void    LVM_BufferOut(  LVM_Handle_t     hInstance,
    272                         LVM_INT16        *pOutData,
    273                         LVM_UINT16       *pNumSamples);
    274 
    275 LVM_INT32 LVM_AlgoCallBack(     void          *pBundleHandle,
    276                                 void          *pData,
    277                                 LVM_INT16     callbackId);
    278 
    279 #ifdef __cplusplus
    280 }
    281 #endif /* __cplusplus */
    282 
    283 #endif      /* __LVM_PRIVATE_H__ */
    284 
    285