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