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 LVMixer3_MIXSOFT_1ST_D16C31_SAT
35 ***********************************************************************************/
36 #ifdef BUILD_FLOAT
LVC_MixSoft_1St_D16C31_SAT(LVMixer3_1St_FLOAT_st * ptrInstance,const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 n)37 void LVC_MixSoft_1St_D16C31_SAT( LVMixer3_1St_FLOAT_st *ptrInstance,
38 const LVM_FLOAT *src,
39 LVM_FLOAT *dst,
40 LVM_INT16 n)
41 {
42 char HardMixing = TRUE;
43 LVM_FLOAT TargetGain;
44 Mix_Private_FLOAT_st *pInstance = \
45 (Mix_Private_FLOAT_st *)(ptrInstance->MixerStream[0].PrivateParams);
46
47 if(n <= 0) return;
48
49 /******************************************************************************
50 SOFT MIXING
51 *******************************************************************************/
52 if (pInstance->Current != pInstance->Target)
53 {
54 if(pInstance->Delta == 1.0f){
55 pInstance->Current = pInstance->Target;
56 TargetGain = pInstance->Target;
57 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]), TargetGain);
58 }else if (Abs_Float(pInstance->Current - pInstance->Target) < pInstance->Delta){
59 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
60 Make them equal. */
61 TargetGain = pInstance->Target;
62 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]), TargetGain);
63 }else{
64 /* Soft mixing has to be applied */
65 HardMixing = FALSE;
66 LVC_Core_MixSoft_1St_D16C31_WRA(&(ptrInstance->MixerStream[0]), src, dst, n);
67 }
68 }
69
70 /******************************************************************************
71 HARD MIXING
72 *******************************************************************************/
73
74 if (HardMixing){
75 if (pInstance->Target == 0)
76 LoadConst_Float(0.0, dst, n);
77 else {
78 if ((pInstance->Target) != 1.0f)
79 Mult3s_Float(src, (pInstance->Target), dst, n);
80 else if(src != dst)
81 Copy_Float(src, dst, n);
82 }
83
84 }
85
86 /******************************************************************************
87 CALL BACK
88 *******************************************************************************/
89
90 if (ptrInstance->MixerStream[0].CallbackSet){
91 if (Abs_Float(pInstance->Current - pInstance->Target) < pInstance->Delta){
92 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
93 Make them equal. */
94 TargetGain = pInstance->Target;
95 LVC_Mixer_SetTarget(ptrInstance->MixerStream, TargetGain);
96 ptrInstance->MixerStream[0].CallbackSet = FALSE;
97 if (ptrInstance->MixerStream[0].pCallBack != 0){
98 (*ptrInstance->MixerStream[0].pCallBack) ( \
99 ptrInstance->MixerStream[0].pCallbackHandle,
100 ptrInstance->MixerStream[0].pGeneralPurpose,
101 ptrInstance->MixerStream[0].CallbackParam );
102 }
103 }
104 }
105 }
106 #else
LVC_MixSoft_1St_D16C31_SAT(LVMixer3_1St_st * ptrInstance,const LVM_INT16 * src,LVM_INT16 * dst,LVM_INT16 n)107 void LVC_MixSoft_1St_D16C31_SAT( LVMixer3_1St_st *ptrInstance,
108 const LVM_INT16 *src,
109 LVM_INT16 *dst,
110 LVM_INT16 n)
111 {
112 char HardMixing = TRUE;
113 LVM_INT32 TargetGain;
114 Mix_Private_st *pInstance=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams);
115
116 if(n<=0) return;
117
118 /******************************************************************************
119 SOFT MIXING
120 *******************************************************************************/
121 if (pInstance->Current != pInstance->Target)
122 {
123 if(pInstance->Delta == 0x7FFFFFFF){
124 pInstance->Current = pInstance->Target;
125 TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format
126 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain);
127 }else if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){
128 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */
129 TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format
130 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain);
131 }else{
132 /* Soft mixing has to be applied */
133 HardMixing = FALSE;
134 if(pInstance->Shift!=0){
135 Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,dst,n);
136 LVC_Core_MixSoft_1St_D16C31_WRA( &(ptrInstance->MixerStream[0]), dst, dst, n);
137 }
138 else
139 LVC_Core_MixSoft_1St_D16C31_WRA( &(ptrInstance->MixerStream[0]), src, dst, n);
140 }
141 }
142
143 /******************************************************************************
144 HARD MIXING
145 *******************************************************************************/
146
147 if (HardMixing){
148 if (pInstance->Target == 0)
149 LoadConst_16(0, dst, n);
150 else if(pInstance->Shift!=0){
151 Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,dst,n);
152 if ((pInstance->Target>>16) != 0x7FFF)
153 Mult3s_16x16( dst, (LVM_INT16)(pInstance->Target>>16), dst, n );
154 }
155 else {
156 if ((pInstance->Target>>16) != 0x7FFF)
157 Mult3s_16x16( src, (LVM_INT16)(pInstance->Target>>16), dst, n );
158 else if(src!=dst)
159 Copy_16(src, dst, n);
160 }
161
162 }
163
164 /******************************************************************************
165 CALL BACK
166 *******************************************************************************/
167
168 if (ptrInstance->MixerStream[0].CallbackSet){
169 if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){
170 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */
171 TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format
172 LVC_Mixer_SetTarget(ptrInstance->MixerStream,TargetGain);
173 ptrInstance->MixerStream[0].CallbackSet = FALSE;
174 if (ptrInstance->MixerStream[0].pCallBack != 0){
175 (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam );
176 }
177 }
178 }
179 }
180 #endif/*BUILD_FLOAT*/
181 /**********************************************************************************/
182