• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /*------------------------------------------------------------------------------
17  *
18  *  This file includes the coefficient tables or the two convolution function
19  *  It also includes the definition of Qmf_storage and the prototype of all
20  *  necessary functions required to implement the QMF filtering.
21  *
22  *----------------------------------------------------------------------------*/
23 
24 #ifndef QMF_H
25 #define QMF_H
26 
27 #include "AptxParameters.h"
28 
29 typedef struct {
30   int16_t QmfL_buf[32];
31   int16_t QmfH_buf[32];
32   int32_t QmfLH_buf[32];
33   int32_t QmfHL_buf[32];
34   int32_t QmfLL_buf[32];
35   int32_t QmfHH_buf[32];
36   int32_t QmfI_pt;
37   int32_t QmfO_pt;
38 } Qmf_storage;
39 
40 /* Outer QMF filter for Enhanced aptX is a symmetrical 32-tap filter (16
41  * different coefficients). The table in defined in QmfConv.c */
42 #ifndef _STDQMFOUTERCOEFF
43 static const int32_t Qmf_outerCoeffs[12] = {
44         /* (C(1/30)C(3/28)), C(5/26), C(7/24) */
45         0xFE6302DA,
46         0xFFFFDA75,
47         0x0000AA6A,
48         /*  C(9/22), C(11/20), C(13/18), C(15/16) */
49         0xFFFE273E,
50         0x00041E95,
51         0xFFF710B5,
52         0x002AC12E,
53         /*  C(17/14), C(19/12), (C(21/10)C(23/8)) */
54         0x000AA328,
55         0xFFFD8D1F,
56         0x211E6BDB,
57         /* (C(25/6)C(27/4)), (C(29/2)C(31/0)) */
58         0x0DB7D8C5,
59         0xFC7F02B0,
60 };
61 #else
62 static const int32_t Qmf_outerCoeffs[16] = {
63         730,    -413,    -9611, 43626, -121026, 269973, -585547, 2801966,
64         697128, -160481, 27611, 8478,  -10043,  3511,   688,     -897,
65 };
66 #endif
67 
68 /* Each inner QMF filter for Enhanced aptX is a symmetrical 32-tap filter (16
69  * different coefficients) */
70 static const int32_t Qmf_innerCoeffs[16] = {
71         1033,   -584,    -13592, 61697, -171156, 381799, -828088, 3962579,
72         985888, -226954, 39048,  11990, -14203,  4966,   973,     -1268,
73 };
74 
75 void AsmQmfConvI(const int32_t* p1dl_buffPtr, const int32_t* p2dl_buffPtr, const int32_t* coeffPtr,
76                  int32_t* filterOutputs);
77 void AsmQmfConvO(const int16_t* p1dl_buffPtr, const int16_t* p2dl_buffPtr, const int32_t* coeffPtr,
78                  int32_t* convSumDiff);
79 
QmfAnalysisFilter(const int32_t pcm[4],Qmf_storage * Qmf_St,const int32_t predVals[4],int32_t * aqmfOutputs)80 XBT_INLINE_ void QmfAnalysisFilter(const int32_t pcm[4], Qmf_storage* Qmf_St,
81                                    const int32_t predVals[4], int32_t* aqmfOutputs) {
82   int32_t convSumDiff[4];
83   int32_t filterOutputs[4];
84 
85   int32_t lc_QmfO_pt = (Qmf_St->QmfO_pt);
86   int32_t lc_QmfI_pt = (Qmf_St->QmfI_pt);
87 
88   /* Symbolic constants to represent the first and second set out outer filter
89    * outputs. */
90   enum { FirstOuterOutputs = 0, SecondOuterOutputs = 1 };
91 
92   /* Load outer filter phase1 and phase2 delay lines with the first 2 PCM
93    * samples. Convolve the filter and get the 2 convolution results. */
94   Qmf_St->QmfL_buf[lc_QmfO_pt + 16] = (int16_t)pcm[FirstPcm];
95   Qmf_St->QmfL_buf[lc_QmfO_pt] = (int16_t)pcm[FirstPcm];
96   Qmf_St->QmfH_buf[lc_QmfO_pt + 16] = (int16_t)pcm[SecondPcm];
97   Qmf_St->QmfH_buf[lc_QmfO_pt++] = (int16_t)pcm[SecondPcm];
98   lc_QmfO_pt &= 0xF;
99 
100   AsmQmfConvO(&Qmf_St->QmfL_buf[lc_QmfO_pt + 15], &Qmf_St->QmfH_buf[lc_QmfO_pt], Qmf_outerCoeffs,
101               &convSumDiff[0]);
102 
103   /* Load outer filter phase1 and phase2 delay lines with the second 2 PCM
104    * samples. Convolve the filter and get the 2 convolution results. */
105   Qmf_St->QmfL_buf[lc_QmfO_pt + 16] = (int16_t)pcm[ThirdPcm];
106   Qmf_St->QmfL_buf[lc_QmfO_pt] = (int16_t)pcm[ThirdPcm];
107   Qmf_St->QmfH_buf[lc_QmfO_pt + 16] = (int16_t)pcm[FourthPcm];
108   Qmf_St->QmfH_buf[lc_QmfO_pt++] = (int16_t)pcm[FourthPcm];
109   lc_QmfO_pt &= 0xF;
110 
111   AsmQmfConvO(&Qmf_St->QmfL_buf[lc_QmfO_pt + 15], &Qmf_St->QmfH_buf[lc_QmfO_pt], Qmf_outerCoeffs,
112               &convSumDiff[1]);
113 
114   /* Load the first inner filter phase1 and phase2 delay lines with the 2
115    * convolution sum (low-pass) outer filter outputs. Convolve the filter and
116    * get the 2 convolution results. The first 2 analysis filter outputs are
117    * the sum and difference values for the first inner filter convolutions. */
118   Qmf_St->QmfLL_buf[lc_QmfI_pt + 16] = convSumDiff[0];
119   Qmf_St->QmfLL_buf[lc_QmfI_pt] = convSumDiff[0];
120   Qmf_St->QmfLH_buf[lc_QmfI_pt + 16] = convSumDiff[1];
121   Qmf_St->QmfLH_buf[lc_QmfI_pt] = convSumDiff[1];
122 
123   AsmQmfConvI(&Qmf_St->QmfLL_buf[lc_QmfI_pt + 16], &Qmf_St->QmfLH_buf[lc_QmfI_pt + 1],
124               &Qmf_innerCoeffs[0], &filterOutputs[LL]);
125 
126   /* Load the second inner filter phase1 and phase2 delay lines with the 2
127    * convolution difference (high-pass) outer filter outputs. Convolve the
128    * filter and get the 2 convolution results. The second 2 analysis filter
129    * outputs are the sum and difference values for the second inner filter
130    * convolutions. */
131   Qmf_St->QmfHL_buf[lc_QmfI_pt + 16] = convSumDiff[2];
132   Qmf_St->QmfHL_buf[lc_QmfI_pt] = convSumDiff[2];
133   Qmf_St->QmfHH_buf[lc_QmfI_pt + 16] = convSumDiff[3];
134   Qmf_St->QmfHH_buf[lc_QmfI_pt++] = convSumDiff[3];
135   lc_QmfI_pt &= 0xF;
136 
137   AsmQmfConvI(&Qmf_St->QmfHL_buf[lc_QmfI_pt + 15], &Qmf_St->QmfHH_buf[lc_QmfI_pt],
138               &Qmf_innerCoeffs[0], &filterOutputs[HL]);
139 
140   /* Subtracted the previous predicted value from the filter output on a
141    * per-subband basis. Ensure these values are saturated, if necessary.
142    * Manual unrolling */
143   aqmfOutputs[LL] = filterOutputs[LL] - predVals[LL];
144   aqmfOutputs[LL] = ssat24(aqmfOutputs[LL]);
145 
146   aqmfOutputs[LH] = filterOutputs[LH] - predVals[LH];
147   aqmfOutputs[LH] = ssat24(aqmfOutputs[LH]);
148 
149   aqmfOutputs[HL] = filterOutputs[HL] - predVals[HL];
150   aqmfOutputs[HL] = ssat24(aqmfOutputs[HL]);
151 
152   aqmfOutputs[HH] = filterOutputs[HH] - predVals[HH];
153   aqmfOutputs[HH] = ssat24(aqmfOutputs[HH]);
154 
155   (Qmf_St->QmfO_pt) = lc_QmfO_pt;
156   (Qmf_St->QmfI_pt) = lc_QmfI_pt;
157 }
158 
159 #endif  // QMF_H
160