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 /****************************************************************************************/
19 /*                                                                                      */
20 /*    Includes                                                                          */
21 /*                                                                                      */
22 /****************************************************************************************/
23 
24 #include "LVM_Private.h"
25 #include "LVM_Tables.h"
26 
27 /****************************************************************************************/
28 /*                                                                                      */
29 /* FUNCTION:                LVM_GetSpectrum                                             */
30 /*                                                                                      */
31 /* DESCRIPTION:                                                                         */
32 /* This function is used to retrieve Spectral information at a given Audio time         */
33 /* for display usage                                                                    */
34 /*                                                                                      */
35 /* PARAMETERS:                                                                          */
36 /*  hInstance               Instance Handle                                             */
37 /*  pCurrentPeaks           Pointer to location where currents peaks are to be saved    */
38 /*  pPastPeaks              Pointer to location where past peaks are to be saved        */
39 /*  AudioTime               Audio time at which the spectral information is needed      */
40 /*                                                                                      */
41 /* RETURNS:                                                                             */
42 /*  LVM_SUCCESS             Succeeded                                                   */
43 /*  LVM_NULLADDRESS         If any of input addresses are NULL                          */
44 /*  LVM_WRONGAUDIOTIME      Failure due to audio time error                             */
45 /*                                                                                      */
46 /* NOTES:                                                                               */
47 /*  1. This function may be interrupted by the LVM_Process function                     */
48 /*                                                                                      */
49 /****************************************************************************************/
LVM_GetSpectrum(LVM_Handle_t hInstance,LVM_UINT8 * pCurrentPeaks,LVM_UINT8 * pPastPeaks,LVM_INT32 AudioTime)50 LVM_ReturnStatus_en LVM_GetSpectrum(
51                                     LVM_Handle_t            hInstance,
52                                     LVM_UINT8               *pCurrentPeaks,
53                                     LVM_UINT8               *pPastPeaks,
54                                     LVM_INT32               AudioTime
55                                     )
56 {
57     LVM_Instance_t           *pInstance   = (LVM_Instance_t  *)hInstance;
58 
59     pLVPSA_Handle_t        *hPSAInstance;
60     LVPSA_RETURN           LVPSA_Status;
61 
62     if(pInstance == LVM_NULL)
63     {
64         return LVM_NULLADDRESS;
65     }
66 
67     /*If PSA is not included at the time of instance creation, return without any processing*/
68     if(pInstance->InstParams.PSA_Included!=LVM_PSA_ON)
69     {
70         return LVM_SUCCESS;
71     }
72 
73     hPSAInstance = (pLVPSA_Handle_t *)pInstance->hPSAInstance;
74 
75     if((pCurrentPeaks == LVM_NULL) ||
76         (pPastPeaks == LVM_NULL))
77     {
78         return LVM_NULLADDRESS;
79     }
80 
81     /*
82      * Update new parameters if necessary
83      */
84     if (pInstance->ControlPending == LVM_TRUE)
85     {
86         LVM_ApplyNewSettings(hInstance);
87     }
88 
89     /* If PSA module is disabled, do nothing */
90     if(pInstance->Params.PSA_Enable==LVM_PSA_OFF)
91     {
92         return LVM_ALGORITHMDISABLED;
93     }
94 
95     LVPSA_Status = LVPSA_GetSpectrum(hPSAInstance,
96                             (LVPSA_Time) (AudioTime),
97                             (LVM_UINT8*) pCurrentPeaks,
98                             (LVM_UINT8*) pPastPeaks );
99 
100     if(LVPSA_Status != LVPSA_OK)
101     {
102         if(LVPSA_Status == LVPSA_ERROR_WRONGTIME)
103         {
104             return (LVM_ReturnStatus_en) LVM_WRONGAUDIOTIME;
105         }
106         else
107         {
108             return (LVM_ReturnStatus_en) LVM_NULLADDRESS;
109         }
110     }
111 
112     return(LVM_SUCCESS);
113 }
114 
115 /****************************************************************************************/
116 /*                                                                                      */
117 /* FUNCTION:                LVM_SetVolumeNoSmoothing                                    */
118 /*                                                                                      */
119 /* DESCRIPTION:                                                                         */
120 /* This function is used to set output volume without any smoothing                     */
121 /*                                                                                      */
122 /* PARAMETERS:                                                                          */
123 /*  hInstance               Instance Handle                                             */
124 /*  pParams                 Control Parameters, only volume value is used here          */
125 /*                                                                                      */
126 /* RETURNS:                                                                             */
127 /*  LVM_SUCCESS             Succeeded                                                   */
128 /*  LVM_NULLADDRESS         If any of input addresses are NULL                          */
129 /*  LVM_OUTOFRANGE          When any of the control parameters are out of range         */
130 /*                                                                                      */
131 /* NOTES:                                                                               */
132 /*  1. This function may be interrupted by the LVM_Process function                     */
133 /*                                                                                      */
134 /****************************************************************************************/
LVM_SetVolumeNoSmoothing(LVM_Handle_t hInstance,LVM_ControlParams_t * pParams)135 LVM_ReturnStatus_en LVM_SetVolumeNoSmoothing( LVM_Handle_t           hInstance,
136                                               LVM_ControlParams_t    *pParams)
137 {
138     LVM_Instance_t      *pInstance =(LVM_Instance_t  *)hInstance;
139     LVM_ReturnStatus_en Error;
140 
141     /*Apply new controls*/
142     Error = LVM_SetControlParameters(hInstance,pParams);
143     pInstance->NoSmoothVolume = LVM_TRUE;
144     return Error;
145 }
146 
147