summaryrefslogtreecommitdiffstats
path: root/media/libeffects/lvm/lib/SpectrumAnalyzer/lib/LVPSA.h
blob: b9903b260e2f74c101b186908ba6c1a2cc51735f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
 * Copyright (C) 2004-2010 NXP Software
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/************************************************************************/
/*                                                                      */
/*     Project::   PSA_01_ARMC_01                                       */
/*     $Author: beq07716 $*/
/*     $Revision: 1006 $*/
/*     $Date: 2010-06-28 14:01:47 +0200 (Mon, 28 Jun 2010) $*/
/*                                                                      */
/************************************************************************/
#ifndef _LVPSA_H_
#define _LVPSA_H_


#include "LVM_Types.h"


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/****************************************************************************************/
/*                                                                                      */
/*  CONSTANTS DEFINITIONS                                                               */
/*                                                                                      */
/****************************************************************************************/

/* Memory table*/
#define     LVPSA_NR_MEMORY_REGIONS                  4      /* Number of memory regions                                          */

/****************************************************************************************/
/*                                                                                      */
/*  TYPES DEFINITIONS                                                                   */
/*                                                                                      */
/****************************************************************************************/
/* Memory Types */
typedef enum
{
    LVPSA_PERSISTENT      = LVM_PERSISTENT,
    LVPSA_PERSISTENT_DATA = LVM_PERSISTENT_DATA,
    LVPSA_PERSISTENT_COEF = LVM_PERSISTENT_COEF,
    LVPSA_SCRATCH         = LVM_SCRATCH,
    LVPSA_MEMORY_DUMMY = LVM_MAXINT_32                      /* Force 32 bits enum, don't use it!                                 */
} LVPSA_MemoryTypes_en;

/* Level detection speed control parameters */
typedef enum
{
    LVPSA_SPEED_LOW,                                        /* Low speed level   detection                                       */
    LVPSA_SPEED_MEDIUM,                                     /* Medium speed level   detection                                    */
    LVPSA_SPEED_HIGH,                                       /* High speed level   detection                                      */
    LVPSA_SPEED_DUMMY = LVM_MAXINT_32                       /* Force 32 bits enum, don't use it!                                 */
} LVPSA_LevelDetectSpeed_en;

/* Filter control parameters */
typedef struct
{
    LVM_UINT16                 CenterFrequency;             /* Center frequency of the band-pass filter (in Hz)                  */
    LVM_UINT16                 QFactor;                     /* Quality factor of the filter             (in 1/100)               */
    LVM_INT16                  PostGain;                    /* Postgain to apply after the filtering    (in dB Q16.0)            */

} LVPSA_FilterParam_t;

/* LVPSA initialization parameters */
typedef struct
{
    LVM_UINT16                 SpectralDataBufferDuration;  /* Spectral data buffer duration in time (ms in Q16.0)               */
    LVM_UINT16                 MaxInputBlockSize;           /* Maximum expected input block size (in samples)                    */
    LVM_UINT16                 nBands;                      /* Number of bands of the SA                                         */
    LVPSA_FilterParam_t       *pFiltersParams;              /* Points to nBands filter param structures for filters settings     */

} LVPSA_InitParams_t, *pLVPSA_InitParams_t;

/* LVPSA control parameters */
typedef struct
{
    LVM_Fs_en                  Fs;                          /* Input sampling rate                                               */
    LVPSA_LevelDetectSpeed_en  LevelDetectionSpeed;         /* Level detection speed                                             */

} LVPSA_ControlParams_t, *pLVPSA_ControlParams_t;

/* Memory region definition */
typedef struct
{
    LVM_UINT32                 Size;                        /* Region size in bytes                                              */
    LVPSA_MemoryTypes_en       Type;                        /* Region type                                                       */
    void                       *pBaseAddress;               /* Pointer to the region base address                                */
} LVPSA_MemoryRegion_t;

/* Memory table containing the region definitions */
typedef struct
{
    LVPSA_MemoryRegion_t       Region[LVPSA_NR_MEMORY_REGIONS];/* One definition for each region                                 */
} LVPSA_MemTab_t;

/* Audio time type */
typedef LVM_INT32 LVPSA_Time;

/* Module instance Handle */
typedef void *pLVPSA_Handle_t;

/* LVPSA return codes */
typedef enum
{
    LVPSA_OK,                                               /* The function ran without any problem                              */
    LVPSA_ERROR_INVALIDPARAM,                               /* A parameter is incorrect                                          */
    LVPSA_ERROR_WRONGTIME,                                  /* An incorrect AudioTime is used                                    */
    LVPSA_ERROR_NULLADDRESS,                                /* A pointer has a NULL value                                        */
    LVPSA_RETURN_DUMMY = LVM_MAXINT_32                      /* Force 32 bits enum, don't use it!                                 */
} LVPSA_RETURN;



/*********************************************************************************************************************************
   FUNCTIONS PROTOTYPE
**********************************************************************************************************************************/
/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_Memory                                                                                         */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  This function is used for memory allocation and free. It can be called in                                                    */
/*  two ways:                                                                                                                    */
/*                                                                                                                               */
/*      hInstance = NULL                Returns the memory requirements                                                          */
/*      hInstance = Instance handle     Returns the memory requirements and                                                      */
/*                                      allocated base addresses for the instance                                                */
/*                                                                                                                               */
/*  When this function is called for memory allocation (hInstance=NULL) the memory                                               */
/*  base address pointers are NULL on return.                                                                                    */
/*                                                                                                                               */
/*  When the function is called for free (hInstance = Instance Handle) the memory                                                */
/*  table returns the allocated memory and base addresses used during initialisation.                                            */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  hInstance           Instance Handle                                                                                          */
/*  pMemoryTable        Pointer to an empty memory definition table                                                              */
/*  pInitParams         Pointer to the instance init parameters                                                                  */
/*                                                                                                                               */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_Memory            ( pLVPSA_Handle_t             hInstance,
                                       LVPSA_MemTab_t             *pMemoryTable,
                                       LVPSA_InitParams_t         *pInitParams    );

/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_Init                                                                                               */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  Initializes the LVPSA module.                                                                                                */
/*                                                                                                                               */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  phInstance          Pointer to the instance Handle                                                                           */
/*  pInitParams         Pointer to the instance init parameters                                                                  */
/*  pControlParams      Pointer to the instance control parameters                                                               */
/*  pMemoryTable        Pointer to the memory definition table                                                                   */
/*                                                                                                                               */
/*                                                                                                                               */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_Init              ( pLVPSA_Handle_t             *phInstance,
                                       LVPSA_InitParams_t          *pInitParams,
                                       LVPSA_ControlParams_t       *pControlParams,
                                       LVPSA_MemTab_t              *pMemoryTable  );

/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_Control                                                                                            */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  Controls the LVPSA module.                                                                                                   */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  hInstance           Instance Handle                                                                                          */
/*  pNewParams          Pointer to the instance new control parameters                                                           */
/*                                                                                                                               */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_Control           ( pLVPSA_Handle_t             hInstance,
                                       LVPSA_ControlParams_t      *pNewParams     );

/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_Process                                                                                            */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  The process calculates the levels of the frequency bands.                                                                    */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  hInstance           Instance Handle                                                                                          */
/*  pLVPSA_InputSamples Pointer to the input samples buffer                                                                      */
/*  InputBlockSize      Number of mono samples to process                                                                        */
/*  AudioTime           Playback time of the first input sample                                                                  */
/*                                                                                                                               */
/*                                                                                                                               */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_Process           ( pLVPSA_Handle_t      hInstance,
                                       LVM_INT16           *pLVPSA_InputSamples,
                                       LVM_UINT16           InputBlockSize,
                                       LVPSA_Time           AudioTime             );

/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_GetSpectrum                                                                                        */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  This function is used for memory allocation and free.                                                                        */
/*                                                                                                                               */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  hInstance            Instance Handle                                                                                         */
/*  GetSpectrumAudioTime Time to retrieve the values at                                                                          */
/*  pCurrentValues       Pointer to an empty buffer : Current level values output                                                */
/*  pPeakValues          Pointer to an empty buffer : Peak level values output                                                   */
/*                                                                                                                               */
/*                                                                                                                               */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_GetSpectrum       ( pLVPSA_Handle_t      hInstance,
                                       LVPSA_Time           GetSpectrumAudioTime,
                                       LVM_UINT8           *pCurrentValues,
                                       LVM_UINT8           *pPeakValues           );

/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_GetControlParams                                                                                   */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  Get the current control parameters of the LVPSA module.                                                                      */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  hInstance           Instance Handle                                                                                          */
/*  pParams             Pointer to an empty control parameters structure                                                         */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_GetControlParams  (    pLVPSA_Handle_t            hInstance,
                                          LVPSA_ControlParams_t     *pParams      );

/*********************************************************************************************************************************/
/*                                                                                                                               */
/* FUNCTION:            LVPSA_GetInitParams                                                                                      */
/*                                                                                                                               */
/* DESCRIPTION:                                                                                                                  */
/*  Get the initialization parameters of the LVPSA module.                                                                       */
/*                                                                                                                               */
/* PARAMETERS:                                                                                                                   */
/*  hInstance           Instance Handle                                                                                          */
/*  pParams             Pointer to an empty init parameters structure                                                            */
/* RETURNS:                                                                                                                      */
/*  LVPSA_OK            Succeeds                                                                                                 */
/*  otherwise           Error due to bad parameters                                                                              */
/*                                                                                                                               */
/*********************************************************************************************************************************/
LVPSA_RETURN LVPSA_GetInitParams     (    pLVPSA_Handle_t            hInstance,
                                          LVPSA_InitParams_t        *pParams      );


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _LVPSA_H */