LVC_MixSoft_1St_D16C31_SAT.c revision 2c8e5cab3faa6d360e222b7a6c40a80083d021ac
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 20 $Author: beq07716 $ 21 $Revision: 1000 $ 22 $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $ 23 24***********************************************************************************/ 25 26/********************************************************************************** 27 INCLUDE FILES 28***********************************************************************************/ 29 30#include "LVC_Mixer_Private.h" 31#include "VectorArithmetic.h" 32#include "ScalarArithmetic.h" 33 34/********************************************************************************** 35 DEFINITIONS 36***********************************************************************************/ 37 38#define TRUE 1 39#define FALSE 0 40 41/********************************************************************************** 42 FUNCTION LVMixer3_MIXSOFT_1ST_D16C31_SAT 43***********************************************************************************/ 44 45void LVC_MixSoft_1St_D16C31_SAT( LVMixer3_1St_st *ptrInstance, 46 const LVM_INT16 *src, 47 LVM_INT16 *dst, 48 LVM_INT16 n) 49{ 50 char HardMixing = TRUE; 51 LVM_INT32 TargetGain; 52 Mix_Private_st *pInstance=(Mix_Private_st *)(ptrInstance->MixerStream[0].PrivateParams); 53 54 if(n<=0) return; 55 56 /****************************************************************************** 57 SOFT MIXING 58 *******************************************************************************/ 59 if (pInstance->Current != pInstance->Target) 60 { 61 if(pInstance->Delta == 0x7FFFFFFF){ 62 pInstance->Current = pInstance->Target; 63 TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format 64 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); 65 }else if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){ 66 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ 67 TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format 68 LVC_Mixer_SetTarget(&(ptrInstance->MixerStream[0]),TargetGain); 69 }else{ 70 /* Soft mixing has to be applied */ 71 HardMixing = FALSE; 72 if(pInstance->Shift!=0){ 73 Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,dst,n); 74 LVC_Core_MixSoft_1St_D16C31_WRA( &(ptrInstance->MixerStream[0]), dst, dst, n); 75 } 76 else 77 LVC_Core_MixSoft_1St_D16C31_WRA( &(ptrInstance->MixerStream[0]), src, dst, n); 78 } 79 } 80 81 /****************************************************************************** 82 HARD MIXING 83 *******************************************************************************/ 84 85 if (HardMixing){ 86 if (pInstance->Target == 0) 87 LoadConst_16(0, dst, n); 88 else if(pInstance->Shift!=0){ 89 Shift_Sat_v16xv16 ((LVM_INT16)pInstance->Shift,src,dst,n); 90 if ((pInstance->Target>>16) != 0x7FFF) 91 Mult3s_16x16( dst, (LVM_INT16)(pInstance->Target>>16), dst, n ); 92 } 93 else { 94 if ((pInstance->Target>>16) != 0x7FFF) 95 Mult3s_16x16( src, (LVM_INT16)(pInstance->Target>>16), dst, n ); 96 else if(src!=dst) 97 Copy_16(src, dst, n); 98 } 99 100 } 101 102 /****************************************************************************** 103 CALL BACK 104 *******************************************************************************/ 105 106 if (ptrInstance->MixerStream[0].CallbackSet){ 107 if (Abs_32(pInstance->Current-pInstance->Target) < pInstance->Delta){ 108 pInstance->Current = pInstance->Target; /* Difference is not significant anymore. Make them equal. */ 109 TargetGain=pInstance->Target>>(16-pInstance->Shift); // TargetGain in Q16.15 format 110 LVC_Mixer_SetTarget(ptrInstance->MixerStream,TargetGain); 111 ptrInstance->MixerStream[0].CallbackSet = FALSE; 112 if (ptrInstance->MixerStream[0].pCallBack != 0){ 113 (*ptrInstance->MixerStream[0].pCallBack) ( ptrInstance->MixerStream[0].pCallbackHandle, ptrInstance->MixerStream[0].pGeneralPurpose,ptrInstance->MixerStream[0].CallbackParam ); 114 } 115 } 116 } 117} 118 119/**********************************************************************************/ 120