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 "Mixer_private.h"
23#include "VectorArithmetic.h"
24
25/**********************************************************************************
26   DEFINITIONS
27***********************************************************************************/
28
29#define TRUE          1
30#define FALSE         0
31
32
33
34/**********************************************************************************
35   FUNCTION MIXSOFT_1ST_D32C31_WRA
36***********************************************************************************/
37#ifdef BUILD_FLOAT
38void MixSoft_1St_D32C31_WRA(    Mix_1St_Cll_FLOAT_t       *pInstance,
39                                const LVM_FLOAT     *src,
40                                      LVM_FLOAT     *dst,
41                                      LVM_INT16     n)
42{
43    char HardMixing = TRUE;
44
45    if(n <= 0)    return;
46
47    /******************************************************************************
48       SOFT MIXING
49    *******************************************************************************/
50    if (pInstance->Current != pInstance->Target)
51    {
52        if(pInstance->Alpha == 0){
53            pInstance->Current = pInstance->Target;
54        }else if ((pInstance->Current - pInstance->Target < POINT_ZERO_ONE_DB_FLOAT) &&
55                 (pInstance->Current - pInstance->Target > -POINT_ZERO_ONE_DB_FLOAT)){
56            pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
57                                                       Make them equal. */
58        }else{
59            /* Soft mixing has to be applied */
60            HardMixing = FALSE;
61            Core_MixSoft_1St_D32C31_WRA(pInstance, src, dst, n);
62        }
63    }
64
65    /******************************************************************************
66       HARD MIXING
67    *******************************************************************************/
68
69    if (HardMixing){
70        if (pInstance->Target == 0)
71            LoadConst_Float(0, dst, n);
72        else if ((pInstance->Target) == 1.0f){
73            if (src != dst)
74                Copy_Float((LVM_FLOAT*)src, (LVM_FLOAT*)dst, (LVM_INT16)(n));
75        }
76        else
77            Mult3s_Float(src, pInstance->Current, dst, n);
78    }
79
80    /******************************************************************************
81       CALL BACK
82    *******************************************************************************/
83
84    if (pInstance->CallbackSet){
85        if ((pInstance->Current - pInstance->Target < POINT_ZERO_ONE_DB_FLOAT) &&
86            (pInstance->Current - pInstance->Target > -POINT_ZERO_ONE_DB_FLOAT)){
87            pInstance->Current = pInstance->Target; /* Difference is not significant anymore. \
88                                                       Make them equal. */
89            pInstance->CallbackSet = FALSE;
90            if (pInstance->pCallBack != 0){
91                (*pInstance->pCallBack) ( pInstance->pCallbackHandle,
92                                          pInstance->pGeneralPurpose,
93                                          pInstance->CallbackParam );
94            }
95        }
96    }
97}
98#else
99void MixSoft_1St_D32C31_WRA(    Mix_1St_Cll_t       *pInstance,
100                                const LVM_INT32     *src,
101                                      LVM_INT32     *dst,
102                                      LVM_INT16     n)
103{
104    char HardMixing = TRUE;
105
106    if(n<=0)    return;
107
108    /******************************************************************************
109       SOFT MIXING
110    *******************************************************************************/
111    if (pInstance->Current != pInstance->Target)
112    {
113        if(pInstance->Alpha == 0){
114            pInstance->Current = pInstance->Target;
115        }else if ((pInstance->Current-pInstance->Target <POINT_ZERO_ONE_DB)&&
116                 (pInstance->Current-pInstance->Target > -POINT_ZERO_ONE_DB)){
117            pInstance->Current = pInstance->Target; /* Difference is not significant anymore.  Make them equal. */
118        }else{
119            /* Soft mixing has to be applied */
120            HardMixing = FALSE;
121            Core_MixSoft_1St_D32C31_WRA( pInstance, src, dst, n);
122        }
123    }
124
125    /******************************************************************************
126       HARD MIXING
127    *******************************************************************************/
128
129    if (HardMixing){
130        if (pInstance->Target == 0)
131            LoadConst_32(0, dst, n);
132        else if ((pInstance->Target>>16) == 0x7FFF){
133            if (src != dst)
134                Copy_16((LVM_INT16*)src, (LVM_INT16*)dst, (LVM_INT16)(n * 2));
135        }
136        else
137            Mult3s_32x16( src, (LVM_INT16)(pInstance->Current>>16), dst, n );
138    }
139
140    /******************************************************************************
141       CALL BACK
142    *******************************************************************************/
143
144    if (pInstance->CallbackSet){
145        if ((pInstance->Current-pInstance->Target <POINT_ZERO_ONE_DB)&&
146            (pInstance->Current-pInstance->Target > -POINT_ZERO_ONE_DB)){
147            pInstance->Current = pInstance->Target; /* Difference is not significant anymore.  Make them equal. */
148            pInstance->CallbackSet = FALSE;
149            if (pInstance->pCallBack != 0){
150                (*pInstance->pCallBack) ( pInstance->pCallbackHandle, pInstance->pGeneralPurpose,pInstance->CallbackParam );
151            }
152        }
153    }
154}
155#endif
156/**********************************************************************************/
157