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