1 /*
2 * Audio Processing Technology codec for Bluetooth (aptX)
3 *
4 * Copyright (C) 2017 Aurelien Jacobs <aurel@gnuage.org>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef AVCODEC_APTX_H
24 #define AVCODEC_APTX_H
25
29
30
35 };
36
38 LF,
// Low Frequency (0-5.5 kHz)
39 MLF,
// Medium-Low Frequency (5.5-11kHz)
40 MHF,
// Medium-High Frequency (11-16.5kHz)
41 HF,
// High Frequency (16.5-22kHz)
43 };
44
46 #define FILTER_TAPS 16
47
52
57
63
69
80
85
91
98
99 typedef const struct {
108
110
111 /* Rounded right shift with optional clipping */
112 #define RSHIFT_SIZE(size) \
113 av_always_inline \
114 static int##size##_t rshift##size(int##size##_t value, int shift) \
115 { \
116 int##size##_t rounding = (int##size##_t)1 << (shift - 1); \
117 int##size##_t mask = ((int##size##_t)1 << (shift + 1)) - 1; \
118 return ((value + rounding) >> shift) - ((value & mask) == rounding); \
119 } \
120 av_always_inline \
121 static int##size##_t rshift##size##_clip24(int##size##_t value, int shift) \
122 { \
123 return av_clip_intp2(rshift##size(value, shift), 23); \
124 }
127
128 /*
129 * Convolution filter coefficients for the outer QMF of the QMF tree.
130 * The 2 sets are a mirror of each other.
131 */
133 {
134 730, -413, -9611, 43626, -121026, 269973, -585547, 2801966,
135 697128, -160481, 27611, 8478, -10043, 3511, 688, -897,
136 },
137 {
138 -897, 688, 3511, -10043, 8478, 27611, -160481, 697128,
139 2801966, -585547, 269973, -121026, 43626, -9611, -413, 730,
140 },
141 };
142
143 /*
144 * Convolution filter coefficients for the inner QMF of the QMF tree.
145 * The 2 sets are a mirror of each other.
146 */
148 {
149 1033, -584, -13592, 61697, -171156, 381799, -828088, 3962579,
150 985888, -226954, 39048, 11990, -14203, 4966, 973, -1268,
151 },
152 {
153 -1268, 973, 4966, -14203, 11990, 39048, -226954, 985888,
154 3962579, -828088, 381799, -171156, 61697, -13592, -584, 1033,
155 },
156 };
157
158 /*
159 * Push one sample into a circular signal buffer.
160 */
163 {
167 }
168
169 /*
170 * Compute the convolution of the signal with the coefficients, and reduce
171 * to 24 bits by applying the specified right shifting.
172 */
177 {
181
184
185 return rshift64_clip24(e,
shift);
186 }
187
189 {
191 int subband;
192
193 for (subband = 0; subband <
NB_SUBBANDS; subband++)
195
197 }
198
199 /* For each sample, ensure that the parity of all subbands of all channels
200 * is 0 except once every 8 samples where the parity is forced to 1. */
202 {
205
206 int eighth = *idx == 7;
207 *idx = (*idx + 1) & 7;
208
210 }
211
214
216
217 #endif /* AVCODEC_APTX_H */