M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
@@ -0,0 +1,312 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Header file for the application layer interface of the LVREV module */
/* */
/* This files includes all definitions, types, structures and function prototypes */
/* required by the calling layer. All other types, structures and functions are */
/* private. */
/* */
/****************************************************************************************/
#ifndef __LVREV_H__
#define __LVREV_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVM_Types.h"
/****************************************************************************************/
/* */
/* Definitions */
/* */
/****************************************************************************************/
/* General */
#define LVREV_BLOCKSIZE_MULTIPLE 1 /* Processing block size multiple */
#define LVREV_MAX_T60 7000 /* Maximum decay time is 7000ms */
/* Memory table*/
#define LVREV_NR_MEMORY_REGIONS 4 /* Number of memory regions */
/****************************************************************************************/
/* */
/* Types */
/* */
/****************************************************************************************/
/* Instance handle */
typedef void *LVREV_Handle_t;
/* Status return values */
typedef enum
{
LVREV_SUCCESS = 0, /* Successful return from a routine */
LVREV_NULLADDRESS = 1, /* NULL allocation address */
LVREV_OUTOFRANGE = 2, /* Out of range control parameter */
LVREV_INVALIDNUMSAMPLES = 3, /* Invalid number of samples */
LVREV_RETURNSTATUS_DUMMY = LVM_MAXENUM
} LVREV_ReturnStatus_en;
/* Reverb delay lines */
typedef enum
{
LVREV_DELAYLINES_1 = 1, /* One delay line */
LVREV_DELAYLINES_2 = 2, /* Two delay lines */
LVREV_DELAYLINES_4 = 4, /* Four delay lines */
LVREV_DELAYLINES_DUMMY = LVM_MAXENUM
} LVREV_NumDelayLines_en;
/****************************************************************************************/
/* */
/* Structures */
/* */
/****************************************************************************************/
/* Memory table containing the region definitions */
typedef struct
{
LVM_MemoryRegion_st Region[LVREV_NR_MEMORY_REGIONS]; /* One definition for each region */
} LVREV_MemoryTable_st;
/* Control Parameter structure */
typedef struct
{
/* General parameters */
LVM_Mode_en OperatingMode; /* Operating mode */
LVM_Fs_en SampleRate; /* Sample rate */
LVM_Format_en SourceFormat; /* Source data format */
/* Parameters for REV */
LVM_UINT16 Level; /* Level, 0 to 100 representing percentage of reverb */
LVM_UINT16 LPF; /* Low pass filter, in Hz */
LVM_UINT16 HPF; /* High pass filter, in Hz */
LVM_UINT16 T60; /* Decay time constant, in ms */
LVM_UINT16 Density; /* Echo density, 0 to 100 for minimum to maximum density */
LVM_UINT16 Damping; /* Damping */
LVM_UINT16 RoomSize; /* Simulated room size, 1 to 100 for minimum to maximum size */
} LVREV_ControlParams_st;
/* Instance Parameter structure */
typedef struct
{
/* General */
LVM_UINT16 MaxBlockSize; /* Maximum processing block size */
/* Reverb */
LVM_Format_en SourceFormat; /* Source data formats to support */
LVREV_NumDelayLines_en NumDelays; /* The number of delay lines, 1, 2 or 4 */
} LVREV_InstanceParams_st;
/****************************************************************************************/
/* */
/* Function Prototypes */
/* */
/****************************************************************************************/
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_GetMemoryTable */
/* */
/* DESCRIPTION: */
/* This function is used to obtain the LVREV module memory requirements to support */
/* memory allocation. It can also be used to return the memory base address provided */
/* during memory allocation to support freeing of memory when the LVREV module is no */
/* longer required. It is called in two ways: */
/* */
/* hInstance = NULL Returns the memory requirements */
/* hInstance = Instance handle Returns the memory requirements and allocated */
/* base addresses. */
/* */
/* When this function is called with hInstance = NULL the memory base address pointers */
/* will be NULL on return. */
/* */
/* When the function is called for freeing memory, hInstance = Instance Handle the */
/* memory table returns the allocated memory and base addresses used during */
/* initialisation. */
/* */
/* PARAMETERS: */
/* hInstance Instance Handle */
/* pMemoryTable Pointer to an empty memory table */
/* pInstanceParams Pointer to the instance parameters */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Succeeded */
/* LVREV_NULLADDRESS When pMemoryTable is NULL */
/* LVREV_NULLADDRESS When requesting memory requirements and pInstanceParams */
/* is NULL */
/* */
/* NOTES: */
/* 1. This function may be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetMemoryTable(LVREV_Handle_t hInstance,
LVREV_MemoryTable_st *pMemoryTable,
LVREV_InstanceParams_st *pInstanceParams);
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_GetInstanceHandle */
/* */
/* DESCRIPTION: */
/* This function is used to create a LVREV module instance. It returns the created */
/* instance handle through phInstance. All parameters are set to invalid values, the */
/* LVREV_SetControlParameters function must be called with a set of valid control */
/* parameters before the LVREV_Process function can be called. */
/* */
/* The memory allocation must be provided by the application by filling in the memory */
/* region base addresses in the memory table before calling this function. */
/* */
/* PARAMETERS: */
/* phInstance Pointer to the instance handle */
/* pMemoryTable Pointer to the memory definition table */
/* pInstanceParams Pointer to the instance parameters */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Succeeded */
/* LVREV_NULLADDRESS When phInstance or pMemoryTable or pInstanceParams is NULL */
/* LVREV_NULLADDRESS When one of the memory regions has a NULL pointer */
/* */
/* NOTES: */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetInstanceHandle(LVREV_Handle_t *phInstance,
LVREV_MemoryTable_st *pMemoryTable,
LVREV_InstanceParams_st *pInstanceParams);
/****************************************************************************************/
/* */
/* FUNCTION: LVXX_GetControlParameters */
/* */
/* DESCRIPTION: */
/* Request the LVREV module control parameters. The current parameter set is returned */
/* via the parameter pointer. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pControlParams Pointer to an empty parameter structure */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Succeeded */
/* LVREV_NULLADDRESS When hInstance or pControlParams is NULL */
/* */
/* NOTES: */
/* 1. This function may be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetControlParameters(LVREV_Handle_t hInstance,
LVREV_ControlParams_st *pControlParams);
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_SetControlParameters */
/* */
/* DESCRIPTION: */
/* Sets or changes the LVREV module parameters. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pNewParams Pointer to a parameter structure */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Succeeded */
/* LVREV_NULLADDRESS When hInstance or pNewParams is NULL */
/* */
/* NOTES: */
/* 1. This function may be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_SetControlParameters(LVREV_Handle_t hInstance,
LVREV_ControlParams_st *pNewParams);
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_ClearAudioBuffers */
/* */
/* DESCRIPTION: */
/* This function is used to clear the internal audio buffers of the module. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Initialisation succeeded */
/* LVREV_NULLADDRESS Instance is NULL */
/* */
/* NOTES: */
/* 1. This function must not be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_ClearAudioBuffers(LVREV_Handle_t hInstance);
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_Process */
/* */
/* DESCRIPTION: */
/* Process function for the LVREV module. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pInData Pointer to the input data */
/* pOutData Pointer to the output data */
/* NumSamples Number of samples in the input buffer */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Succeeded */
/* LVREV_INVALIDNUMSAMPLES NumSamples was larger than the maximum block size */
/* */
/* NOTES: */
/* 1. The input and output buffers must be 32-bit aligned */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_Process(LVREV_Handle_t hInstance,
const LVM_INT32 *pInData,
LVM_INT32 *pOutData,
const LVM_UINT16 NumSamples);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __LVREV_H__ */
/* End of file */
@@ -0,0 +1,642 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
#include "Filter.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_ApplyNewSettings */
/* */
/* DESCRIPTION: */
/* Applies the new control parameters */
/* */
/* PARAMETERS: */
/* pPrivate Pointer to the instance private parameters */
/* */
/* RETURNS: */
/* LVREV_Success Succeeded */
/* LVREV_NULLADDRESS When pPrivate is NULL */
/* */
/* NOTES: */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_ApplyNewSettings (LVREV_Instance_st *pPrivate)
{
LVM_Mode_en OperatingMode;
LVM_INT32 NumberOfDelayLines;
/* Check for NULL pointer */
if(pPrivate == LVM_NULL)
{
return LVREV_NULLADDRESS;
}
OperatingMode = pPrivate->NewParams.OperatingMode;
if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_4)
{
NumberOfDelayLines = 4;
}
else if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_2)
{
NumberOfDelayLines = 2;
}
else
{
NumberOfDelayLines = 1;
}
/*
* Update the high pass filter coefficients
*/
if((pPrivate->NewParams.HPF != pPrivate->CurrentParams.HPF) ||
(pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_INT32 Omega;
FO_C32_Coefs_t Coeffs;
Omega = LVM_GetOmega(pPrivate->NewParams.HPF, pPrivate->NewParams.SampleRate);
LVM_FO_HPF(Omega, &Coeffs);
FO_1I_D32F32Cll_TRC_WRA_01_Init( &pPrivate->pFastCoef->HPCoefs, &pPrivate->pFastData->HPTaps, &Coeffs);
LoadConst_32(0,
(void *)&pPrivate->pFastData->HPTaps, /* Destination Cast to void: no dereferencing in function*/
sizeof(Biquad_1I_Order1_Taps_t)/sizeof(LVM_INT32));
}
/*
* Update the low pass filter coefficients
*/
if((pPrivate->NewParams.LPF != pPrivate->CurrentParams.LPF) ||
(pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_INT32 Omega;
FO_C32_Coefs_t Coeffs;
Coeffs.A0 = 0x7FFFFFFF;
Coeffs.A1 = 0;
Coeffs.B1 = 0;
if(pPrivate->NewParams.LPF <= (LVM_FsTable[pPrivate->NewParams.SampleRate] >> 1))
{
Omega = LVM_GetOmega(pPrivate->NewParams.LPF, pPrivate->NewParams.SampleRate);
/*
* Do not apply filter if w =2*pi*fc/fs >= 2.9
*/
if(Omega<=LVREV_2_9_INQ29)
{
LVM_FO_LPF(Omega, &Coeffs);
}
}
FO_1I_D32F32Cll_TRC_WRA_01_Init( &pPrivate->pFastCoef->LPCoefs, &pPrivate->pFastData->LPTaps, &Coeffs);
LoadConst_32(0,
(void *)&pPrivate->pFastData->LPTaps, /* Destination Cast to void: no dereferencing in function*/
sizeof(Biquad_1I_Order1_Taps_t)/sizeof(LVM_INT32));
}
/*
* Calculate the room size parameter
*/
if( pPrivate->NewParams.RoomSize != pPrivate->CurrentParams.RoomSize)
{
/* Room size range is 10ms to 200ms
* 0% -- 10ms
* 50% -- 65ms
* 100% -- 120ms
*/
pPrivate->RoomSizeInms = 10 + (((pPrivate->NewParams.RoomSize*11) + 5)/10);
}
/*
* Update the T delay number of samples and the all pass delay number of samples
*/
if( (pPrivate->NewParams.RoomSize != pPrivate->CurrentParams.RoomSize) ||
(pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_UINT32 Temp;
LVM_INT32 APDelaySize;
LVM_INT32 Fs = LVM_GetFsFromTable(pPrivate->NewParams.SampleRate);
LVM_UINT32 DelayLengthSamples = (LVM_UINT32)(Fs * pPrivate->RoomSizeInms);
LVM_INT16 i;
LVM_INT16 ScaleTable[] = {LVREV_T_3_Power_minus0_on_4, LVREV_T_3_Power_minus1_on_4, LVREV_T_3_Power_minus2_on_4, LVREV_T_3_Power_minus3_on_4};
LVM_INT16 MaxT_Delay[] = {LVREV_MAX_T0_DELAY, LVREV_MAX_T1_DELAY, LVREV_MAX_T2_DELAY, LVREV_MAX_T3_DELAY};
LVM_INT16 MaxAP_Delay[] = {LVREV_MAX_AP0_DELAY, LVREV_MAX_AP1_DELAY, LVREV_MAX_AP2_DELAY, LVREV_MAX_AP3_DELAY};
/*
* For each delay line
*/
for (i=0; i<NumberOfDelayLines; i++)
{
if (i != 0)
{
LVM_INT32 Temp1; /* to avoid QAC warning on type conversion */
LVM_INT32 Temp2; /* to avoid QAC warning on type conversion */
Temp2=(LVM_INT32)DelayLengthSamples;
MUL32x16INTO32(Temp2, ScaleTable[i], Temp1, 15)
Temp=(LVM_UINT32)Temp1;
}
else
{
Temp = DelayLengthSamples;
}
APDelaySize = Temp / 1500;
/*
* Set the fixed delay
*/
Temp = (MaxT_Delay[i] - MaxAP_Delay[i]) * Fs / 48000;
pPrivate->Delay_AP[i] = pPrivate->T[i] - Temp;
/*
* Set the tap selection
*/
if (pPrivate->AB_Selection)
{
/* Smooth from tap A to tap B */
pPrivate->pOffsetB[i] = &pPrivate->pDelay_T[i][pPrivate->T[i] - Temp - APDelaySize];
pPrivate->B_DelaySize[i] = APDelaySize;
pPrivate->Mixer_APTaps[i].Target1 = 0;
pPrivate->Mixer_APTaps[i].Target2 = 0x7fffffff;
}
else
{
/* Smooth from tap B to tap A */
pPrivate->pOffsetA[i] = &pPrivate->pDelay_T[i][pPrivate->T[i] - Temp - APDelaySize];
pPrivate->A_DelaySize[i] = APDelaySize;
pPrivate->Mixer_APTaps[i].Target2 = 0;
pPrivate->Mixer_APTaps[i].Target1 = 0x7fffffff;
}
/*
* Set the maximum block size to the smallest delay size
*/
pPrivate->MaxBlkLen = Temp;
if (pPrivate->MaxBlkLen > pPrivate->A_DelaySize[i])
{
pPrivate->MaxBlkLen = pPrivate->A_DelaySize[i];
}
if (pPrivate->MaxBlkLen > pPrivate->B_DelaySize[i])
{
pPrivate->MaxBlkLen = pPrivate->B_DelaySize[i];
}
}
if (pPrivate->AB_Selection)
{
pPrivate->AB_Selection = 0;
}
else
{
pPrivate->AB_Selection = 1;
}
/*
* Limit the maximum block length
*/
pPrivate->MaxBlkLen=pPrivate->MaxBlkLen-2; /* Just as a precausion, but no problem if we remove this line */
if(pPrivate->MaxBlkLen > pPrivate->InstanceParams.MaxBlockSize)
{
pPrivate->MaxBlkLen = (LVM_INT32)pPrivate->InstanceParams.MaxBlockSize;
}
}
/*
* Update the low pass filter coefficient
*/
if( (pPrivate->NewParams.Damping != pPrivate->CurrentParams.Damping) ||
(pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_INT32 Temp;
LVM_INT32 Omega;
FO_C32_Coefs_t Coeffs;
LVM_INT16 i;
LVM_INT16 Damping = (LVM_INT16)((pPrivate->NewParams.Damping * 100) + 1000);
LVM_INT32 ScaleTable[] = {LVREV_T_3_Power_0_on_4, LVREV_T_3_Power_1_on_4, LVREV_T_3_Power_2_on_4, LVREV_T_3_Power_3_on_4};
/*
* For each filter
*/
for (i=0; i<NumberOfDelayLines; i++)
{
if (i != 0)
{
MUL32x16INTO32(ScaleTable[i], Damping, Temp, 15)
}
else
{
Temp = Damping;
}
if(Temp <= (LVM_FsTable[pPrivate->NewParams.SampleRate] >> 1))
{
Omega = LVM_GetOmega((LVM_UINT16)Temp, pPrivate->NewParams.SampleRate);
LVM_FO_LPF(Omega, &Coeffs);
}
else
{
Coeffs.A0 = 0x7FF00000;
Coeffs.A1 = 0;
Coeffs.B1 = 0;
}
FO_1I_D32F32Cll_TRC_WRA_01_Init(&pPrivate->pFastCoef->RevLPCoefs[i], &pPrivate->pFastData->RevLPTaps[i], &Coeffs);
}
}
/*
* Update All-pass filter mixer time constants
*/
if( (pPrivate->NewParams.RoomSize != pPrivate->CurrentParams.RoomSize) ||
(pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->NewParams.Density != pPrivate->CurrentParams.Density))
{
LVM_INT16 i;
LVM_INT32 Alpha = (LVM_INT32)LVM_Mixer_TimeConstant(LVREV_ALLPASS_TC, LVM_GetFsFromTable(pPrivate->NewParams.SampleRate), 1);
LVM_INT32 AlphaTap = (LVM_INT32)LVM_Mixer_TimeConstant(LVREV_ALLPASS_TAP_TC, LVM_GetFsFromTable(pPrivate->NewParams.SampleRate), 1);
for (i=0; i<4; i++)
{
pPrivate->Mixer_APTaps[i].Alpha1 = AlphaTap;
pPrivate->Mixer_APTaps[i].Alpha2 = AlphaTap;
pPrivate->Mixer_SGFeedback[i].Alpha = Alpha;
pPrivate->Mixer_SGFeedforward[i].Alpha = Alpha;
}
}
/*
* Update the feed back gain
*/
if( (pPrivate->NewParams.RoomSize != pPrivate->CurrentParams.RoomSize) ||
(pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->NewParams.T60 != pPrivate->CurrentParams.T60) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_INT32 G[4]; /* Feedback gain (Q7.24) */
if(pPrivate->NewParams.T60 == 0)
{
G[3] = 0;
G[2] = 0;
G[1] = 0;
G[0] = 0;
}
else
{
LVM_INT32 Temp1;
LVM_INT32 Temp2;
LVM_INT16 i;
LVM_INT16 ScaleTable[] = {LVREV_T_3_Power_minus0_on_4, LVREV_T_3_Power_minus1_on_4, LVREV_T_3_Power_minus2_on_4, LVREV_T_3_Power_minus3_on_4};
/*
* For each delay line
*/
for (i=0; i<NumberOfDelayLines; i++)
{
Temp1 = (3 * pPrivate->RoomSizeInms * ScaleTable[i]) / pPrivate->NewParams.T60;
if(Temp1 >= (4 << 15))
{
G[i] = 0;
}
else if((Temp1 >= (2 << 15)))
{
Temp2 = LVM_Power10(-(Temp1 << 14));
Temp1 = LVM_Power10(-(Temp1 << 14));
MUL32x32INTO32(Temp1,Temp2,Temp1,24)
}
else
{
Temp1 = LVM_Power10(-(Temp1 << 15));
}
if (NumberOfDelayLines == 1)
{
G[i] = Temp1;
}
else
{
LVM_INT32 TempG;
MUL32x16INTO32(Temp1,ONE_OVER_SQRT_TWO,TempG,15)
G[i]=TempG;
}
}
}
/* Set up the feedback mixers for four delay lines */
pPrivate->FeedbackMixer[0].Target=G[0]<<7;
pPrivate->FeedbackMixer[1].Target=G[1]<<7;
pPrivate->FeedbackMixer[2].Target=G[2]<<7;
pPrivate->FeedbackMixer[3].Target=G[3]<<7;
}
/*
* Calculate the gain correction
*/
if((pPrivate->NewParams.RoomSize != pPrivate->CurrentParams.RoomSize) ||
(pPrivate->NewParams.Level != pPrivate->CurrentParams.Level) ||
(pPrivate->NewParams.T60 != pPrivate->CurrentParams.T60) )
{
LVM_INT32 Index=0;
LVM_INT32 i=0;
LVM_INT32 Gain=0;
LVM_INT32 RoomSize=0;
LVM_INT32 T60;
LVM_INT32 Coefs[5];
if(pPrivate->NewParams.RoomSize==0)
{
RoomSize=1;
}
else
{
RoomSize=(LVM_INT32)pPrivate->NewParams.RoomSize;
}
if(pPrivate->NewParams.T60<100)
{
T60 = 100 * LVREV_T60_SCALE;
}
else
{
T60 = pPrivate->NewParams.T60 * LVREV_T60_SCALE;
}
/* Find the nearest room size in table */
for(i=0;i<24;i++)
{
if(RoomSize<= LVREV_GainPolyTable[i][0])
{
Index=i;
break;
}
}
if(RoomSize==LVREV_GainPolyTable[Index][0])
{
/* Take table values if the room size is in table */
for(i=1;i<5;i++)
{
Coefs[i-1]=LVREV_GainPolyTable[Index][i];
}
Coefs[4]=0;
Gain=LVM_Polynomial(3,Coefs,T60); /* Q.24 result */
}
else
{
/* Interpolate the gain between nearest room sizes */
LVM_INT32 Gain1,Gain2;
LVM_INT32 Tot_Dist,Dist;
Tot_Dist=LVREV_GainPolyTable[Index][0]-LVREV_GainPolyTable[Index-1][0];
Dist=RoomSize-LVREV_GainPolyTable[Index-1][0];
/* Get gain for first */
for(i=1;i<5;i++)
{
Coefs[i-1]=LVREV_GainPolyTable[Index-1][i];
}
Coefs[4]=0;
Gain1=LVM_Polynomial(3,Coefs,T60); /* Q.24 result */
/* Get gain for second */
for(i=1;i<5;i++)
{
Coefs[i-1]=LVREV_GainPolyTable[Index][i];
}
Coefs[4]=0;
Gain2=LVM_Polynomial(3,Coefs,T60); /* Q.24 result */
/* Linear Interpolate the gain */
Gain = Gain1+ (((Gain2-Gain1)*Dist)/(Tot_Dist));
}
/*
* Get the inverse of gain: Q.15
* Gain is mostly above one except few cases, take only gains above 1
*/
if(Gain < 16777216L)
{
pPrivate->Gain= 32767;
}
else
{
pPrivate->Gain=(LVM_INT16)(LVM_MAXINT_32/(Gain>>8));
}
Index=((32767*100)/(100+pPrivate->NewParams.Level));
pPrivate->Gain=(LVM_INT16)((pPrivate->Gain*Index)>>15);
pPrivate->GainMixer.Target = pPrivate->Gain*Index;
}
/*
* Update the all pass comb filter coefficient
*/
if( (pPrivate->NewParams.Density != pPrivate->CurrentParams.Density) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_INT16 i;
LVM_INT32 b = pPrivate->NewParams.Density * LVREV_B_8_on_1000;
for (i=0;i<4; i++)
{
pPrivate->Mixer_SGFeedback[i].Target = b;
pPrivate->Mixer_SGFeedforward[i].Target = b;
}
}
/*
* Update the bypass mixer time constant
*/
if((pPrivate->NewParams.SampleRate != pPrivate->CurrentParams.SampleRate) ||
(pPrivate->bFirstControl == LVM_TRUE))
{
LVM_UINT16 NumChannels = 1; /* Assume MONO format */
LVM_INT32 Alpha;
Alpha = (LVM_INT32)LVM_Mixer_TimeConstant(LVREV_FEEDBACKMIXER_TC, LVM_GetFsFromTable(pPrivate->NewParams.SampleRate), NumChannels);
pPrivate->FeedbackMixer[0].Alpha=Alpha;
pPrivate->FeedbackMixer[1].Alpha=Alpha;
pPrivate->FeedbackMixer[2].Alpha=Alpha;
pPrivate->FeedbackMixer[3].Alpha=Alpha;
NumChannels = 2; /* Always stereo output */
pPrivate->BypassMixer.Alpha1 = (LVM_INT32)LVM_Mixer_TimeConstant(LVREV_BYPASSMIXER_TC, LVM_GetFsFromTable(pPrivate->NewParams.SampleRate), NumChannels);
pPrivate->BypassMixer.Alpha2 = pPrivate->BypassMixer.Alpha1;
pPrivate->GainMixer.Alpha = pPrivate->BypassMixer.Alpha1;
}
/*
* Update the bypass mixer targets
*/
if( (pPrivate->NewParams.Level != pPrivate->CurrentParams.Level) &&
(pPrivate->NewParams.OperatingMode == LVM_MODE_ON))
{
pPrivate->BypassMixer.Target2 = ((LVM_INT32)(pPrivate->NewParams.Level * 32767)/100)<<16;
pPrivate->BypassMixer.Target1 = 0x00000000;
if ((pPrivate->NewParams.Level == 0) && (pPrivate->bFirstControl == LVM_FALSE))
{
pPrivate->BypassMixer.CallbackSet2 = LVM_TRUE;
}
if (pPrivate->NewParams.Level != 0)
{
pPrivate->bDisableReverb = LVM_FALSE;
}
}
if(pPrivate->NewParams.OperatingMode != pPrivate->CurrentParams.OperatingMode)
{
if(pPrivate->NewParams.OperatingMode == LVM_MODE_ON)
{
pPrivate->BypassMixer.Target2 = ((LVM_INT32)(pPrivate->NewParams.Level * 32767)/100)<<16;
pPrivate->BypassMixer.Target1 = 0x00000000;
pPrivate->BypassMixer.CallbackSet2 = LVM_FALSE;
OperatingMode = LVM_MODE_ON;
if (pPrivate->NewParams.Level == 0)
{
pPrivate->bDisableReverb = LVM_TRUE;
}
else
{
pPrivate->bDisableReverb = LVM_FALSE;
}
}
else if (pPrivate->bFirstControl == LVM_FALSE)
{
pPrivate->BypassMixer.Target2 = 0x00000000;
pPrivate->BypassMixer.Target1 = 0x00000000;
pPrivate->BypassMixer.CallbackSet2 = LVM_TRUE;
pPrivate->GainMixer.Target = 0x03FFFFFF;
OperatingMode = LVM_MODE_ON;
}
else
{
OperatingMode = LVM_MODE_OFF;
}
}
/*
* If it is the first call to ApplyNew settings force the current to the target to begin immediate playback of the effect
*/
if(pPrivate->bFirstControl == LVM_TRUE)
{
pPrivate->BypassMixer.Current1 = pPrivate->BypassMixer.Target1;
pPrivate->BypassMixer.Current2 = pPrivate->BypassMixer.Target2;
}
/*
* Copy the new parameters
*/
pPrivate->CurrentParams = pPrivate->NewParams;
pPrivate->CurrentParams.OperatingMode = OperatingMode;
/*
* Update flag
*/
if(pPrivate->bFirstControl == LVM_TRUE)
{
pPrivate->bFirstControl = LVM_FALSE;
}
return LVREV_SUCCESS;
}
/****************************************************************************************/
/* */
/* FUNCTION: BypassMixer_Callback */
/* */
/* DESCRIPTION: */
/* Controls the On to Off operating mode transition */
/* */
/* PARAMETERS: */
/* pPrivate Pointer to the instance private parameters */
/* */
/* RETURNS: */
/* LVREV_Success Succeeded */
/* LVREV_NULLADDRESS When pPrivate is NULL */
/* */
/* NOTES: */
/* */
/****************************************************************************************/
LVM_INT32 BypassMixer_Callback (void *pCallbackData,
void *pGeneralPurpose,
LVM_INT16 GeneralPurpose )
{
LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)pCallbackData;
/*
* Avoid build warnings
*/
(void)pGeneralPurpose;
(void)GeneralPurpose;
/*
* Turn off
*/
pLVREV_Private->CurrentParams.OperatingMode = LVM_MODE_OFF;
pLVREV_Private->bDisableReverb = LVM_TRUE;
LVREV_ClearAudioBuffers((LVREV_Handle_t)pCallbackData);
return 0;
}
/* End of file */
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
#include "VectorArithmetic.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_ClearAudioBuffers */
/* */
/* DESCRIPTION: */
/* This function is used to clear the internal audio buffers of the module. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Initialisation succeeded */
/* LVREV_NULLADDRESS Instance is NULL */
/* */
/* NOTES: */
/* 1. This function must not be interrupted by the LVM_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_ClearAudioBuffers(LVREV_Handle_t hInstance)
{
LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
/*
* Check for error conditions
*/
/* Check for NULL pointers */
if(hInstance == LVM_NULL)
{
return LVREV_NULLADDRESS;
}
/*
* Clear all filter tap data, delay-lines and other signal related data
*/
LoadConst_32(0,
(void *)&pLVREV_Private->pFastData->HPTaps, /* Destination Cast to void: no dereferencing in function*/
2);
LoadConst_32(0,
(void *)&pLVREV_Private->pFastData->LPTaps, /* Destination Cast to void: no dereferencing in function*/
2);
if((LVM_UINT16)pLVREV_Private->InstanceParams.NumDelays == LVREV_DELAYLINES_4)
{
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[3], 2);
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[2], 2);
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[1], 2);
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[0], 2);
LoadConst_32(0,pLVREV_Private->pDelay_T[3], (LVM_INT16)LVREV_MAX_T3_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[2], (LVM_INT16)LVREV_MAX_T2_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[1], (LVM_INT16)LVREV_MAX_T1_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[0], (LVM_INT16)LVREV_MAX_T0_DELAY);
}
if((LVM_UINT16)pLVREV_Private->InstanceParams.NumDelays >= LVREV_DELAYLINES_2)
{
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[1], 2);
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[0], 2);
LoadConst_32(0,pLVREV_Private->pDelay_T[1], (LVM_INT16)LVREV_MAX_T1_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[0], (LVM_INT16)LVREV_MAX_T0_DELAY);
}
if((LVM_UINT16)pLVREV_Private->InstanceParams.NumDelays >= LVREV_DELAYLINES_1)
{
LoadConst_32(0, (LVM_INT32 *)&pLVREV_Private->pFastData->RevLPTaps[0], 2);
LoadConst_32(0,pLVREV_Private->pDelay_T[0], (LVM_INT16)LVREV_MAX_T0_DELAY);
}
return LVREV_SUCCESS;
}
/* End of file */
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_GetControlParameters */
/* */
/* DESCRIPTION: */
/* Request the LVREV module control parameters. The current parameter set is returned */
/* via the parameter pointer. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pControlParams Pointer to an empty parameter structure */
/* */
/* RETURNS: */
/* LVREV_Success Succeeded */
/* LVREV_NULLADDRESS When hInstance or pControlParams is NULL */
/* */
/* NOTES: */
/* 1. This function may be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetControlParameters(LVREV_Handle_t hInstance,
LVREV_ControlParams_st *pControlParams)
{
LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
/*
* Check for error conditions
*/
if((hInstance == LVM_NULL) || (pControlParams == LVM_NULL))
{
return LVREV_NULLADDRESS;
}
/*
* Return the current parameters
*/
*pControlParams = pLVREV_Private->NewParams;
return LVREV_SUCCESS;
}
/* End of file */
@@ -0,0 +1,322 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
#include "InstAlloc.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_GetInstanceHandle */
/* */
/* DESCRIPTION: */
/* This function is used to create a LVREV module instance. It returns the created */
/* instance handle through phInstance. All parameters are set to their default, */
/* inactive state. */
/* */
/* PARAMETERS: */
/* phInstance pointer to the instance handle */
/* pMemoryTable Pointer to the memory definition table */
/* pInstanceParams Pointer to the instance parameters */
/* */
/* RETURNS: */
/* LVREV_SUCCESS Succeeded */
/* LVREV_NULLADDRESS When phInstance or pMemoryTable or pInstanceParams is NULL */
/* LVREV_NULLADDRESS When one of the memory regions has a NULL pointer */
/* */
/* NOTES: */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetInstanceHandle(LVREV_Handle_t *phInstance,
LVREV_MemoryTable_st *pMemoryTable,
LVREV_InstanceParams_st *pInstanceParams)
{
INST_ALLOC SlowData;
INST_ALLOC FastData;
INST_ALLOC FastCoef;
INST_ALLOC Temporary;
LVREV_Instance_st *pLVREV_Private;
LVM_INT16 i;
LVM_UINT16 MaxBlockSize;
/*
* Check for error conditions
*/
/* Check for NULL pointers */
if((phInstance == LVM_NULL) || (pMemoryTable == LVM_NULL) || (pInstanceParams == LVM_NULL))
{
return LVREV_NULLADDRESS;
}
/* Check the memory table for NULL pointers */
for (i = 0; i < LVREV_NR_MEMORY_REGIONS; i++)
{
if (pMemoryTable->Region[i].Size!=0)
{
if (pMemoryTable->Region[i].pBaseAddress==LVM_NULL)
{
return(LVREV_NULLADDRESS);
}
}
}
/*
* Check all instance parameters are in range
*/
/* Check for a non-zero block size */
if (pInstanceParams->MaxBlockSize == 0)
{
return LVREV_OUTOFRANGE;
}
/* Check for a valid number of delay lines */
if ((pInstanceParams->NumDelays != LVREV_DELAYLINES_1)&&
(pInstanceParams->NumDelays != LVREV_DELAYLINES_2)&&
(pInstanceParams->NumDelays != LVREV_DELAYLINES_4))
{
return LVREV_OUTOFRANGE;
}
/*
* Initialise the InstAlloc instances
*/
InstAlloc_Init(&SlowData, pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress);
InstAlloc_Init(&FastData, pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress);
InstAlloc_Init(&FastCoef, pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress);
InstAlloc_Init(&Temporary, pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress);
/*
* Zero all memory regions
*/
LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size)/sizeof(LVM_INT16)));
LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size)/sizeof(LVM_INT16)));
LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size)/sizeof(LVM_INT16)));
LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_TEMPORARY_FAST].Size)/sizeof(LVM_INT16)));
/*
* Set the instance handle if not already initialised
*/
if (*phInstance == LVM_NULL)
{
*phInstance = InstAlloc_AddMember(&SlowData, sizeof(LVREV_Instance_st));
}
pLVREV_Private =(LVREV_Instance_st *)*phInstance;
pLVREV_Private->MemoryTable = *pMemoryTable;
if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_4)
{
MaxBlockSize = LVREV_MAX_AP3_DELAY;
}
else if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_2)
{
MaxBlockSize = LVREV_MAX_AP1_DELAY;
}
else
{
MaxBlockSize = LVREV_MAX_AP0_DELAY;
}
if(MaxBlockSize>pInstanceParams->MaxBlockSize)
{
MaxBlockSize=pInstanceParams->MaxBlockSize;
}
/*
* Set the data, coefficient and temporary memory pointers
*/
pLVREV_Private->pFastData = InstAlloc_AddMember(&FastData, sizeof(LVREV_FastData_st)); /* Fast data memory base address */
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
{
pLVREV_Private->pDelay_T[3] = InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * sizeof(LVM_INT32));
pLVREV_Private->pDelay_T[2] = InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * sizeof(LVM_INT32));
pLVREV_Private->pDelay_T[1] = InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
for( i = 0; i < 4; i++)
{
pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* Scratch for each delay line output */
}
LoadConst_32(0,pLVREV_Private->pDelay_T[3] ,(LVM_INT16)LVREV_MAX_T3_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[2] ,(LVM_INT16)LVREV_MAX_T2_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[1] ,(LVM_INT16)LVREV_MAX_T1_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[0] ,(LVM_INT16)LVREV_MAX_T0_DELAY);
}
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
{
pLVREV_Private->pDelay_T[1] = InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
for( i = 0; i < 2; i++)
{
pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* Scratch for each delay line output */
}
LoadConst_32(0,pLVREV_Private->pDelay_T[1] , (LVM_INT16)LVREV_MAX_T1_DELAY);
LoadConst_32(0,pLVREV_Private->pDelay_T[0] , (LVM_INT16)LVREV_MAX_T0_DELAY);
}
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
{
pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
for( i = 0; i < 1; i++)
{
pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* Scratch for each delay line output */
}
LoadConst_32(0,pLVREV_Private->pDelay_T[0] , (LVM_INT16)LVREV_MAX_T0_DELAY);
}
/* All-pass delay buffer addresses and sizes */
pLVREV_Private->T[0] = LVREV_MAX_T0_DELAY;
pLVREV_Private->T[1] = LVREV_MAX_T1_DELAY;
pLVREV_Private->T[2] = LVREV_MAX_T2_DELAY;
pLVREV_Private->T[3] = LVREV_MAX_T3_DELAY;
pLVREV_Private->AB_Selection = 1; /* Select smoothing A to B */
pLVREV_Private->pFastCoef = InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st)); /* Fast coefficient memory base address */
pLVREV_Private->pScratch = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* General purpose scratch */
pLVREV_Private->pInputSave = InstAlloc_AddMember(&Temporary, 2 * sizeof(LVM_INT32) * MaxBlockSize); /* Mono->stereo input save for end mix */
LoadConst_32(0, pLVREV_Private->pInputSave, (LVM_INT16)(MaxBlockSize*2));
/*
* Save the instance parameters in the instance structure
*/
pLVREV_Private->InstanceParams = *pInstanceParams;
/*
* Set the parameters to invalid
*/
pLVREV_Private->CurrentParams.SampleRate = LVM_FS_INVALID;
pLVREV_Private->CurrentParams.OperatingMode = LVM_MODE_DUMMY;
pLVREV_Private->CurrentParams.SourceFormat = LVM_SOURCE_DUMMY;
pLVREV_Private->bControlPending = LVM_FALSE;
pLVREV_Private->bFirstControl = LVM_TRUE;
pLVREV_Private->bDisableReverb = LVM_FALSE;
/*
* Set mixer parameters
*/
pLVREV_Private->BypassMixer.CallbackParam2 = 0;
pLVREV_Private->BypassMixer.pCallbackHandle2 = pLVREV_Private;
pLVREV_Private->BypassMixer.pGeneralPurpose2 = LVM_NULL;
pLVREV_Private->BypassMixer.pCallBack2 = BypassMixer_Callback;
pLVREV_Private->BypassMixer.CallbackSet2 = LVM_FALSE;
pLVREV_Private->BypassMixer.Current2 = 0;
pLVREV_Private->BypassMixer.Target2 = 0;
pLVREV_Private->BypassMixer.CallbackParam1 = 0;
pLVREV_Private->BypassMixer.pCallbackHandle1 = LVM_NULL;
pLVREV_Private->BypassMixer.pGeneralPurpose1 = LVM_NULL;
pLVREV_Private->BypassMixer.pCallBack1 = LVM_NULL;
pLVREV_Private->BypassMixer.CallbackSet1 = LVM_FALSE;
pLVREV_Private->BypassMixer.Current1 = 0x00000000;
pLVREV_Private->BypassMixer.Target1 = 0x00000000;
pLVREV_Private->RoomSizeInms = 100; // 100 msec
/*
* Set the output gain mixer parameters
*/
pLVREV_Private->GainMixer.CallbackParam = 0;
pLVREV_Private->GainMixer.pCallbackHandle = LVM_NULL;
pLVREV_Private->GainMixer.pGeneralPurpose = LVM_NULL;
pLVREV_Private->GainMixer.pCallBack = LVM_NULL;
pLVREV_Private->GainMixer.CallbackSet = LVM_FALSE;
pLVREV_Private->GainMixer.Current = 0x03ffffff;
pLVREV_Private->GainMixer.Target = 0x03ffffff;
/*
* Set the All-Pass Filter mixers
*/
for (i=0; i<4; i++)
{
pLVREV_Private->pOffsetA[i] = pLVREV_Private->pDelay_T[i];
pLVREV_Private->pOffsetB[i] = pLVREV_Private->pDelay_T[i];
/* Delay tap selection mixer */
pLVREV_Private->Mixer_APTaps[i].CallbackParam2 = 0;
pLVREV_Private->Mixer_APTaps[i].pCallbackHandle2 = LVM_NULL;
pLVREV_Private->Mixer_APTaps[i].pGeneralPurpose2 = LVM_NULL;
pLVREV_Private->Mixer_APTaps[i].pCallBack2 = LVM_NULL;
pLVREV_Private->Mixer_APTaps[i].CallbackSet2 = LVM_FALSE;
pLVREV_Private->Mixer_APTaps[i].Current2 = 0;
pLVREV_Private->Mixer_APTaps[i].Target2 = 0;
pLVREV_Private->Mixer_APTaps[i].CallbackParam1 = 0;
pLVREV_Private->Mixer_APTaps[i].pCallbackHandle1 = LVM_NULL;
pLVREV_Private->Mixer_APTaps[i].pGeneralPurpose1 = LVM_NULL;
pLVREV_Private->Mixer_APTaps[i].pCallBack1 = LVM_NULL;
pLVREV_Private->Mixer_APTaps[i].CallbackSet1 = LVM_FALSE;
pLVREV_Private->Mixer_APTaps[i].Current1 = 0;
pLVREV_Private->Mixer_APTaps[i].Target1 = 0x7fffffff;
/* Feedforward mixer */
pLVREV_Private->Mixer_SGFeedforward[i].CallbackParam = 0;
pLVREV_Private->Mixer_SGFeedforward[i].pCallbackHandle = LVM_NULL;
pLVREV_Private->Mixer_SGFeedforward[i].pGeneralPurpose = LVM_NULL;
pLVREV_Private->Mixer_SGFeedforward[i].pCallBack = LVM_NULL;
pLVREV_Private->Mixer_SGFeedforward[i].CallbackSet = LVM_FALSE;
pLVREV_Private->Mixer_SGFeedforward[i].Current = 0;
pLVREV_Private->Mixer_SGFeedforward[i].Target = 0;
/* Feedback mixer */
pLVREV_Private->Mixer_SGFeedback[i].CallbackParam = 0;
pLVREV_Private->Mixer_SGFeedback[i].pCallbackHandle = LVM_NULL;
pLVREV_Private->Mixer_SGFeedback[i].pGeneralPurpose = LVM_NULL;
pLVREV_Private->Mixer_SGFeedback[i].pCallBack = LVM_NULL;
pLVREV_Private->Mixer_SGFeedback[i].CallbackSet = LVM_FALSE;
pLVREV_Private->Mixer_SGFeedback[i].Current = 0;
pLVREV_Private->Mixer_SGFeedback[i].Target = 0;
/* Feedback gain mixer */
pLVREV_Private->FeedbackMixer[i].CallbackParam = 0;
pLVREV_Private->FeedbackMixer[i].pCallbackHandle = LVM_NULL;
pLVREV_Private->FeedbackMixer[i].pGeneralPurpose = LVM_NULL;
pLVREV_Private->FeedbackMixer[i].pCallBack = LVM_NULL;
pLVREV_Private->FeedbackMixer[i].CallbackSet = LVM_FALSE;
pLVREV_Private->FeedbackMixer[i].Current = 0;
pLVREV_Private->FeedbackMixer[i].Target = 0;
}
/* Delay tap index */
pLVREV_Private->A_DelaySize[0] = LVREV_MAX_AP0_DELAY;
pLVREV_Private->B_DelaySize[0] = LVREV_MAX_AP0_DELAY;
pLVREV_Private->A_DelaySize[1] = LVREV_MAX_AP1_DELAY;
pLVREV_Private->B_DelaySize[1] = LVREV_MAX_AP1_DELAY;
pLVREV_Private->A_DelaySize[2] = LVREV_MAX_AP2_DELAY;
pLVREV_Private->B_DelaySize[2] = LVREV_MAX_AP2_DELAY;
pLVREV_Private->A_DelaySize[3] = LVREV_MAX_AP3_DELAY;
pLVREV_Private->B_DelaySize[3] = LVREV_MAX_AP3_DELAY;
LVREV_ClearAudioBuffers(*phInstance);
return LVREV_SUCCESS;
}
/* End of file */
@@ -0,0 +1,245 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
#include "InstAlloc.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_GetMemoryTable */
/* */
/* DESCRIPTION: */
/* This function is used for memory allocation and free. It can be called in */
/* two ways: */
/* */
/* hInstance = NULL Returns the memory requirements */
/* hInstance = Instance handle Returns the memory requirements and allocated */
/* base addresses. */
/* */
/* When this function is called for memory allocation (hInstance=NULL) the memory */
/* base address pointers are NULL on return. */
/* */
/* When the function is called for free (hInstance = Instance Handle) the memory */
/* table returns the allocated memory and base addresses used during initialisation. */
/* */
/* PARAMETERS: */
/* hInstance Instance Handle */
/* pMemoryTable Pointer to an empty memory table */
/* pInstanceParams Pointer to the instance parameters */
/* */
/* RETURNS: */
/* LVREV_Success Succeeded */
/* LVREV_NULLADDRESS When pMemoryTable is NULL */
/* LVREV_NULLADDRESS When requesting memory requirements and pInstanceParams */
/* is NULL */
/* */
/* NOTES: */
/* 1. This function may be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetMemoryTable(LVREV_Handle_t hInstance,
LVREV_MemoryTable_st *pMemoryTable,
LVREV_InstanceParams_st *pInstanceParams)
{
INST_ALLOC SlowData;
INST_ALLOC FastData;
INST_ALLOC FastCoef;
INST_ALLOC Temporary;
LVM_INT16 i;
LVM_UINT16 MaxBlockSize;
/*
* Check for error conditions
*/
/* Check for NULL pointer */
if (pMemoryTable == LVM_NULL)
{
return(LVREV_NULLADDRESS);
}
/*
* Check all instance parameters are in range
*/
if (pInstanceParams != LVM_NULL)
{
/*
* Call for memory allocation, so check the parameters
*/
/* Check for a non-zero block size */
if (pInstanceParams->MaxBlockSize == 0)
{
return LVREV_OUTOFRANGE;
}
/* Check for a valid number of delay lines */
if ((pInstanceParams->NumDelays != LVREV_DELAYLINES_1) &&
(pInstanceParams->NumDelays != LVREV_DELAYLINES_2) &&
(pInstanceParams->NumDelays != LVREV_DELAYLINES_4))
{
return LVREV_OUTOFRANGE;
}
}
/*
* Initialise the InstAlloc instances
*/
InstAlloc_Init(&SlowData, (void *)LVM_NULL);
InstAlloc_Init(&FastData, (void *)LVM_NULL);
InstAlloc_Init(&FastCoef, (void *)LVM_NULL);
InstAlloc_Init(&Temporary, (void *)LVM_NULL);
/*
* Fill in the memory table
*/
if (hInstance == LVM_NULL)
{
/*
* Check for null pointers
*/
if (pInstanceParams == LVM_NULL)
{
return(LVREV_NULLADDRESS);
}
/*
* Select the maximum internal block size
*/
if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_4)
{
MaxBlockSize = LVREV_MAX_AP3_DELAY;
}
else if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_2)
{
MaxBlockSize = LVREV_MAX_AP1_DELAY;
}
else
{
MaxBlockSize = LVREV_MAX_AP0_DELAY;
}
if(MaxBlockSize>pInstanceParams->MaxBlockSize)
{
MaxBlockSize=pInstanceParams->MaxBlockSize;
}
/*
* Slow data memory
*/
InstAlloc_AddMember(&SlowData, sizeof(LVREV_Instance_st));
pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size = InstAlloc_GetTotal(&SlowData);
pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Type = LVM_PERSISTENT_SLOW_DATA;
pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;
/*
* Persistent fast data memory
*/
InstAlloc_AddMember(&FastData, sizeof(LVREV_FastData_st));
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
{
InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * sizeof(LVM_INT32));
InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * sizeof(LVM_INT32));
InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
}
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
{
InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
}
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
{
InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
}
pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size = InstAlloc_GetTotal(&FastData);
pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Type = LVM_PERSISTENT_FAST_DATA;
pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
/*
* Persistent fast coefficient memory
*/
InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st));
pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size = InstAlloc_GetTotal(&FastCoef);
pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Type = LVM_PERSISTENT_FAST_COEF;
pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
/*
* Temporary fast memory
*/
InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* General purpose scratch memory */
InstAlloc_AddMember(&Temporary, 2*sizeof(LVM_INT32) * MaxBlockSize); /* Mono->stereo input saved for end mix */
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
{
for(i=0; i<4; i++)
{
InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* A Scratch buffer for each delay line */
}
}
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
{
for(i=0; i<2; i++)
{
InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* A Scratch buffer for each delay line */
}
}
if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
{
for(i=0; i<1; i++)
{
InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* A Scratch buffer for each delay line */
}
}
pMemoryTable->Region[LVM_TEMPORARY_FAST].Size = InstAlloc_GetTotal(&Temporary);
pMemoryTable->Region[LVM_TEMPORARY_FAST].Type = LVM_TEMPORARY_FAST;
pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress = LVM_NULL;
}
else
{
LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
/*
* Read back memory allocation table
*/
*pMemoryTable = pLVREV_Private->MemoryTable;
}
return(LVREV_SUCCESS);
}
/* End of file */
@@ -0,0 +1,189 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __LVREV_PRIVATE_H__
#define __LVREV_PRIVATE_H__
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV.h"
#include "LVREV_Tables.h"
#include "BIQUAD.h"
#include "Filter.h"
#include "VectorArithmetic.h"
#include "Mixer.h"
#include "LVM_Macros.h"
/****************************************************************************************/
/* */
/* Defines */
/* */
/****************************************************************************************/
/* General */
#define ONE_OVER_SQRT_TWO 23170 /* 1/sqrt(2) * 2^15 */
#define LVREV_B_8_on_1000 17179869 /* 0.8 * 2^31 */
#define LVREV_HEADROOM 8192 /* -12dB * 2^15 */
#define LVREV_2_9_INQ29 1583769190L /* 2.9 in Q29 format */
#define LVREV_MIN3DB 0x5A82 /* -3dB in Q15 format */
/* Intenal constants */
#define LVREV_LP_Poly_Order 4
#define LVREV_LP_Poly_Shift 5
#define LVREV_T_3_Power_0_on_4 32768
#define LVREV_T_3_Power_1_on_4 43125
#define LVREV_T_3_Power_2_on_4 56755
#define LVREV_T_3_Power_3_on_4 74694
#define LVREV_T60_SCALE 306774 /*(32767/7000)<<16 */
#define LVREV_T_3_Power_minus0_on_4 32767 /* 3^(-0/4) * 2^15 */
#define LVREV_T_3_Power_minus1_on_4 24898 /* 3^(-1/4) * 2^15 */
#define LVREV_T_3_Power_minus2_on_4 18919 /* 3^(-2/4) * 2^15 */
#define LVREV_T_3_Power_minus3_on_4 14375 /* 3^(-3/4) * 2^15 */
#define LVREV_MAX_T3_DELAY 2527 /* ((48000 * 120 * LVREV_T_3_Power_minus3_on_4) >> 15) / 1000 */
#define LVREV_MAX_T2_DELAY 3326 /* ((48000 * 120 * LVREV_T_3_Power_minus2_on_4) >> 15) / 1000 */
#define LVREV_MAX_T1_DELAY 4377 /* ((48000 * 120 * LVREV_T_3_Power_minus1_on_4) >> 15) / 1000 */
#define LVREV_MAX_T0_DELAY 5760 /* ((48000 * 120 * LVREV_T_3_Power_minus0_on_4) >> 15) / 1000 */
#define LVREV_MAX_AP3_DELAY 1685 /* ((48000 * 120 * LVREV_T_3_Power_minus3_on_4) >> 15) / 1500 */
#define LVREV_MAX_AP2_DELAY 2218 /* ((48000 * 120 * LVREV_T_3_Power_minus2_on_4) >> 15) / 1500 */
#define LVREV_MAX_AP1_DELAY 2918 /* ((48000 * 120 * LVREV_T_3_Power_minus1_on_4) >> 15) / 1500 */
#define LVREV_MAX_AP0_DELAY 3840 /* ((48000 * 120 * LVREV_T_3_Power_minus0_on_4) >> 15) / 1500 */
#define LVREV_BYPASSMIXER_TC 1000 /* Bypass mixer time constant*/
#define LVREV_ALLPASS_TC 1000 /* All-pass filter time constant */
#define LVREV_ALLPASS_TAP_TC 10000 /* All-pass filter dely tap change */
#define LVREV_FEEDBACKMIXER_TC 100 /* Feedback mixer time constant*/
#define LVREV_OUTPUTGAIN_SHIFT 5 /* Bits shift for output gain correction */
/* Parameter limits */
#define LVREV_NUM_FS 9 /* Number of supported sample rates */
#define LVREV_MAXBLKSIZE_LIMIT 64 /* Maximum block size low limit */
#define LVREV_MAX_LEVEL 100 /* Maximum level, 100% */
#define LVREV_MIN_LPF_CORNER 50 /* Low pass filter limits */
#define LVREV_MAX_LPF_CORNER 23999
#define LVREV_MIN_HPF_CORNER 20 /* High pass filrer limits */
#define LVREV_MAX_HPF_CORNER 1000
#define LVREV_MAX_T60 7000 /* Maximum T60 time in ms */
#define LVREV_MAX_DENSITY 100 /* Maximum density, 100% */
#define LVREV_MAX_DAMPING 100 /* Maximum damping, 100% */
#define LVREV_MAX_ROOMSIZE 100 /* Maximum room size, 100% */
/****************************************************************************************/
/* */
/* Structures */
/* */
/****************************************************************************************/
/* Fast data structure */
typedef struct
{
Biquad_1I_Order1_Taps_t HPTaps; /* High pass filter taps */
Biquad_1I_Order1_Taps_t LPTaps; /* Low pass filter taps */
Biquad_1I_Order1_Taps_t RevLPTaps[4]; /* Reverb low pass filters taps */
} LVREV_FastData_st;
/* Fast coefficient structure */
typedef struct
{
Biquad_Instance_t HPCoefs; /* High pass filter coefficients */
Biquad_Instance_t LPCoefs; /* Low pass filter coefficients */
Biquad_Instance_t RevLPCoefs[4]; /* Reverb low pass filters coefficients */
} LVREV_FastCoef_st;
/* Instance parameter structure */
typedef struct
{
/* General */
LVREV_InstanceParams_st InstanceParams; /* Initialisation time instance parameters */
LVREV_MemoryTable_st MemoryTable; /* Memory table */
LVREV_ControlParams_st CurrentParams; /* Parameters being used */
LVREV_ControlParams_st NewParams; /* New parameters from the calling application */
LVM_CHAR bControlPending; /* Flag to indicate new parameters are available */
LVM_CHAR bFirstControl; /* Flag to indicate that the control function is called for the first time */
LVM_CHAR bDisableReverb; /* Flag to indicate that the mix level is 0% and the reverb can be disabled */
LVM_INT32 RoomSizeInms; /* Room size in msec */
LVM_INT32 MaxBlkLen; /* Maximum block size for internal processing */
/* Aligned memory pointers */
LVREV_FastData_st *pFastData; /* Fast data memory base address */
LVREV_FastCoef_st *pFastCoef; /* Fast coefficient memory base address */
LVM_INT32 *pScratchDelayLine[4]; /* Delay line scratch memory */
LVM_INT32 *pScratch; /* Multi ussge scratch */
LVM_INT32 *pInputSave; /* Reverb block input save for dry/wet mixing*/
/* Feedback matrix */
Mix_1St_Cll_t FeedbackMixer[4]; /* Mixer for Pop and Click Supression caused by feedback Gain */
/* All-Pass Filter */
LVM_INT32 T[4]; /* Maximum delay size of buffer */
LVM_INT32 *pDelay_T[4]; /* Pointer to delay buffers */
LVM_INT32 Delay_AP[4]; /* Offset to AP delay buffer start */
LVM_INT16 AB_Selection; /* Smooth from tap A to B when 1 otherwise B to A */
LVM_INT32 A_DelaySize[4]; /* A delay length in samples */
LVM_INT32 B_DelaySize[4]; /* B delay length in samples */
LVM_INT32 *pOffsetA[4]; /* Offset for the A delay tap */
LVM_INT32 *pOffsetB[4]; /* Offset for the B delay tap */
Mix_2St_Cll_t Mixer_APTaps[4]; /* Smoothed AP delay mixer */
Mix_1St_Cll_t Mixer_SGFeedback[4]; /* Smoothed SAfeedback gain */
Mix_1St_Cll_t Mixer_SGFeedforward[4]; /* Smoothed AP feedforward gain */
/* Output gain */
Mix_2St_Cll_t BypassMixer; /* Dry/wet mixer */
LVM_INT16 Gain; /* Gain applied to output to maintain average signal power */
Mix_1St_Cll_t GainMixer; /* Gain smoothing */
} LVREV_Instance_st;
/****************************************************************************************/
/* */
/* Function prototypes */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_ApplyNewSettings(LVREV_Instance_st *pPrivate);
void ReverbBlock(LVM_INT32 *pInput,
LVM_INT32 *pOutput,
LVREV_Instance_st *pPrivate,
LVM_UINT16 NumSamples);
LVM_INT32 BypassMixer_Callback(void *pCallbackData,
void *pGeneralPurpose,
LVM_INT16 GeneralPurpose );
#ifdef __cplusplus
}
#endif
#endif /** __LVREV_PRIVATE_H__ **/
/* End of file */
@@ -0,0 +1,485 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
#include "VectorArithmetic.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_Process */
/* */
/* DESCRIPTION: */
/* Process function for the LVREV module. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pInData Pointer to the input data */
/* pOutData Pointer to the output data */
/* NumSamples Number of samples in the input buffer */
/* */
/* RETURNS: */
/* LVREV_Success Succeeded */
/* LVREV_INVALIDNUMSAMPLES NumSamples was larger than the maximum block size */
/* LVREV_NULLADDRESS When one of hInstance, pInData or pOutData is NULL */
/* */
/* NOTES: */
/* 1. The input and output buffers must be 32-bit aligned */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_Process(LVREV_Handle_t hInstance,
const LVM_INT32 *pInData,
LVM_INT32 *pOutData,
const LVM_UINT16 NumSamples)
{
LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
LVM_INT32 *pInput = (LVM_INT32 *)pInData;
LVM_INT32 *pOutput = pOutData;
LVM_INT32 SamplesToProcess, RemainingSamples;
LVM_INT32 format = 1;
/*
* Check for error conditions
*/
/* Check for NULL pointers */
if((hInstance == LVM_NULL) || (pInData == LVM_NULL) || (pOutData == LVM_NULL))
{
return LVREV_NULLADDRESS;
}
/*
* Apply the new controls settings if required
*/
if(pLVREV_Private->bControlPending == LVM_TRUE)
{
LVREV_ReturnStatus_en errorCode;
/*
* Clear the pending flag and update the control settings
*/
pLVREV_Private->bControlPending = LVM_FALSE;
errorCode = LVREV_ApplyNewSettings (pLVREV_Private);
if(errorCode != LVREV_SUCCESS)
{
return errorCode;
}
}
/*
* Trap the case where the number of samples is zero.
*/
if (NumSamples == 0)
{
return LVREV_SUCCESS;
}
/*
* If OFF copy and reformat the data as necessary
*/
if (pLVREV_Private->CurrentParams.OperatingMode == LVM_MODE_OFF)
{
if(pInput != pOutput)
{
/*
* Copy the data to the output buffer, convert to stereo is required
*/
if(pLVREV_Private->CurrentParams.SourceFormat == LVM_MONO){
MonoTo2I_32(pInput, pOutput, NumSamples);
} else {
Copy_16((LVM_INT16 *)pInput,
(LVM_INT16 *)pOutput,
(LVM_INT16)(NumSamples << 2)); // 32 bit data, stereo
}
}
return LVREV_SUCCESS;
}
RemainingSamples = (LVM_INT32)NumSamples;
if (pLVREV_Private->CurrentParams.SourceFormat != LVM_MONO)
{
format = 2;
}
while (RemainingSamples!=0)
{
/*
* Process the data
*/
if(RemainingSamples > pLVREV_Private->MaxBlkLen)
{
SamplesToProcess = pLVREV_Private->MaxBlkLen;
RemainingSamples = (LVM_INT16)(RemainingSamples - SamplesToProcess);
}
else
{
SamplesToProcess = RemainingSamples;
RemainingSamples = 0;
}
ReverbBlock(pInput, pOutput, pLVREV_Private, (LVM_UINT16)SamplesToProcess);
pInput = (LVM_INT32 *)(pInput +(SamplesToProcess*format));
pOutput = (LVM_INT32 *)(pOutput+(SamplesToProcess*2)); // Always stereo output
}
return LVREV_SUCCESS;
}
/****************************************************************************************/
/* */
/* FUNCTION: ReverbBlock */
/* */
/* DESCRIPTION: */
/* Process function for the LVREV module. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pInData Pointer to the input data */
/* pOutData Pointer to the output data */
/* NumSamples Number of samples in the input buffer */
/* */
/* RETURNS: */
/* LVREV_Success Succeeded */
/* LVREV_INVALIDNUMSAMPLES NumSamples was larger than the maximum block size */
/* LVREV_NULLADDRESS When one of hInstance, pInData or pOutData is NULL */
/* */
/* NOTES: */
/* 1. The input and output buffers must be 32-bit aligned */
/* */
/****************************************************************************************/
void ReverbBlock(LVM_INT32 *pInput, LVM_INT32 *pOutput, LVREV_Instance_st *pPrivate, LVM_UINT16 NumSamples)
{
LVM_INT16 j, size;
LVM_INT32 *pDelayLine;
LVM_INT32 *pDelayLineInput = pPrivate->pScratch;
LVM_INT32 *pScratch = pPrivate->pScratch;
LVM_INT32 *pIn;
LVM_INT32 *pTemp = pPrivate->pInputSave;
LVM_INT32 NumberOfDelayLines;
/******************************************************************************
* All calculations will go into the buffer pointed to by pTemp, this will *
* then be mixed with the original input to create the final output. *
* *
* When INPLACE processing is selected this must be a temporary buffer and *
* hence this is the worst case, so for simplicity this will ALWAYS be so *
* *
* The input buffer will remain untouched until the output of the mixer if *
* INPLACE processing is selected. *
* *
* The temp buffer will always be NumSamples in size regardless of MONO or *
* STEREO input. In the case of stereo input all processing is done in MONO *
* and the final output is converted to STEREO after the mixer *
******************************************************************************/
if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_4 )
{
NumberOfDelayLines = 4;
}
else if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_2 )
{
NumberOfDelayLines = 2;
}
else
{
NumberOfDelayLines = 1;
}
if(pPrivate->CurrentParams.SourceFormat == LVM_MONO)
{
pIn = pInput;
}
else
{
/*
* Stereo to mono conversion
*/
From2iToMono_32( pInput,
pTemp,
(LVM_INT16)NumSamples);
pIn = pTemp;
}
Mult3s_32x16(pIn,
(LVM_INT16)LVREV_HEADROOM,
pTemp,
(LVM_INT16)NumSamples);
/*
* High pass filter
*/
FO_1I_D32F32C31_TRC_WRA_01( &pPrivate->pFastCoef->HPCoefs,
pTemp,
pTemp,
(LVM_INT16)NumSamples);
/*
* Low pass filter
*/
FO_1I_D32F32C31_TRC_WRA_01( &pPrivate->pFastCoef->LPCoefs,
pTemp,
pTemp,
(LVM_INT16)NumSamples);
/*
* Process all delay lines
*/
for(j = 0; j < NumberOfDelayLines; j++)
{
pDelayLine = pPrivate->pScratchDelayLine[j];
/*
* All-pass filter with pop and click suppression
*/
/* Get the smoothed, delayed output. Put it in the output buffer */
MixSoft_2St_D32C31_SAT(&pPrivate->Mixer_APTaps[j],
pPrivate->pOffsetA[j],
pPrivate->pOffsetB[j],
pDelayLine,
(LVM_INT16)NumSamples);
/* Re-align the all pass filter delay buffer and copying the fixed delay data to the AP delay in the process */
Copy_16((LVM_INT16 *)&pPrivate->pDelay_T[j][NumSamples],
(LVM_INT16 *)pPrivate->pDelay_T[j],
(LVM_INT16)((pPrivate->T[j]-NumSamples) << 1)); /* 32-bit data */
/* Apply the smoothed feedback and save to fixed delay input (currently empty) */
MixSoft_1St_D32C31_WRA(&pPrivate->Mixer_SGFeedback[j],
pDelayLine,
&pPrivate->pDelay_T[j][pPrivate->T[j]-NumSamples],
(LVM_INT16)NumSamples);
/* Sum into the AP delay line */
Mac3s_Sat_32x16(&pPrivate->pDelay_T[j][pPrivate->T[j]-NumSamples],
-0x7fff, /* Invert since the feedback coefficient is negative */
&pPrivate->pDelay_T[j][pPrivate->Delay_AP[j]-NumSamples],
(LVM_INT16)NumSamples);
/* Apply smoothed feedforward sand save to fixed delay input (currently empty) */
MixSoft_1St_D32C31_WRA(&pPrivate->Mixer_SGFeedforward[j],
&pPrivate->pDelay_T[j][pPrivate->Delay_AP[j]-NumSamples],
&pPrivate->pDelay_T[j][pPrivate->T[j]-NumSamples],
(LVM_INT16)NumSamples);
/* Sum into the AP output */
Mac3s_Sat_32x16(&pPrivate->pDelay_T[j][pPrivate->T[j]-NumSamples],
0x7fff,
pDelayLine,
(LVM_INT16)NumSamples);
/*
* Feedback gain
*/
MixSoft_1St_D32C31_WRA(&pPrivate->FeedbackMixer[j], pDelayLine, pDelayLine, NumSamples);
/*
* Low pass filter
*/
FO_1I_D32F32C31_TRC_WRA_01( &pPrivate->pFastCoef->RevLPCoefs[j],
pDelayLine,
pDelayLine,
(LVM_INT16)NumSamples);
}
/*
* Apply rotation matrix and delay samples
*/
for(j = 0; j < NumberOfDelayLines; j++)
{
Copy_16( (LVM_INT16*)(pTemp),
(LVM_INT16*)(pDelayLineInput),
(LVM_INT16)(NumSamples << 1));
/*
* Rotation matrix mix
*/
switch(j)
{
case 3:
/*
* Add delay line 1 and 2 contribution
*/
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[1], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[2], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
break;
case 2:
/*
* Add delay line 0 and 3 contribution
*/
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[0], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[3], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
break;
case 1:
if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_4)
{
/*
* Add delay line 0 and 3 contribution
*/
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[0], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
Add2_Sat_32x32(pPrivate->pScratchDelayLine[3], pDelayLineInput, (LVM_INT16)NumSamples);
}
else
{
/*
* Add delay line 0 and 1 contribution
*/
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[0], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[1], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
}
break;
case 0:
if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_4)
{
/*
* Add delay line 1 and 2 contribution
*/
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[1], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
Add2_Sat_32x32(pPrivate->pScratchDelayLine[2], pDelayLineInput, (LVM_INT16)NumSamples);
}
else if(pPrivate->InstanceParams.NumDelays == LVREV_DELAYLINES_2)
{
/*
* Add delay line 0 and 1 contribution
*/
Add2_Sat_32x32(pPrivate->pScratchDelayLine[0], pDelayLineInput, (LVM_INT16)NumSamples);
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[1], -0x8000, pDelayLineInput, (LVM_INT16)NumSamples);
}
else
{
/*
* Add delay line 0 contribution
*/
/* SOURCE DESTINATION*/
Add2_Sat_32x32(pPrivate->pScratchDelayLine[0], pDelayLineInput, (LVM_INT16)NumSamples);
}
break;
default:
break;
}
/*
* Delay samples
*/
Copy_16((LVM_INT16 *)pDelayLineInput,
(LVM_INT16 *)&pPrivate->pDelay_T[j][pPrivate->T[j]-NumSamples],
(LVM_INT16)(NumSamples << 1)); /* 32-bit data */
}
/*
* Create stereo output
*/
switch(pPrivate->InstanceParams.NumDelays)
{
case LVREV_DELAYLINES_4:
Add2_Sat_32x32(pPrivate->pScratchDelayLine[3],
pPrivate->pScratchDelayLine[0],
(LVM_INT16)NumSamples);
Add2_Sat_32x32(pPrivate->pScratchDelayLine[2],
pPrivate->pScratchDelayLine[1],
(LVM_INT16)NumSamples);
JoinTo2i_32x32(pPrivate->pScratchDelayLine[0],
pPrivate->pScratchDelayLine[1],
pTemp,
(LVM_INT16)NumSamples);
break;
case LVREV_DELAYLINES_2:
Copy_16( (LVM_INT16*)pPrivate->pScratchDelayLine[1],
(LVM_INT16*)pScratch,
(LVM_INT16)(NumSamples << 1));
Mac3s_Sat_32x16(pPrivate->pScratchDelayLine[0],
-0x8000,
pScratch,
(LVM_INT16)NumSamples);
Add2_Sat_32x32(pPrivate->pScratchDelayLine[1],
pPrivate->pScratchDelayLine[0],
(LVM_INT16)NumSamples);
JoinTo2i_32x32(pPrivate->pScratchDelayLine[0],
pScratch,
pTemp,
(LVM_INT16)NumSamples);
break;
case LVREV_DELAYLINES_1:
MonoTo2I_32(pPrivate->pScratchDelayLine[0],
pTemp,
(LVM_INT16)NumSamples);
break;
default:
break;
}
/*
* Dry/wet mixer
*/
size = (LVM_INT16)(NumSamples << 1);
MixSoft_2St_D32C31_SAT(&pPrivate->BypassMixer,
pTemp,
pTemp,
pOutput,
size);
/* Apply Gain*/
Shift_Sat_v32xv32 (LVREV_OUTPUTGAIN_SHIFT,
pOutput,
pOutput,
size);
MixSoft_1St_D32C31_WRA(&pPrivate->GainMixer,
pOutput,
pOutput,
size);
return;
}
/* End of file */
@@ -0,0 +1,119 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
/****************************************************************************************/
/* */
/* FUNCTION: LVREV_SetControlParameters */
/* */
/* DESCRIPTION: */
/* Sets or changes the LVREV module parameters. */
/* */
/* PARAMETERS: */
/* hInstance Instance handle */
/* pNewParams Pointer to a parameter structure */
/* */
/* RETURNS: */
/* LVM_Success Succeeded */
/* LVREV_NULLADDRESS When hInstance or pNewParams is NULL */
/* LVREV_OUTOFRANGE When any of the new parameters is out of range */
/* */
/* NOTES: */
/* 1. This function may be interrupted by the LVREV_Process function */
/* */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_SetControlParameters(LVREV_Handle_t hInstance,
LVREV_ControlParams_st *pNewParams)
{
LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
/*
* Check for error conditions
*/
if((hInstance == LVM_NULL) || (pNewParams == LVM_NULL))
{
return LVREV_NULLADDRESS;
}
/*
* Check all new control parameters are in range
*/
if( ((pNewParams->OperatingMode != LVM_MODE_OFF) && (pNewParams->OperatingMode != LVM_MODE_ON)) ||
((pNewParams->SampleRate != LVM_FS_8000) && (pNewParams->SampleRate != LVM_FS_11025) && (pNewParams->SampleRate != LVM_FS_12000) &&
(pNewParams->SampleRate != LVM_FS_16000) && (pNewParams->SampleRate != LVM_FS_22050) && (pNewParams->SampleRate != LVM_FS_24000) &&
(pNewParams->SampleRate != LVM_FS_32000) && (pNewParams->SampleRate != LVM_FS_44100) && (pNewParams->SampleRate != LVM_FS_48000)) ||
((pNewParams->SourceFormat != LVM_STEREO) && (pNewParams->SourceFormat != LVM_MONOINSTEREO) && (pNewParams->SourceFormat != LVM_MONO)) )
{
return (LVREV_OUTOFRANGE);
}
if (pNewParams->Level > LVREV_MAX_LEVEL)
{
return LVREV_OUTOFRANGE;
}
if ((pNewParams->LPF < LVREV_MIN_LPF_CORNER) || (pNewParams->LPF > LVREV_MAX_LPF_CORNER))
{
return LVREV_OUTOFRANGE;
}
if ((pNewParams->HPF < LVREV_MIN_HPF_CORNER) || (pNewParams->HPF > LVREV_MAX_HPF_CORNER))
{
return LVREV_OUTOFRANGE;
}
if (pNewParams->T60 > LVREV_MAX_T60)
{
return LVREV_OUTOFRANGE;
}
if (pNewParams->Density > LVREV_MAX_DENSITY)
{
return LVREV_OUTOFRANGE;
}
if (pNewParams->Damping > LVREV_MAX_DAMPING)
{
return LVREV_OUTOFRANGE;
}
if (pNewParams->RoomSize > LVREV_MAX_ROOMSIZE)
{
return LVREV_OUTOFRANGE;
}
/*
* Copy the new parameters and set the flag to indicate they are available
*/
pLVREV_Private->NewParams = *pNewParams;
pLVREV_Private->bControlPending = LVM_TRUE;
return LVREV_SUCCESS;
}
/* End of file */
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV.h"
/****************************************************************************************/
/* */
/* Tables */
/* */
/****************************************************************************************/
/* Table with supported sampling rates. The table can be indexed using LVM_Fs_en */
const LVM_UINT16 LVM_FsTable[] = {
8000 ,
11025,
12000,
16000,
22050,
24000,
32000,
44100,
48000
};
/* Table with supported sampling rates. The table can be indexed using LVM_Fs_en */
LVM_UINT16 LVM_GetFsFromTable(LVM_Fs_en FsIndex){
if (FsIndex > LVM_FS_48000)
return 0;
return (LVM_FsTable[FsIndex]);
}
/* In order to maintain consistant input and out put signal strengths
output gain/attenuation is applied. This gain depends on T60 and Rooms
size parameters. These polynomial coefficients are calculated experimentally.
First value in the table is room size
second value is A0
third value is A1
fourth value is A2
fifth value is A3
sixth value is A4
shift value is to be added array (to use LVM_Polynomial function)
The gain is calculated using variable x=(T60*32767/7000)*32768;
first values is used to get polynomial set for given room size,
For room sizes which are not in the table, linear interpolation can be used.
*/
/* Normalizing output including Reverb Level part (only shift up)*/
const LVM_INT32 LVREV_GainPolyTable[24][5]={{1,17547434,128867434,-120988896,50761228,},
{2,18256869,172666902,-193169292,88345744,},
{3,16591311,139250151,-149667234,66770059,},
{4,17379977,170835131,-173579321,76278163,},
{5,18963512,210364934,-228623519,103435022,},
{6,17796318,135756417,-144084053,64327698,},
{7,17454695,174593214,-187513064,85146582,},
{8,17229257,140715570,-145790588,65361740,},
{9,17000547,163195946,-176733969,79562130,},
{10,16711699,142476304,-133339887,58366547,},
{13,18108419,149223697,-161762020,74397589,},
{15,16682043,124844884,-134284487,60082180,},
{17,16627346,120936430,-121766674,53146421,},
{20,17338325,125432694,-126616983,56534237,},
{25,16489146,99218217,-94597467,40616506,},
{30,15582373,84479043,-75365006,30952348,},
{40,16000669,84896611,-75031127,30696306,},
{50,15087054,71695031,-59349268,23279669,},
{60,15830714,68672971,-58211201,23671158,},
{70,15536061,66657972,-55901437,22560153,},
{75,15013145,48179917,-24138354,5232074,},
{80,15688738,50195036,-34206760,11515792,},
{90,16003322,48323661,-35607378,13153872,},
{100,15955223,48558201,-33706865,11715792,},
};
/* End of file */
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2004-2010 NXP Software
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LVREV_TABLES_H_
#define _LVREV_TABLES_H_
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************************************/
/* */
/* Includes */
/* */
/****************************************************************************************/
#include "LVREV_Private.h"
/****************************************************************************************/
/* */
/* Definitions */
/* */
/****************************************************************************************/
extern const LVM_UINT16 LVM_FsTable[];
extern LVM_UINT16 LVM_GetFsFromTable(LVM_Fs_en FsIndex);
extern LVM_INT32 LVREV_GainPolyTable[24][5];
#ifdef __cplusplus
}
#endif
#endif /** _LVREV_TABLES_H_ **/
/* End of file */