• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef BUILD_FLOAT
142 typedef struct
143 {
144     LVM_FLOAT               *pScratch;          /* Bundle scratch buffer */
145 
146     LVM_INT16               BufferState;        /* Buffer status */
147 #ifdef SUPPORT_MC
148     LVM_FLOAT               InDelayBuffer[3 * LVM_MAX_CHANNELS * MIN_INTERNAL_BLOCKSIZE];
149 #else
150     LVM_FLOAT               InDelayBuffer[6 * MIN_INTERNAL_BLOCKSIZE]; /* Input buffer delay line, \
151                                                                            left and right */
152 #endif
153     LVM_INT16               InDelaySamples;     /* Number of samples in the input delay buffer */
154 #ifdef SUPPORT_MC
155     LVM_FLOAT               OutDelayBuffer[LVM_MAX_CHANNELS * MIN_INTERNAL_BLOCKSIZE];
156 #else
157     LVM_FLOAT               OutDelayBuffer[2 * MIN_INTERNAL_BLOCKSIZE]; /* Output buffer delay \
158                                                                                       line */
159 #endif
160     LVM_INT16               OutDelaySamples;    /* Number of samples in the output delay buffer, \
161                                                                              left and right */
162     LVM_INT16               SamplesToOutput;    /* Samples to write to the output */
163 } LVM_Buffer_t;
164 #else
165 typedef struct
166 {
167     LVM_INT16               *pScratch;          /* Bundle scratch buffer */
168 
169     LVM_INT16               BufferState;        /* Buffer status */
170     LVM_INT16               InDelayBuffer[6*MIN_INTERNAL_BLOCKSIZE]; /* Input buffer delay line, left and right */
171     LVM_INT16               InDelaySamples;     /* Number of samples in the input delay buffer */
172 
173     LVM_INT16               OutDelayBuffer[2*MIN_INTERNAL_BLOCKSIZE]; /* Output buffer delay line */
174     LVM_INT16               OutDelaySamples;    /* Number of samples in the output delay buffer, left and right */
175     LVM_INT16               SamplesToOutput;    /* Samples to write to the output */
176 } LVM_Buffer_t;
177 #endif
178 
179 /* Filter taps */
180 typedef struct
181 {
182 #ifdef BUILD_FLOAT
183     Biquad_2I_Order1_FLOAT_Taps_t TrebleBoost_Taps;   /* Treble boost Taps */
184 #else
185     Biquad_2I_Order1_Taps_t TrebleBoost_Taps;   /* Treble boost Taps */
186 #endif
187 } LVM_TE_Data_t;
188 
189 /* Coefficients */
190 typedef struct
191 {
192 #ifdef BUILD_FLOAT
193     Biquad_FLOAT_Instance_t       TrebleBoost_State;  /* State for the treble boost filter */
194 #else
195     Biquad_Instance_t       TrebleBoost_State;  /* State for the treble boost filter */
196 #endif
197 } LVM_TE_Coefs_t;
198 
199 typedef struct
200 {
201     /* Public parameters */
202     LVM_MemTab_t            MemoryTable;        /* Instance memory allocation table */
203     LVM_ControlParams_t     Params;             /* Control parameters */
204     LVM_InstParams_t        InstParams;         /* Instance parameters */
205 
206     /* Private parameters */
207     LVM_UINT16              ControlPending;     /* Control flag to indicate update pending */
208     LVM_ControlParams_t     NewParams;          /* New control parameters pending update */
209 
210     /* Buffer control */
211     LVM_INT16               InternalBlockSize;  /* Maximum internal block size */
212     LVM_Buffer_t            *pBufferManagement; /* Buffer management variables */
213     LVM_INT16               SamplesToProcess;   /* Input samples left to process */
214 #ifdef BUILD_FLOAT
215     LVM_FLOAT               *pInputSamples;     /* External input sample pointer */
216     LVM_FLOAT               *pOutputSamples;    /* External output sample pointer */
217 #else
218     LVM_INT16               *pInputSamples;     /* External input sample pointer */
219     LVM_INT16               *pOutputSamples;    /* External output sample pointer */
220 #endif
221 
222     /* Configuration number */
223     LVM_INT32               ConfigurationNumber;
224     LVM_INT32               BlickSizeMultiple;
225 
226     /* DC removal */
227 #ifdef BUILD_FLOAT
228     Biquad_FLOAT_Instance_t       DC_RemovalInstance; /* DC removal filter instance */
229 #else
230     Biquad_Instance_t       DC_RemovalInstance; /* DC removal filter instance */
231 #endif
232 
233     /* Concert Sound */
234     LVCS_Handle_t           hCSInstance;        /* Concert Sound instance handle */
235     LVCS_Instance_t         CS_Instance;        /* Concert Sound instance */
236     LVM_INT16               CS_Active;          /* Control flag */
237 
238     /* Equalizer */
239     LVEQNB_Handle_t         hEQNBInstance;      /* N-Band Equaliser instance handle */
240     LVEQNB_Instance_t       EQNB_Instance;      /* N-Band Equaliser instance */
241     LVM_EQNB_BandDef_t      *pEQNB_BandDefs;    /* Local storage for new definitions */
242     LVM_EQNB_BandDef_t      *pEQNB_UserDefs;    /* Local storage for the user's definitions */
243     LVM_INT16               EQNB_Active;        /* Control flag */
244 
245     /* Dynamic Bass Enhancement */
246     LVDBE_Handle_t          hDBEInstance;       /* Dynamic Bass Enhancement instance handle */
247     LVDBE_Instance_t        DBE_Instance;       /* Dynamic Bass Enhancement instance */
248     LVM_INT16               DBE_Active;         /* Control flag */
249 
250     /* Volume Control */
251 #ifdef BUILD_FLOAT
252     LVMixer3_1St_FLOAT_st   VC_Volume;          /* Volume scaler */
253 #else
254     LVMixer3_1St_st         VC_Volume;          /* Volume scaler */
255 #endif
256 #ifdef BUILD_FLOAT
257     LVMixer3_2St_FLOAT_st         VC_BalanceMix;      /* VC balance mixer */
258 #else
259     LVMixer3_2St_st         VC_BalanceMix;      /* VC balance mixer */
260 #endif
261     LVM_INT16               VC_VolumedB;        /* Gain in dB */
262     LVM_INT16               VC_Active;          /* Control flag */
263     LVM_INT16               VC_AVLFixedVolume;  /* AVL fixed volume */
264 
265     /* Treble Enhancement */
266     LVM_TE_Data_t           *pTE_Taps;          /* Treble boost Taps */
267     LVM_TE_Coefs_t          *pTE_State;         /* State for the treble boost filter */
268     LVM_INT16               TE_Active;          /* Control flag */
269 
270     /* Headroom */
271     LVM_HeadroomParams_t    NewHeadroomParams;   /* New headroom parameters pending update */
272     LVM_HeadroomParams_t    HeadroomParams;      /* Headroom parameters */
273     LVM_HeadroomBandDef_t   *pHeadroom_BandDefs; /* Local storage for new definitions */
274     LVM_HeadroomBandDef_t   *pHeadroom_UserDefs; /* Local storage for the user's definitions */
275     LVM_UINT16              Headroom;            /* Value of the current headroom */
276 
277     /* Spectrum Analyzer */
278     pLVPSA_Handle_t         hPSAInstance;       /* Spectrum Analyzer instance handle */
279     LVPSA_InstancePr_t      PSA_Instance;       /* Spectrum Analyzer instance */
280     LVPSA_InitParams_t      PSA_InitParams;     /* Spectrum Analyzer initialization parameters */
281     LVPSA_ControlParams_t   PSA_ControlParams;  /* Spectrum Analyzer control parameters */
282     LVM_INT16               PSA_GainOffset;     /* Tone control flag */
283     LVM_Callback            CallBack;
284 #ifdef BUILD_FLOAT
285     LVM_FLOAT               *pPSAInput;         /* PSA input pointer */
286 #else
287     LVM_INT16               *pPSAInput;         /* PSA input pointer */
288 #endif
289 
290     LVM_INT16              NoSmoothVolume;      /* Enable or disable smooth volume changes*/
291 
292 #ifdef SUPPORT_MC
293     LVM_INT16              NrChannels;
294     LVM_INT32              ChMask;
295 #endif
296 
297 } LVM_Instance_t;
298 
299 
300 /************************************************************************************/
301 /*                                                                                  */
302 /*  Function Prototypes                                                             */
303 /*                                                                                  */
304 /************************************************************************************/
305 
306 LVM_ReturnStatus_en LVM_ApplyNewSettings(LVM_Handle_t       hInstance);
307 
308 void    LVM_SetTrebleBoost( LVM_Instance_t         *pInstance,
309                             LVM_ControlParams_t    *pParams);
310 
311 void    LVM_SetVolume(  LVM_Instance_t         *pInstance,
312                         LVM_ControlParams_t    *pParams);
313 
314 LVM_INT32    LVM_VCCallBack(void*   pBundleHandle,
315                             void*   pGeneralPurpose,
316                             short   CallBackParam);
317 
318 void    LVM_SetHeadroom(    LVM_Instance_t         *pInstance,
319                             LVM_ControlParams_t    *pParams);
320 #ifdef BUILD_FLOAT
321 void    LVM_BufferIn(   LVM_Handle_t      hInstance,
322                         const LVM_FLOAT   *pInData,
323                         LVM_FLOAT         **pToProcess,
324                         LVM_FLOAT         **pProcessed,
325                         LVM_UINT16        *pNumSamples);
326 #else
327 void    LVM_BufferIn(   LVM_Handle_t      hInstance,
328                         const LVM_INT16   *pInData,
329                         LVM_INT16         **pToProcess,
330                         LVM_INT16         **pProcessed,
331                         LVM_UINT16        *pNumSamples);
332 #endif
333 #ifdef BUILD_FLOAT
334 void    LVM_BufferOut(  LVM_Handle_t     hInstance,
335                         LVM_FLOAT        *pOutData,
336                         LVM_UINT16       *pNumSamples);
337 #else
338 void    LVM_BufferOut(  LVM_Handle_t     hInstance,
339                         LVM_INT16        *pOutData,
340                         LVM_UINT16       *pNumSamples);
341 #endif
342 
343 LVM_INT32 LVM_AlgoCallBack(     void          *pBundleHandle,
344                                 void          *pData,
345                                 LVM_INT16     callbackId);
346 
347 #ifdef __cplusplus
348 }
349 #endif /* __cplusplus */
350 
351 #endif      /* __LVM_PRIVATE_H__ */
352 
353