LVDBE_Process.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: nxp007753 $ 21 $Revision: 1081 $ 22 $Date: 2010-07-05 11:48:44 +0200 (Mon, 05 Jul 2010) $ 23 24*****************************************************************************************/ 25 26/****************************************************************************************/ 27/* */ 28/* Includes */ 29/* */ 30/****************************************************************************************/ 31 32#include "LVDBE.h" 33#include "LVDBE_Private.h" 34#include "VectorArithmetic.h" 35#include "AGC.h" 36#include "LVDBE_Coeffs.h" /* Filter coefficients */ 37 38 39/********************************************************************************************/ 40/* */ 41/* FUNCTION: LVDBE_Process */ 42/* */ 43/* DESCRIPTION: */ 44/* Process function for the Bass Enhancement module. */ 45/* */ 46/* Data can be processed in two formats, stereo or mono-in-stereo. Data in mono */ 47/* format is not supported, the calling routine must convert the mono stream to */ 48/* mono-in-stereo. */ 49/* ___________ */ 50/* ________ | | ________ */ 51/* | | _____ |------------------------->| | | | */ 52/* | 16-bit | | | | ________ | | | 32-bit | */ 53/* -+-->| to |-->| HPF |--| | | _____ | AGC Mixer |-->| to |--| */ 54/* | | 32-bit | |_____| | | Stereo | | | | | | 16-bit | | */ 55/* | |________| |-->| to |-->| BPF |-->| | |________| 0 */ 56/* | | Mono | |_____| |___________| \--> */ 57/* | |________| */ 58/* | _________ 0 */ 59/* | | | | */ 60/* |----------------------------------------------------| Volume |-----------------| */ 61/* | Control | */ 62/* |_________| */ 63/* */ 64/* PARAMETERS: */ 65/* hInstance Instance handle */ 66/* pInData Pointer to the input data */ 67/* pOutData Pointer to the output data */ 68/* NumSamples Number of samples in the input buffer */ 69/* */ 70/* RETURNS: */ 71/* LVDBE_SUCCESS Succeeded */ 72/* LVDBE_TOOMANYSAMPLES NumSamples was larger than the maximum block size */ 73/* */ 74/* NOTES: */ 75/* 1. The input and output data must be 32-bit format. The input is scaled by a shift */ 76/* when converting from 16-bit format, this scaling allows for internal headroom in the */ 77/* bass enhancement algorithm. */ 78/* 2. For a 16-bit implementation the converstion to 32-bit is removed and replaced with */ 79/* the headroom loss. This headroom loss is compensated in the volume control so the */ 80/* overall end to end gain is odB. */ 81/* */ 82/********************************************************************************************/ 83 84LVDBE_ReturnStatus_en LVDBE_Process(LVDBE_Handle_t hInstance, 85 const LVM_INT16 *pInData, 86 LVM_INT16 *pOutData, 87 LVM_UINT16 NumSamples) 88{ 89 90 LVDBE_Instance_t *pInstance =(LVDBE_Instance_t *)hInstance; 91 LVM_INT32 *pScratch = (LVM_INT32 *)pInstance->MemoryTable.Region[LVDBE_MEMREGION_SCRATCH].pBaseAddress; 92 LVM_INT32 *pMono = (LVM_INT32 *)pOutData; 93 LVM_INT16 *pInput = (LVM_INT16 *)pInData; 94 95 96 /* 97 * Check the number of samples is not too large 98 */ 99 if (NumSamples > pInstance->Capabilities.MaxBlockSize) 100 { 101 return(LVDBE_TOOMANYSAMPLES); 102 } 103 104 /* 105 * Check if the algorithm is enabled 106 */ 107 if ((pInstance->Params.OperatingMode != LVDBE_OFF) || 108 (pInstance->bTransitionOnToOff == LVM_TRUE)) 109 { 110 111 /* 112 * Convert 16-bit samples to 32-bit and scale 113 * (For a 16-bit implementation apply headroom loss here) 114 */ 115 Int16LShiftToInt32_16x32(pInput, /* Source 16-bit data */ 116 pScratch, /* Destination 32-bit data */ 117 (LVM_INT16)(2*NumSamples), /* Left and right */ 118 LVDBE_SCALESHIFT); /* Shift scale */ 119 120 121 /* 122 * Apply the high pass filter if selected 123 */ 124 if (pInstance->Params.HPFSelect == LVDBE_HPF_ON) 125 { 126 BQ_2I_D32F32C30_TRC_WRA_01(&pInstance->pCoef->HPFInstance, /* Filter instance */ 127 (LVM_INT32 *)pScratch, /* Source */ 128 (LVM_INT32 *)pScratch, /* Destination */ 129 (LVM_INT16)NumSamples); /* Number of samples */ 130 } 131 132 133 /* 134 * Create the mono stream 135 */ 136 From2iToMono_32(pScratch, /* Stereo source */ 137 pMono, /* Mono destination */ 138 (LVM_INT16)NumSamples); /* Number of samples */ 139 140 141 /* 142 * Apply the band pass filter 143 */ 144 BP_1I_D32F32C30_TRC_WRA_02(&pInstance->pCoef->BPFInstance, /* Filter instance */ 145 (LVM_INT32 *)pMono, /* Source */ 146 (LVM_INT32 *)pMono, /* Destination */ 147 (LVM_INT16)NumSamples); /* Number of samples */ 148 149 150 /* 151 * Apply the AGC and mix 152 */ 153 AGC_MIX_VOL_2St1Mon_D32_WRA(&pInstance->pData->AGCInstance, /* Instance pointer */ 154 pScratch, /* Stereo source */ 155 pMono, /* Mono band pass source */ 156 pScratch, /* Stereo destination */ 157 NumSamples); /* Number of samples */ 158 159 if(pInstance->bTransitionOnToOff == LVM_TRUE) 160 { 161 if ((pInstance->pData->AGCInstance.AGC_Gain == pInstance->pData->AGCInstance.AGC_Target)&& 162 (pInstance->pData->AGCInstance.AGC_Gain == 0)) 163 { 164 pInstance->bTransitionOnToOff = LVM_FALSE; 165 } 166 } 167 168 169 170 /* 171 * Convert 32-bit samples to 16-bit and saturate 172 * (Not required for 16-bit implemenations) 173 */ 174 Int32RShiftToInt16_Sat_32x16(pScratch, /* Source 32-bit data */ 175 pOutData, /* Destination 16-bit data */ 176 (LVM_INT16)(2*NumSamples), /* Left and right */ 177 LVDBE_SCALESHIFT); /* Shift scale */ 178 179 } 180 else 181 { 182 183 /* 184 * The algorithm is disabled but volume management is required to compensate for 185 * headroom and volume (if enabled) 186 */ 187 LVC_MixSoft_1St_D16C31_SAT(&pInstance->pData->BypassVolume, 188 pInData, 189 pOutData, 190 (LVM_INT16)(2*NumSamples)); /* Left and right */ 191 192 } 193 194 return(LVDBE_SUCCESS); 195} 196 197 198 199 200 201 202 203 204 205 206