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 #include "LVC_Mixer_Private.h"
22 #include "LVM_Macros.h"
23 #include "ScalarArithmetic.h"
24
25 /**********************************************************************************
26 FUNCTION LVCore_MIXSOFT_1ST_D16C31_WRA
27 ***********************************************************************************/
LVC_Core_MixSoft_1St_D16C31_WRA(LVMixer3_FLOAT_st * ptrInstance,const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 n)28 void LVC_Core_MixSoft_1St_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance, const LVM_FLOAT* src,
29 LVM_FLOAT* dst, LVM_INT16 n) {
30 LVM_INT16 OutLoop;
31 LVM_INT16 InLoop;
32 LVM_INT32 ii;
33 Mix_Private_FLOAT_st* pInstance = (Mix_Private_FLOAT_st*)(ptrInstance->PrivateParams);
34 LVM_FLOAT Delta = (LVM_FLOAT)pInstance->Delta;
35 LVM_FLOAT Current = (LVM_FLOAT)pInstance->Current;
36 LVM_FLOAT Target = (LVM_FLOAT)pInstance->Target;
37
38 InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */
39 OutLoop = (LVM_INT16)(n - (InLoop << 2));
40
41 if (Current < Target) {
42 if (OutLoop) {
43 Current = LVM_Clamp(Current + Delta);
44 if (Current > Target) Current = Target;
45
46 for (ii = OutLoop; ii != 0; ii--) {
47 *(dst++) = (((LVM_FLOAT) * (src++) * (LVM_FLOAT)Current));
48 }
49 }
50
51 for (ii = InLoop; ii != 0; ii--) {
52 Current = LVM_Clamp(Current + Delta);
53
54 if (Current > Target) Current = Target;
55
56 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
57 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
58 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
59 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
60 }
61 } else {
62 if (OutLoop) {
63 Current -= Delta;
64 if (Current < Target) Current = Target;
65
66 for (ii = OutLoop; ii != 0; ii--) {
67 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
68 }
69 }
70
71 for (ii = InLoop; ii != 0; ii--) {
72 Current -= Delta;
73 if (Current < Target) Current = Target;
74
75 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
76 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
77 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
78 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
79 }
80 }
81 pInstance->Current = Current;
82 }
83
84 /*
85 * FUNCTION: LVC_Core_MixSoft_Mc_D16C31_WRA
86 *
87 * DESCRIPTION:
88 * Mixer function with support for processing multichannel input
89 *
90 * PARAMETERS:
91 * ptrInstance Instance pointer
92 * src Source
93 * dst Destination
94 * NrFrames Number of frames
95 * NrChannels Number of channels
96 *
97 * RETURNS:
98 * void
99 *
100 */
LVC_Core_MixSoft_Mc_D16C31_WRA(LVMixer3_FLOAT_st * ptrInstance,const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 NrFrames,LVM_INT16 NrChannels)101 void LVC_Core_MixSoft_Mc_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance, const LVM_FLOAT* src,
102 LVM_FLOAT* dst, LVM_INT16 NrFrames, LVM_INT16 NrChannels) {
103 LVM_INT16 OutLoop;
104 LVM_INT16 InLoop;
105 LVM_INT32 ii, jj;
106 Mix_Private_FLOAT_st* pInstance = (Mix_Private_FLOAT_st*)(ptrInstance->PrivateParams);
107 LVM_FLOAT Delta = (LVM_FLOAT)pInstance->Delta;
108 LVM_FLOAT Current = (LVM_FLOAT)pInstance->Current;
109 LVM_FLOAT Target = (LVM_FLOAT)pInstance->Target;
110
111 /*
112 * Same operation is performed on consecutive frames.
113 * So two frames are processed in one iteration and
114 * the loop will run only for half the NrFrames value times.
115 */
116 InLoop = (LVM_INT16)(NrFrames >> 1);
117 /* OutLoop is calculated to handle cases where NrFrames value can be odd.*/
118 OutLoop = (LVM_INT16)(NrFrames - (InLoop << 1));
119
120 if (Current < Target) {
121 if (OutLoop) {
122 Current = LVM_Clamp(Current + Delta);
123 if (Current > Target) Current = Target;
124
125 for (ii = OutLoop; ii != 0; ii--) {
126 for (jj = NrChannels; jj != 0; jj--) {
127 *(dst++) = (((LVM_FLOAT) * (src++) * (LVM_FLOAT)Current));
128 }
129 }
130 }
131
132 for (ii = InLoop; ii != 0; ii--) {
133 Current = LVM_Clamp(Current + Delta);
134 if (Current > Target) Current = Target;
135
136 for (jj = NrChannels; jj != 0; jj--) {
137 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
138 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
139 }
140 }
141 } else {
142 if (OutLoop) {
143 Current -= Delta;
144 if (Current < Target) Current = Target;
145
146 for (ii = OutLoop; ii != 0; ii--) {
147 for (jj = NrChannels; jj != 0; jj--) {
148 *(dst++) = (((LVM_FLOAT) * (src++) * (LVM_FLOAT)Current));
149 }
150 }
151 }
152
153 for (ii = InLoop; ii != 0; ii--) {
154 Current -= Delta;
155 if (Current < Target) Current = Target;
156
157 for (jj = NrChannels; jj != 0; jj--) {
158 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
159 *(dst++) = (((LVM_FLOAT) * (src++) * Current));
160 }
161 }
162 }
163 pInstance->Current = Current;
164 }
165
166 /**********************************************************************************/
167