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    INCLUDE FILES
20 ***********************************************************************************/
21 
22 #include "Mixer_private.h"
23 #include "VectorArithmetic.h"
24 
25 /**********************************************************************************
26    DEFINITIONS
27 ***********************************************************************************/
28 
29 #define TRUE          1
30 #define FALSE         0
31 
32 /**********************************************************************************
33    FUNCTION MIXINSOFT_D32C31_SAT
34 ***********************************************************************************/
MixInSoft_D32C31_SAT(Mix_1St_Cll_FLOAT_t * pInstance,const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 n)35 void MixInSoft_D32C31_SAT( Mix_1St_Cll_FLOAT_t        *pInstance,
36                            const LVM_FLOAT      *src,
37                            LVM_FLOAT      *dst,
38                            LVM_INT16      n)
39 {
40     char HardMixing = TRUE;
41 
42     if(n <= 0)    return;
43 
44     /******************************************************************************
45        SOFT MIXING
46     *******************************************************************************/
47     if (pInstance->Current != pInstance->Target)
48     {
49         if(pInstance->Alpha == 0){
50             pInstance->Current = pInstance->Target;
51         }else if ((pInstance->Current-pInstance->Target < POINT_ZERO_ONE_DB_FLOAT) &&
52                  (pInstance->Current-pInstance->Target > -POINT_ZERO_ONE_DB_FLOAT)){
53             pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
54                                                        Make them equal. */
55         }else{
56             /* Soft mixing has to be applied */
57             HardMixing = FALSE;
58             Core_MixInSoft_D32C31_SAT(pInstance, src, dst, n);
59         }
60     }
61 
62     /******************************************************************************
63        HARD MIXING
64     *******************************************************************************/
65 
66     if (HardMixing){
67         if (pInstance->Target != 0){ /* Nothing to do in case Target = 0 */
68             if ((pInstance->Target) == 1.0f)
69                 Add2_Sat_Float(src, dst, n);
70             else{
71                 Core_MixInSoft_D32C31_SAT(pInstance, src, dst, n);
72                 pInstance->Current = pInstance->Target; /* In case the core function would \
73                                                            have changed the Current value */
74             }
75         }
76     }
77 
78     /******************************************************************************
79        CALL BACK
80     *******************************************************************************/
81     /* Call back before the hard mixing, because in this case, hard mixing makes
82        use of the core soft mix function which can change the Current value!      */
83 
84     if (pInstance->CallbackSet){
85         if ((pInstance->Current - pInstance->Target < POINT_ZERO_ONE_DB_FLOAT) &&
86             (pInstance->Current - pInstance->Target > -POINT_ZERO_ONE_DB_FLOAT)){
87             pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
88                                                        Make them equal. */
89             pInstance->CallbackSet = FALSE;
90             if (pInstance->pCallBack != 0){
91                 (*pInstance->pCallBack) ( pInstance->pCallbackHandle,
92                                           pInstance->pGeneralPurpose,
93                                           pInstance->CallbackParam );
94             }
95         }
96     }
97 }
98 /**********************************************************************************/
99