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 #ifndef __LVREV_PRIVATE_H__
19 #define __LVREV_PRIVATE_H__
20 
21 /****************************************************************************************/
22 /*                                                                                      */
23 /*  Includes                                                                            */
24 /*                                                                                      */
25 /****************************************************************************************/
26 #include "LVREV.h"
27 #include "LVREV_Tables.h"
28 #include "BIQUAD.h"
29 #include "Filter.h"
30 #include "VectorArithmetic.h"
31 #include "Mixer.h"
32 #include "LVM_Macros.h"
33 
34 /****************************************************************************************/
35 /*                                                                                      */
36 /*  Defines                                                                             */
37 /*                                                                                      */
38 /****************************************************************************************/
39 /* General */
40 #define ONE_OVER_SQRT_TWO            0.707107f           /* 1/sqrt(2) * 2^15 */
41 #define LVREV_B_8_on_1000               0.008f           /* 0.8 * 2^31 */
42 #define LVREV_HEADROOM                   0.25f           /* -12dB * 2^15 */
43 #define LVREV_2_9_INQ29                   2.9f           /* 2.9 in Q29 format */
44 #define LVREV_MIN3DB                0.7079457f           /* -3dB in Q15 format */
45 
46 /* Intenal constants */
47 #define LVREV_LP_Poly_Order                 4
48 #define LVREV_LP_Poly_Shift                 5
49 
50 #define LVREV_T60_SCALE                0.000142f           /*(1/7000) */
51 
52 #define LVREV_T_3_Power_0_on_4              1.0f
53 #define LVREV_T_3_Power_1_on_4         1.316074f
54 #define LVREV_T_3_Power_2_on_4         1.732051f
55 #define LVREV_T_3_Power_3_on_4         2.279507f
56 #define LVREV_T_3_Power_minus0_on_4         1.0f        /* 3^(-0/4) * 2^15 */
57 #define LVREV_T_3_Power_minus1_on_4    0.759836f        /* 3^(-1/4) * 2^15 */
58 #define LVREV_T_3_Power_minus2_on_4    0.577350f        /* 3^(-2/4) * 2^15 */
59 #define LVREV_T_3_Power_minus3_on_4    0.438691f        /* 3^(-3/4) * 2^15 */
60 
61     /* ((192000 * 120 * LVREV_T_3_Power_minus3_on_4) >> 15) / 1000 */
62 #define LVREV_MAX_T3_DELAY               10108
63     /* ((192000 * 120 * LVREV_T_3_Power_minus2_on_4) >> 15) / 1000 */
64 #define LVREV_MAX_T2_DELAY               13304
65     /* ((192000 * 120 * LVREV_T_3_Power_minus1_on_4) >> 15) / 1000 */
66 #define LVREV_MAX_T1_DELAY               17508
67     /* ((192000 * 120 * LVREV_T_3_Power_minus0_on_4) >> 15) / 1000 */
68 #define LVREV_MAX_T0_DELAY               23040
69     /* ((192000 * 120 * LVREV_T_3_Power_minus3_on_4) >> 15) / 1500 */
70 #define LVREV_MAX_AP3_DELAY               6740
71     /* ((192000 * 120 * LVREV_T_3_Power_minus2_on_4) >> 15) / 1500 */
72 #define LVREV_MAX_AP2_DELAY               8872
73     /* ((192000 * 120 * LVREV_T_3_Power_minus1_on_4) >> 15) / 1500 */
74 #define LVREV_MAX_AP1_DELAY              11672
75     /* ((192000 * 120 * LVREV_T_3_Power_minus0_on_4) >> 15) / 1500 */
76 #define LVREV_MAX_AP0_DELAY              15360
77 
78 #define LVREV_BYPASSMIXER_TC             1000           /* Bypass mixer time constant*/
79 #define LVREV_ALLPASS_TC                 1000           /* All-pass filter time constant */
80 #define LVREV_ALLPASS_TAP_TC             10000           /* All-pass filter dely tap change */
81 #define LVREV_FEEDBACKMIXER_TC            100           /* Feedback mixer time constant*/
82 #define LVREV_OUTPUTGAIN_SHIFT              5           /* Bits shift for output gain correction */
83 
84 /* Parameter limits */
85 #define LVREV_NUM_FS                       13           /* Number of supported sample rates */
86 
87 #define LVREV_MAXBLKSIZE_LIMIT             64           /* Maximum block size low limit */
88 #define LVREV_MAX_LEVEL                   100           /* Maximum level, 100% */
89 #define LVREV_MIN_LPF_CORNER               50           /* Low pass filter limits */
90 #define LVREV_MAX_LPF_CORNER            23999
91 #define LVREV_MIN_HPF_CORNER               20           /* High pass filrer limits */
92 #define LVREV_MAX_HPF_CORNER             1000
93 #define LVREV_MAX_T60                    7000           /* Maximum T60 time in ms */
94 #define LVREV_MAX_DENSITY                 100           /* Maximum density, 100% */
95 #define LVREV_MAX_DAMPING                 100           /* Maximum damping, 100% */
96 #define LVREV_MAX_ROOMSIZE                100           /* Maximum room size, 100% */
97 
98 /****************************************************************************************/
99 /*                                                                                      */
100 /*  Structures                                                                          */
101 /*                                                                                      */
102 /****************************************************************************************/
103 
104 /* Fast data structure */
105 typedef struct
106 {
107     Biquad_1I_Order1_FLOAT_Taps_t HPTaps;                     /* High pass filter taps */
108     Biquad_1I_Order1_FLOAT_Taps_t LPTaps;                     /* Low pass filter taps */
109     Biquad_1I_Order1_FLOAT_Taps_t RevLPTaps[4];               /* Reverb low pass filters taps */
110 
111 } LVREV_FastData_st;
112 
113 /* Fast coefficient structure */
114 typedef struct
115 {
116 
117     Biquad_FLOAT_Instance_t       HPCoefs;              /* High pass filter coefficients */
118     Biquad_FLOAT_Instance_t       LPCoefs;              /* Low pass filter coefficients */
119     Biquad_FLOAT_Instance_t       RevLPCoefs[4];        /* Reverb low pass filters coefficients */
120 
121 } LVREV_FastCoef_st;
122 typedef struct
123 {
124     /* General */
125     LVREV_InstanceParams_st InstanceParams;           /* Initialisation time instance parameters */
126     LVREV_MemoryTable_st    MemoryTable;              /* Memory table */
127     LVREV_ControlParams_st  CurrentParams;            /* Parameters being used */
128     LVREV_ControlParams_st  NewParams;                /* New parameters from the \
129                                                          calling application */
130     LVM_CHAR                bControlPending;          /* Flag to indicate new parameters \
131                                                          are available */
132     LVM_CHAR                bFirstControl;            /* Flag to indicate that the control \
133                                                          function is called for the first time */
134     LVM_CHAR                bDisableReverb;           /* Flag to indicate that the mix level is
135                                                          0% and the reverb can be disabled */
136     LVM_INT32               RoomSizeInms;             /* Room size in msec */
137     LVM_INT32               MaxBlkLen;                /* Maximum block size for internal
138                                                          processing */
139 
140     /* Aligned memory pointers */
141     LVREV_FastData_st       *pFastData;               /* Fast data memory base address */
142     LVREV_FastCoef_st       *pFastCoef;               /* Fast coefficient memory base address */
143     LVM_FLOAT               *pScratchDelayLine[4];    /* Delay line scratch memory */
144     LVM_FLOAT               *pScratch;                /* Multi ussge scratch */
145     LVM_FLOAT               *pInputSave;              /* Reverb block input save for dry/wet
146                                                          mixing*/
147 
148     /* Feedback matrix */
149     Mix_1St_Cll_FLOAT_t     FeedbackMixer[4];         /* Mixer for Pop and Click Supression \
150                                                          caused by feedback Gain */
151 
152     /* All-Pass Filter */
153     LVM_INT32               T[4];                     /* Maximum delay size of buffer */
154     LVM_FLOAT               *pDelay_T[4];             /* Pointer to delay buffers */
155     LVM_INT32               Delay_AP[4];              /* Offset to AP delay buffer start */
156     LVM_INT16               AB_Selection;             /* Smooth from tap A to B when 1 \
157                                                          otherwise B to A */
158     LVM_INT32               A_DelaySize[4];           /* A delay length in samples */
159     LVM_INT32               B_DelaySize[4];           /* B delay length in samples */
160     LVM_FLOAT               *pOffsetA[4];             /* Offset for the A delay tap */
161     LVM_FLOAT               *pOffsetB[4];             /* Offset for the B delay tap */
162     Mix_2St_Cll_FLOAT_t     Mixer_APTaps[4];          /* Smoothed AP delay mixer */
163     Mix_1St_Cll_FLOAT_t     Mixer_SGFeedback[4];      /* Smoothed SAfeedback gain */
164     Mix_1St_Cll_FLOAT_t     Mixer_SGFeedforward[4];   /* Smoothed AP feedforward gain */
165 
166     /* Output gain */
167     Mix_2St_Cll_FLOAT_t     BypassMixer;              /* Dry/wet mixer */
168     LVM_FLOAT               Gain;                     /* Gain applied to output to maintain
169                                                          average signal power */
170     Mix_1St_Cll_FLOAT_t     GainMixer;                /* Gain smoothing */
171 
172 } LVREV_Instance_st;
173 
174 /****************************************************************************************/
175 /*                                                                                      */
176 /*  Function prototypes                                                                 */
177 /*                                                                                      */
178 /****************************************************************************************/
179 
180 LVREV_ReturnStatus_en   LVREV_ApplyNewSettings(LVREV_Instance_st     *pPrivate);
181 void                    ReverbBlock(LVM_FLOAT           *pInput,
182                                     LVM_FLOAT           *pOutput,
183                                     LVREV_Instance_st   *pPrivate,
184                                     LVM_UINT16          NumSamples);
185 LVM_INT32               BypassMixer_Callback(void       *pCallbackData,
186                                              void       *pGeneralPurpose,
187                                              LVM_INT16  GeneralPurpose );
188 
189 #endif  /** __LVREV_PRIVATE_H__ **/
190 
191 /* End of file */
192