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 #ifndef _LVPSA_H_
19 #define _LVPSA_H_
20 
21 #include "LVM_Types.h"
22 
23 /****************************************************************************************/
24 /*                                                                                      */
25 /*  CONSTANTS DEFINITIONS                                                               */
26 /*                                                                                      */
27 /****************************************************************************************/
28 
29 /* Memory table*/
30 #define     LVPSA_NR_MEMORY_REGIONS                  4      /* Number of memory regions                                          */
31 
32 /****************************************************************************************/
33 /*                                                                                      */
34 /*  TYPES DEFINITIONS                                                                   */
35 /*                                                                                      */
36 /****************************************************************************************/
37 /* Memory Types */
38 typedef enum
39 {
40     LVPSA_PERSISTENT      = LVM_PERSISTENT,
41     LVPSA_PERSISTENT_DATA = LVM_PERSISTENT_DATA,
42     LVPSA_PERSISTENT_COEF = LVM_PERSISTENT_COEF,
43     LVPSA_SCRATCH         = LVM_SCRATCH,
44     LVPSA_MEMORY_DUMMY = LVM_MAXINT_32                      /* Force 32 bits enum, don't use it!                                 */
45 } LVPSA_MemoryTypes_en;
46 
47 /* Level detection speed control parameters */
48 typedef enum
49 {
50     LVPSA_SPEED_LOW,                                        /* Low speed level   detection                                       */
51     LVPSA_SPEED_MEDIUM,                                     /* Medium speed level   detection                                    */
52     LVPSA_SPEED_HIGH,                                       /* High speed level   detection                                      */
53     LVPSA_SPEED_DUMMY = LVM_MAXINT_32                       /* Force 32 bits enum, don't use it!                                 */
54 } LVPSA_LevelDetectSpeed_en;
55 
56 /* Filter control parameters */
57 typedef struct
58 {
59     LVM_UINT16                 CenterFrequency;             /* Center frequency of the band-pass filter (in Hz)                  */
60     LVM_UINT16                 QFactor;                     /* Quality factor of the filter             (in 1/100)               */
61     LVM_INT16                  PostGain;                    /* Postgain to apply after the filtering    (in dB Q16.0)            */
62 
63 } LVPSA_FilterParam_t;
64 
65 /* LVPSA initialization parameters */
66 typedef struct
67 {
68     LVM_UINT16                 SpectralDataBufferDuration;  /* Spectral data buffer duration in time (ms in Q16.0)               */
69     LVM_UINT16                 MaxInputBlockSize;           /* Maximum expected input block size (in samples)                    */
70     LVM_UINT16                 nBands;                      /* Number of bands of the SA                                         */
71     LVPSA_FilterParam_t       *pFiltersParams;              /* Points to nBands filter param structures for filters settings     */
72 
73 } LVPSA_InitParams_t, *pLVPSA_InitParams_t;
74 
75 /* LVPSA control parameters */
76 typedef struct
77 {
78     LVM_Fs_en                  Fs;                          /* Input sampling rate                                               */
79     LVPSA_LevelDetectSpeed_en  LevelDetectionSpeed;         /* Level detection speed                                             */
80 
81 } LVPSA_ControlParams_t, *pLVPSA_ControlParams_t;
82 
83 /* Memory region definition */
84 typedef struct
85 {
86     LVM_UINT32                 Size;                        /* Region size in bytes                                              */
87     LVPSA_MemoryTypes_en       Type;                        /* Region type                                                       */
88     void                       *pBaseAddress;               /* Pointer to the region base address                                */
89 } LVPSA_MemoryRegion_t;
90 
91 /* Memory table containing the region definitions */
92 typedef struct
93 {
94     LVPSA_MemoryRegion_t       Region[LVPSA_NR_MEMORY_REGIONS];/* One definition for each region                                 */
95 } LVPSA_MemTab_t;
96 
97 /* Audio time type */
98 typedef LVM_INT32 LVPSA_Time;
99 
100 /* Module instance Handle */
101 typedef void *pLVPSA_Handle_t;
102 
103 /* LVPSA return codes */
104 typedef enum
105 {
106     LVPSA_OK,                                               /* The function ran without any problem                              */
107     LVPSA_ERROR_INVALIDPARAM,                               /* A parameter is incorrect                                          */
108     LVPSA_ERROR_WRONGTIME,                                  /* An incorrect AudioTime is used                                    */
109     LVPSA_ERROR_NULLADDRESS,                                /* A pointer has a NULL value                                        */
110     LVPSA_RETURN_DUMMY = LVM_MAXINT_32                      /* Force 32 bits enum, don't use it!                                 */
111 } LVPSA_RETURN;
112 
113 /*********************************************************************************************************************************
114    FUNCTIONS PROTOTYPE
115 **********************************************************************************************************************************/
116 /*********************************************************************************************************************************/
117 /*                                                                                                                               */
118 /* FUNCTION:            LVPSA_Memory                                                                                         */
119 /*                                                                                                                               */
120 /* DESCRIPTION:                                                                                                                  */
121 /*  This function is used for memory allocation and free. It can be called in                                                    */
122 /*  two ways:                                                                                                                    */
123 /*                                                                                                                               */
124 /*      hInstance = NULL                Returns the memory requirements                                                          */
125 /*      hInstance = Instance handle     Returns the memory requirements and                                                      */
126 /*                                      allocated base addresses for the instance                                                */
127 /*                                                                                                                               */
128 /*  When this function is called for memory allocation (hInstance=NULL) the memory                                               */
129 /*  base address pointers are NULL on return.                                                                                    */
130 /*                                                                                                                               */
131 /*  When the function is called for free (hInstance = Instance Handle) the memory                                                */
132 /*  table returns the allocated memory and base addresses used during initialisation.                                            */
133 /*                                                                                                                               */
134 /* PARAMETERS:                                                                                                                   */
135 /*  hInstance           Instance Handle                                                                                          */
136 /*  pMemoryTable        Pointer to an empty memory definition table                                                              */
137 /*  pInitParams         Pointer to the instance init parameters                                                                  */
138 /*                                                                                                                               */
139 /* RETURNS:                                                                                                                      */
140 /*  LVPSA_OK            Succeeds                                                                                                 */
141 /*  otherwise           Error due to bad parameters                                                                              */
142 /*                                                                                                                               */
143 /*********************************************************************************************************************************/
144 LVPSA_RETURN LVPSA_Memory            ( pLVPSA_Handle_t             hInstance,
145                                        LVPSA_MemTab_t             *pMemoryTable,
146                                        LVPSA_InitParams_t         *pInitParams    );
147 
148 /*********************************************************************************************************************************/
149 /*                                                                                                                               */
150 /* FUNCTION:            LVPSA_Init                                                                                               */
151 /*                                                                                                                               */
152 /* DESCRIPTION:                                                                                                                  */
153 /*  Initializes the LVPSA module.                                                                                                */
154 /*                                                                                                                               */
155 /*                                                                                                                               */
156 /* PARAMETERS:                                                                                                                   */
157 /*  phInstance          Pointer to the instance Handle                                                                           */
158 /*  pInitParams         Pointer to the instance init parameters                                                                  */
159 /*  pControlParams      Pointer to the instance control parameters                                                               */
160 /*  pMemoryTable        Pointer to the memory definition table                                                                   */
161 /*                                                                                                                               */
162 /*                                                                                                                               */
163 /* RETURNS:                                                                                                                      */
164 /*  LVPSA_OK            Succeeds                                                                                                 */
165 /*  otherwise           Error due to bad parameters                                                                              */
166 /*                                                                                                                               */
167 /*********************************************************************************************************************************/
168 LVPSA_RETURN LVPSA_Init              ( pLVPSA_Handle_t             *phInstance,
169                                        LVPSA_InitParams_t          *pInitParams,
170                                        LVPSA_ControlParams_t       *pControlParams,
171                                        LVPSA_MemTab_t              *pMemoryTable  );
172 
173 /*********************************************************************************************************************************/
174 /*                                                                                                                               */
175 /* FUNCTION:            LVPSA_Control                                                                                            */
176 /*                                                                                                                               */
177 /* DESCRIPTION:                                                                                                                  */
178 /*  Controls the LVPSA module.                                                                                                   */
179 /*                                                                                                                               */
180 /* PARAMETERS:                                                                                                                   */
181 /*  hInstance           Instance Handle                                                                                          */
182 /*  pNewParams          Pointer to the instance new control parameters                                                           */
183 /*                                                                                                                               */
184 /* RETURNS:                                                                                                                      */
185 /*  LVPSA_OK            Succeeds                                                                                                 */
186 /*  otherwise           Error due to bad parameters                                                                              */
187 /*                                                                                                                               */
188 /*********************************************************************************************************************************/
189 LVPSA_RETURN LVPSA_Control           ( pLVPSA_Handle_t             hInstance,
190                                        LVPSA_ControlParams_t      *pNewParams     );
191 
192 /*********************************************************************************************************************************/
193 /*                                                                                                                               */
194 /* FUNCTION:            LVPSA_Process                                                                                            */
195 /*                                                                                                                               */
196 /* DESCRIPTION:                                                                                                                  */
197 /*  The process calculates the levels of the frequency bands.                                                                    */
198 /*                                                                                                                               */
199 /* PARAMETERS:                                                                                                                   */
200 /*  hInstance           Instance Handle                                                                                          */
201 /*  pLVPSA_InputSamples Pointer to the input samples buffer                                                                      */
202 /*  InputBlockSize      Number of mono samples to process                                                                        */
203 /*  AudioTime           Playback time of the first input sample                                                                  */
204 /*                                                                                                                               */
205 /*                                                                                                                               */
206 /* RETURNS:                                                                                                                      */
207 /*  LVPSA_OK            Succeeds                                                                                                 */
208 /*  otherwise           Error due to bad parameters                                                                              */
209 /*                                                                                                                               */
210 /*********************************************************************************************************************************/
211 LVPSA_RETURN LVPSA_Process           ( pLVPSA_Handle_t      hInstance,
212                                        LVM_FLOAT           *pLVPSA_InputSamples,
213                                        LVM_UINT16           InputBlockSize,
214                                        LVPSA_Time           AudioTime             );
215 /*********************************************************************************************************************************/
216 /*                                                                                                                               */
217 /* FUNCTION:            LVPSA_GetSpectrum                                                                                        */
218 /*                                                                                                                               */
219 /* DESCRIPTION:                                                                                                                  */
220 /*  This function is used for memory allocation and free.                                                                        */
221 /*                                                                                                                               */
222 /*                                                                                                                               */
223 /* PARAMETERS:                                                                                                                   */
224 /*  hInstance            Instance Handle                                                                                         */
225 /*  GetSpectrumAudioTime Time to retrieve the values at                                                                          */
226 /*  pCurrentValues       Pointer to an empty buffer : Current level values output                                                */
227 /*  pPeakValues          Pointer to an empty buffer : Peak level values output                                                   */
228 /*                                                                                                                               */
229 /*                                                                                                                               */
230 /* RETURNS:                                                                                                                      */
231 /*  LVPSA_OK            Succeeds                                                                                                 */
232 /*  otherwise           Error due to bad parameters                                                                              */
233 /*                                                                                                                               */
234 /*********************************************************************************************************************************/
235 LVPSA_RETURN LVPSA_GetSpectrum       ( pLVPSA_Handle_t      hInstance,
236                                        LVPSA_Time           GetSpectrumAudioTime,
237                                        LVM_UINT8           *pCurrentValues,
238                                        LVM_UINT8           *pPeakValues           );
239 
240 /*********************************************************************************************************************************/
241 /*                                                                                                                               */
242 /* FUNCTION:            LVPSA_GetControlParams                                                                                   */
243 /*                                                                                                                               */
244 /* DESCRIPTION:                                                                                                                  */
245 /*  Get the current control parameters of the LVPSA module.                                                                      */
246 /*                                                                                                                               */
247 /* PARAMETERS:                                                                                                                   */
248 /*  hInstance           Instance Handle                                                                                          */
249 /*  pParams             Pointer to an empty control parameters structure                                                         */
250 /* RETURNS:                                                                                                                      */
251 /*  LVPSA_OK            Succeeds                                                                                                 */
252 /*  otherwise           Error due to bad parameters                                                                              */
253 /*                                                                                                                               */
254 /*********************************************************************************************************************************/
255 LVPSA_RETURN LVPSA_GetControlParams  (    pLVPSA_Handle_t            hInstance,
256                                           LVPSA_ControlParams_t     *pParams      );
257 
258 /*********************************************************************************************************************************/
259 /*                                                                                                                               */
260 /* FUNCTION:            LVPSA_GetInitParams                                                                                      */
261 /*                                                                                                                               */
262 /* DESCRIPTION:                                                                                                                  */
263 /*  Get the initialization parameters of the LVPSA module.                                                                       */
264 /*                                                                                                                               */
265 /* PARAMETERS:                                                                                                                   */
266 /*  hInstance           Instance Handle                                                                                          */
267 /*  pParams             Pointer to an empty init parameters structure                                                            */
268 /* RETURNS:                                                                                                                      */
269 /*  LVPSA_OK            Succeeds                                                                                                 */
270 /*  otherwise           Error due to bad parameters                                                                              */
271 /*                                                                                                                               */
272 /*********************************************************************************************************************************/
273 LVPSA_RETURN LVPSA_GetInitParams     (    pLVPSA_Handle_t            hInstance,
274                                           LVPSA_InitParams_t        *pParams      );
275 
276 #endif /* _LVPSA_H */
277