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