• 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 #ifndef _LVPSA_H_
19 #define _LVPSA_H_
20 
21 #include "LVM_Types.h"
22 
23 /****************************************************************************************/
24 /*                                                                                      */
25 /*  TYPES DEFINITIONS                                                                   */
26 /*                                                                                      */
27 /****************************************************************************************/
28 /* Level detection speed control parameters */
29 typedef enum {
30     LVPSA_SPEED_LOW,    /* Low speed level   detection                                       */
31     LVPSA_SPEED_MEDIUM, /* Medium speed level   detection                                    */
32     LVPSA_SPEED_HIGH,   /* High speed level   detection                                      */
33     LVPSA_SPEED_DUMMY = LVM_MAXINT_32 /* Force 32 bits enum, don't use it! */
34 } LVPSA_LevelDetectSpeed_en;
35 
36 /* Filter control parameters */
37 typedef struct {
38     LVM_UINT16 CenterFrequency; /* Center frequency of the band-pass filter (in Hz) */
39     LVM_UINT16 QFactor; /* Quality factor of the filter             (in 1/100)               */
40     LVM_INT16 PostGain; /* Postgain to apply after the filtering    (in dB Q16.0)            */
41 
42 } LVPSA_FilterParam_t;
43 
44 /* LVPSA initialization parameters */
45 typedef struct {
46     LVM_UINT16
47             SpectralDataBufferDuration; /* Spectral data buffer duration in time (ms in Q16.0) */
48     LVM_UINT16 MaxInputBlockSize;       /* Maximum expected input block size (in samples)       */
49     LVM_UINT16 nBands; /* Number of bands of the SA                                         */
50     LVPSA_FilterParam_t*
51             pFiltersParams; /* Points to nBands filter param structures for filters settings     */
52 
53 } LVPSA_InitParams_t, *pLVPSA_InitParams_t;
54 
55 /* LVPSA control parameters */
56 typedef struct {
57     LVM_Fs_en Fs; /* Input sampling rate                                               */
58     LVPSA_LevelDetectSpeed_en LevelDetectionSpeed; /* Level detection speed */
59 
60 } LVPSA_ControlParams_t, *pLVPSA_ControlParams_t;
61 
62 /* Audio time type */
63 typedef LVM_INT32 LVPSA_Time;
64 
65 /* Module instance Handle */
66 typedef void* pLVPSA_Handle_t;
67 
68 /* LVPSA return codes */
69 typedef enum {
70     LVPSA_OK, /* The function ran without any problem                              */
71     LVPSA_ERROR_INVALIDPARAM, /* A parameter is incorrect */
72     LVPSA_ERROR_WRONGTIME,   /* An incorrect AudioTime is used                                    */
73     LVPSA_ERROR_NULLADDRESS, /* A pointer has a NULL value                                        */
74     LVPSA_RETURN_DUMMY = LVM_MAXINT_32 /* Force 32 bits enum, don't use it! */
75 } LVPSA_RETURN;
76 
77 /*********************************************************************************************************************************
78    FUNCTIONS PROTOTYPE
79 **********************************************************************************************************************************/
80 /************************************************************************************/
81 /*                                                                                  */
82 /* FUNCTION:            LVPSA_Init                                                  */
83 /*                                                                                  */
84 /* DESCRIPTION:                                                                     */
85 /*  Create and Initialize the LVPSA module including instance handle                */
86 /*                                                                                  */
87 /*                                                                                  */
88 /* PARAMETERS:                                                                      */
89 /*  phInstance          Pointer to the instance handle                              */
90 /*  InitParams          Init parameters structure                                   */
91 /*  ControlParams       Control parameters structure                                */
92 /*  pScratch            Pointer to bundle scratch memory area                       */
93 /*                                                                                  */
94 /*                                                                                  */
95 /* RETURNS:                                                                         */
96 /*  LVPSA_OK            Succeeds                                                    */
97 /*  otherwise           Error due to bad parameters                                 */
98 /*                                                                                  */
99 /************************************************************************************/
100 LVPSA_RETURN LVPSA_Init(pLVPSA_Handle_t* phInstance, LVPSA_InitParams_t* pInitParams,
101                         LVPSA_ControlParams_t* pControlParams, void* pScratch);
102 
103 /************************************************************************************/
104 /*                                                                                  */
105 /* FUNCTION:            LVPSA_DeInit                                                */
106 /*                                                                                  */
107 /* DESCRIPTION:                                                                     */
108 /*    Free the memories created in LVPSA_Init call including instance handle        */
109 /*                                                                                  */
110 /* PARAMETERS:                                                                      */
111 /*  phInstance          Pointer to the instance handle                              */
112 /*                                                                                  */
113 /************************************************************************************/
114 void LVPSA_DeInit(pLVPSA_Handle_t* phInstance);
115 
116 /*********************************************************************************************************************************/
117 /*                                                                                                                               */
118 /* FUNCTION:            LVPSA_Control */
119 /*                                                                                                                               */
120 /* DESCRIPTION: */
121 /*  Controls the LVPSA module. */
122 /*                                                                                                                               */
123 /* PARAMETERS: */
124 /*  hInstance           Instance Handle */
125 /*  pNewParams          Pointer to the instance new control parameters */
126 /*                                                                                                                               */
127 /* RETURNS: */
128 /*  LVPSA_OK            Succeeds */
129 /*  otherwise           Error due to bad parameters */
130 /*                                                                                                                               */
131 /*********************************************************************************************************************************/
132 LVPSA_RETURN LVPSA_Control(pLVPSA_Handle_t hInstance, LVPSA_ControlParams_t* pNewParams);
133 
134 /*********************************************************************************************************************************/
135 /*                                                                                                                               */
136 /* FUNCTION:            LVPSA_Process */
137 /*                                                                                                                               */
138 /* DESCRIPTION: */
139 /*  The process calculates the levels of the frequency bands. */
140 /*                                                                                                                               */
141 /* PARAMETERS: */
142 /*  hInstance           Instance Handle */
143 /*  pLVPSA_InputSamples Pointer to the input samples buffer */
144 /*  InputBlockSize      Number of mono samples to process */
145 /*  AudioTime           Playback time of the first input sample */
146 /*                                                                                                                               */
147 /*                                                                                                                               */
148 /* RETURNS: */
149 /*  LVPSA_OK            Succeeds */
150 /*  otherwise           Error due to bad parameters */
151 /*                                                                                                                               */
152 /*********************************************************************************************************************************/
153 LVPSA_RETURN LVPSA_Process(pLVPSA_Handle_t hInstance, LVM_FLOAT* pLVPSA_InputSamples,
154                            LVM_UINT16 InputBlockSize, LVPSA_Time AudioTime);
155 /*********************************************************************************************************************************/
156 /*                                                                                                                               */
157 /* FUNCTION:            LVPSA_GetSpectrum */
158 /*                                                                                                                               */
159 /* DESCRIPTION: */
160 /*  This function is used for memory allocation and free. */
161 /*                                                                                                                               */
162 /*                                                                                                                               */
163 /* PARAMETERS: */
164 /*  hInstance            Instance Handle */
165 /*  GetSpectrumAudioTime Time to retrieve the values at */
166 /*  pCurrentValues       Pointer to an empty buffer : Current level values output */
167 /*  pPeakValues          Pointer to an empty buffer : Peak level values output */
168 /*                                                                                                                               */
169 /*                                                                                                                               */
170 /* RETURNS: */
171 /*  LVPSA_OK            Succeeds */
172 /*  otherwise           Error due to bad parameters */
173 /*                                                                                                                               */
174 /*********************************************************************************************************************************/
175 LVPSA_RETURN LVPSA_GetSpectrum(pLVPSA_Handle_t hInstance, LVPSA_Time GetSpectrumAudioTime,
176                                LVM_UINT8* pCurrentValues, LVM_UINT8* pPeakValues);
177 
178 /*********************************************************************************************************************************/
179 /*                                                                                                                               */
180 /* FUNCTION:            LVPSA_GetControlParams */
181 /*                                                                                                                               */
182 /* DESCRIPTION: */
183 /*  Get the current control parameters of the LVPSA module. */
184 /*                                                                                                                               */
185 /* PARAMETERS: */
186 /*  hInstance           Instance Handle */
187 /*  pParams             Pointer to an empty control parameters structure */
188 /* RETURNS: */
189 /*  LVPSA_OK            Succeeds */
190 /*  otherwise           Error due to bad parameters */
191 /*                                                                                                                               */
192 /*********************************************************************************************************************************/
193 LVPSA_RETURN LVPSA_GetControlParams(pLVPSA_Handle_t hInstance, LVPSA_ControlParams_t* pParams);
194 
195 /*********************************************************************************************************************************/
196 /*                                                                                                                               */
197 /* FUNCTION:            LVPSA_GetInitParams */
198 /*                                                                                                                               */
199 /* DESCRIPTION: */
200 /*  Get the initialization parameters of the LVPSA module. */
201 /*                                                                                                                               */
202 /* PARAMETERS: */
203 /*  hInstance           Instance Handle */
204 /*  pParams             Pointer to an empty init parameters structure */
205 /* RETURNS: */
206 /*  LVPSA_OK            Succeeds */
207 /*  otherwise           Error due to bad parameters */
208 /*                                                                                                                               */
209 /*********************************************************************************************************************************/
210 LVPSA_RETURN LVPSA_GetInitParams(pLVPSA_Handle_t hInstance, LVPSA_InitParams_t* pParams);
211 
212 #endif /* _LVPSA_H */
213