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 "LVC_Mixer_Private.h"
23 #include "VectorArithmetic.h"
24 #include "ScalarArithmetic.h"
25 
26 /**********************************************************************************
27    DEFINITIONS
28 ***********************************************************************************/
29 
30 #define TRUE          1
31 #define FALSE         0
32 
33 /**********************************************************************************
34    FUNCTION MIXINSOFT_D16C31_SAT
35 ***********************************************************************************/
36 
LVC_MixInSoft_D16C31_SAT(LVMixer3_1St_st * ptrInstance,LVM_INT16 * src,LVM_INT16 * dst,LVM_INT16 n)37 void LVC_MixInSoft_D16C31_SAT( LVMixer3_1St_st *ptrInstance,
38                                     LVM_INT16             *src,
39                                     LVM_INT16             *dst,
40                                     LVM_INT16             n)
41 {
42     char        HardMixing = TRUE;
43     LVM_INT32   TargetGain;
44     Mix_Private_st  *pInstance=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams);
45 
46     if(n<=0)    return;
47 
48     /******************************************************************************
49        SOFT MIXING
50     *******************************************************************************/
51     if (pInstance->Current != pInstance->Target)
52     {
53         if(pInstance->Delta == 0x7FFFFFFF){
54             pInstance->Current = pInstance->Target;
55             TargetGain=pInstance->Target>>(16-pInstance->Shift);  // TargetGain in Q16.15 format
56             LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain);
57         }else if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){
58             pInstance->Current = pInstance->Target; /* Difference is not significant anymore.  Make them equal. */
59             TargetGain=pInstance->Target>>(16-pInstance->Shift);  // TargetGain in Q16.15 format
60             LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain);
61         }else{
62             /* Soft mixing has to be applied */
63             HardMixing = FALSE;
64             if(pInstance->Shift!=0){
65                 Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,src,n);
66                 LVC_Core_MixInSoft_D16C31_SAT( &(ptrInstance->MixerStream[0]), src, dst, n);
67             }
68             else
69                 LVC_Core_MixInSoft_D16C31_SAT( &(ptrInstance->MixerStream[0]), src, dst, n);
70         }
71     }
72 
73     /******************************************************************************
74        HARD MIXING
75     *******************************************************************************/
76 
77     if (HardMixing){
78         if (pInstance->Target != 0){ /* Nothing to do in case Target = 0 */
79             if ((pInstance->Target>>16) == 0x7FFF){
80                 if(pInstance->Shift!=0)
81                     Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,src,n);
82                 Add2_Sat_16x16( src, dst, n );
83             }
84             else{
85                 if(pInstance->Shift!=0)
86                     Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,src,n);
87                 Mac3s_Sat_16x16(src,(LVM_INT16)(pInstance->Target>>16),dst,n);
88                 pInstance->Current = pInstance->Target; /* In case the LVCore function would have changed the Current value */
89             }
90         }
91     }
92 
93 
94     /******************************************************************************
95        CALL BACK
96     *******************************************************************************/
97 
98     if (ptrInstance->MixerStream[0].CallbackSet){
99         if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){
100             pInstance->Current = pInstance->Target; /* Difference is not significant anymore.  Make them equal. */
101             TargetGain=pInstance->Target>>(16-pInstance->Shift);  // TargetGain in Q16.15 format
102             LVC_Mixer_SetTarget(ptrInstance->MixerStream,TargetGain);
103             ptrInstance->MixerStream[0].CallbackSet = FALSE;
104             if (ptrInstance->MixerStream[0].pCallBack != 0){
105                 (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam );
106             }
107         }
108     }
109 
110 }
111 
112 /**********************************************************************************/
113