12c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/*
22c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Copyright (C) 2004-2010 NXP Software
32c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Copyright (C) 2010 The Android Open Source Project
42c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *
52c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
62c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * you may not use this file except in compliance with the License.
72c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * You may obtain a copy of the License at
82c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *
92c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
102c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *
112c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Unless required by applicable law or agreed to in writing, software
122c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
132c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * See the License for the specific language governing permissions and
152c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * limitations under the License.
162c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent */
172c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
182c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/**********************************************************************************
192c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent   INCLUDE FILES
202c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent***********************************************************************************/
212c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
222c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "LVC_Mixer_Private.h"
232c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "LVM_Macros.h"
242c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "ScalarArithmetic.h"
252c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
262c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/**********************************************************************************
272c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent   FUNCTION LVCore_MIXSOFT_1ST_D16C31_WRA
282c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent***********************************************************************************/
292c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
302c87e9c923b0362fabf8c97ff63997542394c428Eric Laurentvoid LVC_Core_MixSoft_1St_D16C31_WRA( LVMixer3_st *ptrInstance,
312c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                    const LVM_INT16     *src,
322c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                          LVM_INT16     *dst,
332c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                          LVM_INT16     n)
342c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent{
352c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT16   OutLoop;
362c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT16   InLoop;
372c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT16   CurrentShort;
382c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT32   ii;
392c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    Mix_Private_st  *pInstance=(Mix_Private_st *)(ptrInstance->PrivateParams);
402c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT32   Delta=pInstance->Delta;
412c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT32   Current=pInstance->Current;
422c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT32   Target=pInstance->Target;
432c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    LVM_INT32   Temp;
442c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
452c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */
462c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    OutLoop = (LVM_INT16)(n - (InLoop << 2));
472c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
482c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    if(Current<Target){
492c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        if (OutLoop){
502c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ADD2_SAT_32x32(Current,Delta,Temp);                                      /* Q31 + Q31 into Q31*/
512c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            Current=Temp;
522c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            if (Current > Target)
532c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                Current = Target;
542c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
552c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
562c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
572c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            for (ii = OutLoop; ii != 0; ii--){
582c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
592c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            }
602c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
612c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
622c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        for (ii = InLoop; ii != 0; ii--){
632c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ADD2_SAT_32x32(Current,Delta,Temp);                                      /* Q31 + Q31 into Q31*/
642c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            Current=Temp;
652c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            if (Current > Target)
662c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                Current = Target;
672c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
682c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
692c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
702c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
712c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
722c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
732c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
742c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
752c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    }
762c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    else{
772c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        if (OutLoop){
782c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            Current -= Delta;                                                        /* Q31 + Q31 into Q31*/
792c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            if (Current < Target)
802c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                Current = Target;
812c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
822c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
832c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
842c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            for (ii = OutLoop; ii != 0; ii--){
852c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
862c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            }
872c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
882c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
892c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        for (ii = InLoop; ii != 0; ii--){
902c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            Current -= Delta;                                                        /* Q31 + Q31 into Q31*/
912c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            if (Current < Target)
922c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                Current = Target;
932c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
942c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            CurrentShort = (LVM_INT16)(Current>>16);                                 /* From Q31 to Q15*/
952c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
962c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);    /* Q15*Q15>>15 into Q15 */
972c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
982c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
992c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *(dst++) = (LVM_INT16)(((LVM_INT32)*(src++) * (LVM_INT32)CurrentShort)>>15);
1002c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
1012c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    }
1022c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    pInstance->Current=Current;
1032c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent}
1042c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
1052c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
1062c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/**********************************************************************************/
107