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