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 "LVM_Macros.h"
24#include "ScalarArithmetic.h"
25
26/**********************************************************************************
27   FUNCTION LVCore_MIXSOFT_1ST_D16C31_WRA
28***********************************************************************************/
29
30void LVC_Core_MixSoft_1St_D16C31_WRA( LVMixer3_st *ptrInstance,
31                                    const LVM_INT16     *src,
32                                          LVM_INT16     *dst,
33                                          LVM_INT16     n)
34{
35    LVM_INT16   OutLoop;
36    LVM_INT16   InLoop;
37    LVM_INT16   CurrentShort;
38    LVM_INT32   ii;
39    Mix_Private_st  *pInstance=(Mix_Private_st *)(ptrInstance->PrivateParams);
40    LVM_INT32   Delta=pInstance->Delta;
41    LVM_INT32   Current=pInstance->Current;
42    LVM_INT32   Target=pInstance->Target;
43    LVM_INT32   Temp;
44
45    InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */
46    OutLoop = (LVM_INT16)(n - (InLoop << 2));
47
48    if(Current<Target){
49        if (OutLoop){
50            ADD2_SAT_32x32(Current,Delta,Temp);                                      /* Q31 + Q31 into Q31*/
51            Current=Temp;
52            if (Current > Target)
53                Current = Target;
54
55            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
56
57            for (ii = OutLoop; ii != 0; ii--){
58                *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
59            }
60        }
61
62        for (ii = InLoop; ii != 0; ii--){
63            ADD2_SAT_32x32(Current,Delta,Temp);                                      /* Q31 + Q31 into Q31*/
64            Current=Temp;
65            if (Current > Target)
66                Current = Target;
67
68            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
69
70            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
71            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
72            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
73            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
74        }
75    }
76    else{
77        if (OutLoop){
78            Current -= Delta;                                                        /* Q31 + Q31 into Q31*/
79            if (Current < Target)
80                Current = Target;
81
82            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
83
84            for (ii = OutLoop; ii != 0; ii--){
85                *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
86            }
87        }
88
89        for (ii = InLoop; ii != 0; ii--){
90            Current -= Delta;                                                        /* Q31 + Q31 into Q31*/
91            if (Current < Target)
92                Current = Target;
93
94            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
95
96            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
97            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
98            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
99            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
100        }
101    }
102    pInstance->Current=Current;
103}
104
105
106/**********************************************************************************/
107