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 <string.h>
23 #include "LVC_Mixer_Private.h"
24 #include "VectorArithmetic.h"
25 #include "ScalarArithmetic.h"
26
27 /**********************************************************************************
28 DEFINITIONS
29 ***********************************************************************************/
30
31 #define TRUE 1
32 #define FALSE 0
33
34 /**********************************************************************************
35 FUNCTION LVMixer3_MIXSOFT_1ST_D16C31_SAT
36 ***********************************************************************************/
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, const LVM_FLOAT* src,
38 LVM_FLOAT* dst, LVM_INT16 n) {
39 char HardMixing = TRUE;
40 LVM_FLOAT TargetGain;
41 Mix_Private_FLOAT_st* pInstance =
42 (Mix_Private_FLOAT_st*)(ptrInstance->MixerStream[0].PrivateParams);
43
44 if (n <= 0) return;
45
46 /******************************************************************************
47 SOFT MIXING
48 *******************************************************************************/
49 if (pInstance->Current != pInstance->Target) {
50 if (pInstance->Delta == 1.0f) {
51 pInstance->Current = pInstance->Target;
52 TargetGain = pInstance->Target;
53 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]), TargetGain);
54 } else if (Abs_Float(pInstance->Current - pInstance->Target) < pInstance->Delta) {
55 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
56 Make them equal. */
57 TargetGain = pInstance->Target;
58 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]), TargetGain);
59 } else {
60 /* Soft mixing has to be applied */
61 HardMixing = FALSE;
62 LVC_Core_MixSoft_1St_D16C31_WRA(&(ptrInstance->MixerStream[0]), src, dst, n);
63 }
64 }
65
66 /******************************************************************************
67 HARD MIXING
68 *******************************************************************************/
69
70 if (HardMixing) {
71 if (pInstance->Target == 0)
72 memset(dst, 0, n * sizeof(*dst));
73 else {
74 if ((pInstance->Target) != 1.0f)
75 Mult3s_Float(src, (pInstance->Target), dst, n);
76 else if (src != dst)
77 Copy_Float(src, dst, n);
78 }
79 }
80
81 /******************************************************************************
82 CALL BACK
83 *******************************************************************************/
84
85 if (ptrInstance->MixerStream[0].CallbackSet) {
86 if (Abs_Float(pInstance->Current - pInstance->Target) < pInstance->Delta) {
87 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
88 Make them equal. */
89 TargetGain = pInstance->Target;
90 LVC_Mixer_SetTarget(ptrInstance->MixerStream, TargetGain);
91 ptrInstance->MixerStream[0].CallbackSet = FALSE;
92 if (ptrInstance->MixerStream[0].pCallBack != 0) {
93 (*ptrInstance->MixerStream[0].pCallBack)(
94 ptrInstance->MixerStream[0].pCallbackHandle,
95 ptrInstance->MixerStream[0].pGeneralPurpose,
96 ptrInstance->MixerStream[0].CallbackParam);
97 }
98 }
99 }
100 }
101 /*
102 * FUNCTION: LVC_MixSoft_Mc_D16C31_SAT
103 *
104 * DESCRIPTION:
105 * Mixer function with support for processing multichannel input
106 *
107 * PARAMETERS:
108 * ptrInstance Instance pointer
109 * src Source
110 * dst Destination
111 * NrFrames Number of Frames
112 * NrChannels Number of channels
113 *
114 * RETURNS:
115 * void
116 *
117 */
LVC_MixSoft_Mc_D16C31_SAT(LVMixer3_1St_FLOAT_st * ptrInstance,const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 NrFrames,LVM_INT16 NrChannels)118 void LVC_MixSoft_Mc_D16C31_SAT(LVMixer3_1St_FLOAT_st* ptrInstance, const LVM_FLOAT* src,
119 LVM_FLOAT* dst, LVM_INT16 NrFrames, LVM_INT16 NrChannels) {
120 char HardMixing = TRUE;
121 LVM_FLOAT TargetGain;
122 Mix_Private_FLOAT_st* pInstance =
123 (Mix_Private_FLOAT_st*)(ptrInstance->MixerStream[0].PrivateParams);
124
125 if (NrFrames <= 0) return;
126
127 /******************************************************************************
128 SOFT MIXING
129 *******************************************************************************/
130 if (pInstance->Current != pInstance->Target) {
131 if (pInstance->Delta == 1.0f) {
132 pInstance->Current = pInstance->Target;
133 TargetGain = pInstance->Target;
134 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]), TargetGain);
135 } else if (Abs_Float(pInstance->Current - pInstance->Target) < pInstance->Delta) {
136 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
137 Make them equal. */
138 TargetGain = pInstance->Target;
139 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]), TargetGain);
140 } else {
141 /* Soft mixing has to be applied */
142 HardMixing = FALSE;
143 LVC_Core_MixSoft_Mc_D16C31_WRA(&(ptrInstance->MixerStream[0]), src, dst, NrFrames,
144 NrChannels);
145 }
146 }
147
148 /******************************************************************************
149 HARD MIXING
150 *******************************************************************************/
151
152 if (HardMixing) {
153 if (pInstance->Target == 0)
154 memset(dst, 0, NrFrames * NrChannels * sizeof(*dst));
155 else {
156 if ((pInstance->Target) != 1.0f)
157 Mult3s_Float(src, (pInstance->Target), dst, NrFrames * NrChannels);
158 else if (src != dst)
159 Copy_Float(src, dst, NrFrames * NrChannels);
160 }
161 }
162
163 /******************************************************************************
164 CALL BACK
165 *******************************************************************************/
166
167 if (ptrInstance->MixerStream[0].CallbackSet) {
168 if (Abs_Float(pInstance->Current - pInstance->Target) < pInstance->Delta) {
169 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
170 Make them equal. */
171 TargetGain = pInstance->Target;
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)(
176 ptrInstance->MixerStream[0].pCallbackHandle,
177 ptrInstance->MixerStream[0].pGeneralPurpose,
178 ptrInstance->MixerStream[0].CallbackParam);
179 }
180 }
181 }
182 }
183
184 /**********************************************************************************/
185