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 LVC_MixSoft_1St_2i_D16C31_SAT
35 ***********************************************************************************/
36
LVC_MixSoft_1St_2i_D16C31_SAT(LVMixer3_2St_st * ptrInstance,const LVM_INT16 * src,LVM_INT16 * dst,LVM_INT16 n)37 void LVC_MixSoft_1St_2i_D16C31_SAT( LVMixer3_2St_st *ptrInstance,
38 const LVM_INT16 *src,
39 LVM_INT16 *dst,
40 LVM_INT16 n)
41 {
42 char HardMixing = TRUE;
43 LVM_INT32 TargetGain;
44 Mix_Private_st *pInstance1=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams);
45 Mix_Private_st *pInstance2=(Mix_Private_st *)(ptrInstance->MixerStream[1].PrivateParams);
46
47 if(n<=0) return;
48
49 /******************************************************************************
50 SOFT MIXING
51 *******************************************************************************/
52 if ((pInstance1->Current != pInstance1->Target)||(pInstance2->Current != pInstance2->Target))
53 {
54 if(pInstance1->Delta == 0x7FFFFFFF)
55 {
56 pInstance1->Current = pInstance1->Target;
57 TargetGain=pInstance1->Target>>16; // TargetGain in Q16.15 format, no integer part
58 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain);
59 }
60 else if (Abs_32(pInstance1->Current-pInstance1->Target) < pInstance1->Delta)
61 {
62 pInstance1->Current = pInstance1->Target; /* Difference is not significant anymore. Make them equal. */
63 TargetGain=pInstance1->Target>>16; // TargetGain in Q16.15 format, no integer part
64 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain);
65 }
66 else
67 {
68 /* Soft mixing has to be applied */
69 HardMixing = FALSE;
70 }
71
72 if(HardMixing == TRUE)
73 {
74 if(pInstance2->Delta == 0x7FFFFFFF)
75 {
76 pInstance2->Current = pInstance2->Target;
77 TargetGain=pInstance2->Target>>16; // TargetGain in Q16.15 format, no integer part
78 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[1]),TargetGain);
79 }
80 else if (Abs_32(pInstance2->Current-pInstance2->Target) < pInstance2->Delta)
81 {
82 pInstance2->Current = pInstance2->Target; /* Difference is not significant anymore. Make them equal. */
83 TargetGain=pInstance2->Target>>16; // TargetGain in Q16.15 format, no integer part
84 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[1]),TargetGain);
85 }
86 else
87 {
88 /* Soft mixing has to be applied */
89 HardMixing = FALSE;
90 }
91 }
92
93 if(HardMixing == FALSE)
94 {
95 LVC_Core_MixSoft_1St_2i_D16C31_WRA( &(ptrInstance->MixerStream[0]),&(ptrInstance->MixerStream[1]), src, dst, n);
96 }
97 }
98
99 /******************************************************************************
100 HARD MIXING
101 *******************************************************************************/
102
103 if (HardMixing)
104 {
105 if (((pInstance1->Target>>16) == 0x7FFF)&&((pInstance2->Target>>16) == 0x7FFF))
106 {
107 if(src!=dst)
108 {
109 Copy_16(src, dst, n);
110 }
111 }
112 else
113 {
114 LVC_Core_MixHard_1St_2i_D16C31_SAT(&(ptrInstance->MixerStream[0]),&(ptrInstance->MixerStream[1]), src, dst, n);
115 }
116 }
117
118 /******************************************************************************
119 CALL BACK
120 *******************************************************************************/
121
122 if (ptrInstance->MixerStream[0].CallbackSet)
123 {
124 if (Abs_32(pInstance1->Current-pInstance1->Target) < pInstance1->Delta)
125 {
126 pInstance1->Current = pInstance1->Target; /* Difference is not significant anymore. Make them equal. */
127 TargetGain=pInstance1->Target>>(16-pInstance1->Shift); // TargetGain in Q16.15 format
128 LVC_Mixer_SetTarget(&ptrInstance->MixerStream[0],TargetGain);
129 ptrInstance->MixerStream[0].CallbackSet = FALSE;
130 if (ptrInstance->MixerStream[0].pCallBack != 0)
131 {
132 (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam );
133 }
134 }
135 }
136 if (ptrInstance->MixerStream[1].CallbackSet)
137 {
138 if (Abs_32(pInstance2->Current-pInstance2->Target) < pInstance2->Delta)
139 {
140 pInstance2->Current = pInstance2->Target; /* Difference is not significant anymore. Make them equal. */
141 TargetGain=pInstance2->Target>>(16-pInstance2->Shift); // TargetGain in Q16.15 format
142 LVC_Mixer_SetTarget(&ptrInstance->MixerStream[1],TargetGain);
143 ptrInstance->MixerStream[1].CallbackSet = FALSE;
144 if (ptrInstance->MixerStream[1].pCallBack != 0)
145 {
146 (*ptrInstance->MixerStream[1].pCallBack) ( ptrInstance->MixerStream[1].pCallbackHandle, ptrInstance->MixerStream[1].pGeneralPurpose,ptrInstance->MixerStream[1].CallbackParam );
147 }
148 }
149 }
150 }
151
152 /**********************************************************************************/
153