Home | History | Annotate | Download | only in src
      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 "LVM_Macros.h"
     24 
     25 /**********************************************************************************
     26    FUNCTION CORE_MIXSOFT_1ST_D32C31_WRA
     27 ***********************************************************************************/
     28 
     29 void Core_MixInSoft_D32C31_SAT(     Mix_1St_Cll_t       *pInstance,
     30                                     const LVM_INT32     *src,
     31                                           LVM_INT32     *dst,
     32                                           LVM_INT16     n)
     33 {
     34     LVM_INT32    Temp1,Temp2,Temp3;
     35     LVM_INT16     OutLoop;
     36     LVM_INT16     InLoop;
     37     LVM_INT32    TargetTimesOneMinAlpha;
     38     LVM_INT32    CurrentTimesAlpha;
     39     LVM_INT16     ii,jj;
     40     LVM_INT16   CurrentShort;
     41 
     42     InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */
     43     OutLoop = (LVM_INT16)(n - (InLoop << 2));
     44 
     45     MUL32x32INTO32((0x7FFFFFFF-pInstance->Alpha),pInstance->Target,TargetTimesOneMinAlpha,31); /* Q31 * Q0 in Q0 */
     46     if (pInstance->Target >= pInstance->Current){
     47          TargetTimesOneMinAlpha +=2; /* Ceil*/
     48     }
     49 
     50     if (OutLoop){
     51         MUL32x32INTO32(pInstance->Current,pInstance->Alpha,CurrentTimesAlpha,31);       /* Q0 * Q31 in Q0 */
     52         pInstance->Current = TargetTimesOneMinAlpha + CurrentTimesAlpha;                /* Q0 + Q0 into Q0*/
     53         CurrentShort = (LVM_INT16)(pInstance->Current>>16);                             /* From Q31 to Q15*/
     54 
     55         for (ii = OutLoop; ii != 0; ii--){
     56         Temp1=*src++;
     57         Temp2=*dst;
     58         MUL32x16INTO32(Temp1,CurrentShort,Temp3,15)
     59         Temp1=(Temp2>>1)+(Temp3>>1);
     60 
     61         if (Temp1 > 0x3FFFFFFF)
     62             Temp1 = 0x7FFFFFFF;
     63         else if (Temp1 < - 0x40000000)
     64             Temp1 =  0x80000000;
     65         else
     66             Temp1=(Temp1<<1);
     67             *dst++ = Temp1;
     68         }
     69     }
     70 
     71     for (ii = InLoop; ii != 0; ii--){
     72         MUL32x32INTO32(pInstance->Current,pInstance->Alpha,CurrentTimesAlpha,31);       /* Q0 * Q31 in Q0 */
     73         pInstance->Current = TargetTimesOneMinAlpha + CurrentTimesAlpha;                /* Q0 + Q0 into Q0*/
     74         CurrentShort = (LVM_INT16)(pInstance->Current>>16);                             /* From Q31 to Q15*/
     75 
     76         for (jj = 4; jj!=0 ; jj--){
     77         Temp1=*src++;
     78         Temp2=*dst;
     79         MUL32x16INTO32(Temp1,CurrentShort,Temp3,15)
     80         Temp1=(Temp2>>1)+(Temp3>>1);
     81 
     82         if (Temp1 > 0x3FFFFFFF)
     83             Temp1 = 0x7FFFFFFF;
     84         else if (Temp1 < - 0x40000000)
     85             Temp1 =  0x80000000;
     86         else
     87             Temp1=(Temp1<<1);
     88             *dst++ = Temp1;
     89         }
     90     }
     91 }
     92 
     93 
     94 /**********************************************************************************/
     95