• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /****************************************************************************************/
18 /*                                                                                      */
19 /*     Project::                                                                        */
20 /*     %name:          SSRC.h % */
21 /*                                                                                      */
22 /****************************************************************************************/
23 
24 /*
25     The input and output blocks of the SRC are by default blocks of 40 ms.  This means that
26     the following default block sizes are used:
27 
28           Fs     Default Block size
29         -----        ----------
30          8000           320
31         11025           441
32         12000           480
33         16000           640
34         22050           882
35         24000           960
36         32000          1280
37         44100          1764
38         48000          1920
39 
40     An API is provided to change the default block size into any multiple of the minimal
41     block size.
42 
43     All the sampling rates above are supported as input and as output sampling rate
44 */
45 
46 #ifndef __SSRC_H__
47 #define __SSRC_H__
48 
49 /****************************************************************************************
50    INCLUDES
51 *****************************************************************************************/
52 
53 #include "LVM_Types.h"
54 
55 /****************************************************************************************
56    DEFINITIONS
57 *****************************************************************************************/
58 
59 #define SSRC_INSTANCE_SIZE          548
60 #define SSRC_INSTANCE_ALIGNMENT     4
61 #define SSRC_SCRATCH_ALIGNMENT      4
62 
63 /****************************************************************************************
64    TYPE DEFINITIONS
65 *****************************************************************************************/
66 
67 /* Status return values */
68 typedef enum
69 {
70     SSRC_OK                     = 0,                /* Successful return from a routine */
71     SSRC_INVALID_FS             = 1,                /* The input or the output sampling rate is
72                                                         invalid */
73     SSRC_INVALID_NR_CHANNELS    = 2,                /* The number of channels is not equal to mono
74                                                          or stereo */
75     SSRC_NULL_POINTER           = 3,                /* One of the input pointers is NULL */
76     SSRC_WRONG_NR_SAMPLES       = 4,                /* Invalid number of samples */
77     SSRC_ALLINGMENT_ERROR       = 5,                /* The instance memory or the scratch memory
78                                                         is not alligned */
79     SSRC_INVALID_MODE           = 6,                /* A wrong value has been used for the mode
80                                                         parameter */
81     SSRC_INVALID_VALUE          = 7,                /* An invalid (out of range) value has been
82                                                      used for one of the parameters */
83     LVXXX_RETURNSTATUS_DUMMY = LVM_MAXENUM
84 } SSRC_ReturnStatus_en;
85 
86 /* Instance memory */
87 typedef struct
88 {
89     LVM_INT32 Storage [ SSRC_INSTANCE_SIZE/4 ];
90 } SSRC_Instance_t;
91 
92 /* Scratch memory */
93 typedef LVM_INT32 SSRC_Scratch_t;
94 
95 /* Nuber of samples mode */
96 typedef enum
97 {
98     SSRC_NR_SAMPLES_DEFAULT     = 0,
99     SSRC_NR_SAMPLES_MIN         = 1,
100     SSRC_NR_SAMPLES_DUMMY       = LVM_MAXENUM
101 } SSRC_NR_SAMPLES_MODE_en;
102 
103 /* Instance parameters */
104 typedef struct
105 {
106     LVM_Fs_en           SSRC_Fs_In;
107     LVM_Fs_en           SSRC_Fs_Out;
108     LVM_Format_en       SSRC_NrOfChannels;
109     LVM_INT16           NrSamplesIn;
110     LVM_INT16           NrSamplesOut;
111 } SSRC_Params_t;
112 
113 
114 /****************************************************************************************
115    FUNCTION PROTOTYPES
116 *****************************************************************************************/
117 
118 
119 /****************************************************************************************/
120 /*                                                                                      */
121 /* FUNCTION:                SSRC_GetNrSamples                                           */
122 /*                                                                                      */
123 /* DESCRIPTION:                                                                         */
124 /*  This function retrieves the number of samples (or sample pairs for stereo) to be    */
125 /*  used as input and as output of the SSRC module.                                     */
126 /*                                                                                      */
127 /* PARAMETERS:                                                                          */
128 /*  Mode                    There are two modes:                                        */
129 /*                              - SSRC_NR_SAMPELS_DEFAULT.  In this mode, the function  */
130 /*                                will return the number of samples for 40 ms blocks    */
131 /*                              - SSRC_NR_SAMPELS_MIN will return the minimal number    */
132 /*                                of samples that is supported for this conversion      */
133 /*                                ratio.  Each integer multiple of this ratio will      */
134 /*                                be accepted by the SSRC_Init function                 */
135 /*                                                                                      */
136 /*  pSSRC_Params            pointer to the instance parameters                          */
137 /*                                                                                      */
138 /* RETURNS:                                                                             */
139 /*  SSRC_OK                 Succeeded                                                   */
140 /*  SSRC_INVALID_FS         When the requested input or output sampling rates           */
141 /*                          are invalid.                                                */
142 /*  SSRC_INVALID_NR_CHANNELS When the channel format is not equal to LVM_MONO           */
143 /*                          or LVM_STEREO                                               */
144 /*  SSRC_NULL_POINTER       When pSSRC_Params is a NULL pointer                         */
145 /*  SSRC_INVALID_MODE       When Mode is not a valid setting                            */
146 /*                                                                                      */
147 /*                                                                                      */
148 /* NOTES:                                                                               */
149 /*                                                                                      */
150 /****************************************************************************************/
151 
152 SSRC_ReturnStatus_en SSRC_GetNrSamples( SSRC_NR_SAMPLES_MODE_en  Mode,
153                                         SSRC_Params_t*           pSSRC_Params );
154 
155 
156 /****************************************************************************************/
157 /*                                                                                      */
158 /* FUNCTION:                SSRC_GetScratchSize                                         */
159 /*                                                                                      */
160 /* DESCRIPTION:                                                                         */
161 /*  This function retrieves the scratch size for a given conversion ratio and           */
162 /*  for given buffer sizes at the input and at the output                               */
163 /*                                                                                      */
164 /* PARAMETERS:                                                                          */
165 /*  pSSRC_Params            pointer to the instance parameters                          */
166 /*  pScratchSize            pointer to the scratch size.  The SSRC_GetScratchSize       */
167 /*                          function will fill in the correct value (in bytes).         */
168 /*                                                                                      */
169 /* RETURNS:                                                                             */
170 /*  SSRC_OK                 when the function call succeeds                             */
171 /*  SSRC_INVALID_FS         When the requested input or output sampling rates           */
172 /*                          are invalid.                                                */
173 /*  SSRC_INVALID_NR_CHANNELS When the channel format is not equal to LVM_MONO           */
174 /*                          or LVM_STEREO                                               */
175 /*  SSRC_NULL_POINTER       When any of the input pointers is a NULL pointer            */
176 /*  SSRC_WRONG_NR_SAMPLES   When the number of samples on the input or on the output    */
177 /*                          are incorrect                                               */
178 /*                                                                                      */
179 /* NOTES:                                                                               */
180 /*                                                                                      */
181 /****************************************************************************************/
182 
183 SSRC_ReturnStatus_en SSRC_GetScratchSize(   SSRC_Params_t*    pSSRC_Params,
184                                             LVM_INT32*        pScratchSize );
185 
186 
187 /****************************************************************************************/
188 /*                                                                                      */
189 /* FUNCTION:                SSRC_Init                                                   */
190 /*                                                                                      */
191 /* DESCRIPTION:                                                                         */
192 /*  This function is used to initialize the SSRC module instance.                       */
193 /*                                                                                      */
194 /* PARAMETERS:                                                                          */
195 /*  pSSRC_Instance          Instance pointer                                            */
196 /*                                                                                      */
197 /*  pSSRC_Scratch           pointer to the scratch memory                               */
198 /*  pSSRC_Params            pointer to the instance parameters                          */
199 /*  pInputInScratch,        pointer to a location in the scratch memory that can be     */
200 /*                          used to store the input samples (e.g. to save memory)       */
201 /*  pOutputInScratch        pointer to a location in the scratch memory that can be     */
202 /*                          used to store the output samples (e.g. to save memory)      */
203 /*                                                                                      */
204 /* RETURNS:                                                                             */
205 /*  SSRC_OK                 Succeeded                                                   */
206 /*  SSRC_INVALID_FS         When the requested input or output sampling rates           */
207 /*                          are invalid.                                                */
208 /*  SSRC_INVALID_NR_CHANNELS When the channel format is not equal to LVM_MONO           */
209 /*                          or LVM_STEREO                                               */
210 /*  SSRC_WRONG_NR_SAMPLES   When the number of samples on the input or the output       */
211 /*                          are incorrect                                               */
212 /*  SSRC_NULL_POINTER       When any of the input pointers is a NULL pointer            */
213 /*  SSRC_ALLINGMENT_ERROR   When the instance memory or the scratch memory is not       */
214 /*                          4 bytes alligned                                            */
215 /*                                                                                      */
216 /* NOTES:                                                                               */
217 /*  1. The init function will clear the internal state                                  */
218 /*                                                                                      */
219 /****************************************************************************************/
220 
221 SSRC_ReturnStatus_en SSRC_Init( SSRC_Instance_t* pSSRC_Instance,
222                                 SSRC_Scratch_t*  pSSRC_Scratch,
223                                 SSRC_Params_t*   pSSRC_Params,
224                                 LVM_INT16**      ppInputInScratch,
225                                 LVM_INT16**      ppOutputInScratch);
226 
227 
228 /****************************************************************************************/
229 /*                                                                                      */
230 /* FUNCTION:                SSRC_SetGains                                               */
231 /*                                                                                      */
232 /* DESCRIPTION:                                                                         */
233 /*  This function sets headroom gain and the post gain of the SSRC                      */
234 /*                                                                                      */
235 /* PARAMETERS:                                                                          */
236 /*  bHeadroomGainEnabled    parameter to enable or disable the headroom gain of the     */
237 /*                          SSRC.  The default value is LVM_MODE_ON.  LVM_MODE_OFF      */
238 /*                          can be used in case it can be guaranteed that the input     */
239 /*                          level is below -6dB in all cases (the default headroom      */
240 /*                          is -6 dB)                                                   */
241 /*                                                                                      */
242 /*  bOutputGainEnabled      parameter to enable or disable the output gain.  The        */
243 /*                          default value is LVM_MODE_ON                                */
244 /*                                                                                      */
245 /*  OutputGain              the value of the output gain.  The output gain is a linear  */
246 /*                          gain value. 0x7FFF is equal to +6 dB and 0x0000 corresponds */
247 /*                          to -inf dB.  By default, a 3dB gain is applied, resulting   */
248 /*                          in an overall gain of -3dB (-6dB headroom + 3dB output gain)*/
249 /*                                                                                      */
250 /* RETURNS:                                                                             */
251 /*  SSRC_OK                 Succeeded                                                   */
252 /*  SSRC_NULL_POINTER       When pSSRC_Instance is a NULL pointer                       */
253 /*  SSRC_INVALID_MODE       Wrong value used for the bHeadroomGainEnabled or the        */
254 /*                          bOutputGainEnabled parameters.                              */
255 /*  SSRC_INVALID_VALUE      When OutputGain is out to the range [0;32767]               */
256 /*                                                                                      */
257 /* NOTES:                                                                               */
258 /*  1. The SSRC_SetGains function is an optional function that should only be used      */
259 /*     in rare cases.  Preferably, use the default settings.                            */
260 /*                                                                                      */
261 /****************************************************************************************/
262 
263 SSRC_ReturnStatus_en SSRC_SetGains( SSRC_Instance_t* pSSRC_Instance,
264                                     LVM_Mode_en      bHeadroomGainEnabled,
265                                     LVM_Mode_en      bOutputGainEnabled,
266                                     LVM_INT16        OutputGain );
267 
268 
269 /****************************************************************************************/
270 /*                                                                                      */
271 /* FUNCTION:                SSRC_Process                                                */
272 /*                                                                                      */
273 /* DESCRIPTION:                                                                         */
274 /*  Process function for the SSRC module.                                               */
275 /*                                                                                      */
276 /* PARAMETERS:                                                                          */
277 /*  pSSRC_Instance          Instance pointer                                            */
278 /*  pSSRC_AudioIn           Pointer to the input data                                   */
279 /*  pSSRC_AudioOut          Pointer to the output data                                  */
280 /*                                                                                      */
281 /* RETURNS:                                                                             */
282 /* SSRC_OK                  Succeeded                                                   */
283 /* SSRC_NULL_POINTER        When one of pSSRC_Instance, pSSRC_AudioIn or pSSRC_AudioOut */
284 /*                          is NULL                                                     */
285 /*                                                                                      */
286 /* NOTES:                                                                               */
287 /*                                                                                      */
288 /****************************************************************************************/
289 
290 SSRC_ReturnStatus_en SSRC_Process(  SSRC_Instance_t* pSSRC_Instance,
291                                     LVM_INT16*       pSSRC_AudioIn,
292                                     LVM_INT16*       pSSRC_AudioOut);
293 
294 /****************************************************************************************/
295 
296 #endif /* __SSRC_H__ */
297