FFmpeg
Loading...
Searching...
No Matches
sbrdsp.c
Go to the documentation of this file.
1/*
2 * AAC Spectral Band Replication decoding functions
3 * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
4 * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com>
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#define USE_FIXED 0
24
25#include "aac.h"
27#include "libavutil/intfloat.h"
28#include "sbrdsp.h"
29
30static float sbr_sum_square_c(float (*x)[2], int n)
31{
32 float sum0 = 0.0f, sum1 = 0.0f;
33 int i;
34
35 for (i = 0; i < n; i += 2)
36 {
37 sum0 += x[i + 0][0] * x[i + 0][0];
38 sum1 += x[i + 0][1] * x[i + 0][1];
39 sum0 += x[i + 1][0] * x[i + 1][0];
40 sum1 += x[i + 1][1] * x[i + 1][1];
41 }
42
43 return sum0 + sum1;
44}
45
46static void sbr_neg_odd_64_c(float *x)
47{
48 union av_intfloat32 *xi = (union av_intfloat32*) x;
49 int i;
50 for (i = 1; i < 64; i += 4) {
51 xi[i + 0].i ^= 1U << 31;
52 xi[i + 2].i ^= 1U << 31;
53 }
54}
55
56static void sbr_qmf_pre_shuffle_c(float *z)
57{
58 union av_intfloat32 *zi = (union av_intfloat32*) z;
59 int k;
60 zi[64].i = zi[0].i;
61 zi[65].i = zi[1].i;
62 for (k = 1; k < 31; k += 2) {
63 zi[64 + 2 * k + 0].i = zi[64 - k].i ^ (1U << 31);
64 zi[64 + 2 * k + 1].i = zi[ k + 1].i;
65 zi[64 + 2 * k + 2].i = zi[63 - k].i ^ (1U << 31);
66 zi[64 + 2 * k + 3].i = zi[ k + 2].i;
67 }
68
69 zi[64 + 2 * 31 + 0].i = zi[64 - 31].i ^ (1U << 31);
70 zi[64 + 2 * 31 + 1].i = zi[31 + 1].i;
71}
72
73static void sbr_qmf_post_shuffle_c(float W[32][2], const float *z)
74{
75 const union av_intfloat32 *zi = (const union av_intfloat32*) z;
76 union av_intfloat32 *Wi = (union av_intfloat32*) W;
77 int k;
78 for (k = 0; k < 32; k += 2) {
79 Wi[2 * k + 0].i = zi[63 - k].i ^ (1U << 31);
80 Wi[2 * k + 1].i = zi[ k + 0].i;
81 Wi[2 * k + 2].i = zi[62 - k].i ^ (1U << 31);
82 Wi[2 * k + 3].i = zi[ k + 1].i;
83 }
84}
85
86static void sbr_qmf_deint_neg_c(float *v, const float *src)
87{
88 const union av_intfloat32 *si = (const union av_intfloat32*)src;
89 union av_intfloat32 *vi = (union av_intfloat32*)v;
90 int i;
91 for (i = 0; i < 32; i++) {
92 vi[ i].i = si[63 - 2 * i ].i;
93 vi[63 - i].i = si[63 - 2 * i - 1].i ^ (1U << 31);
94 }
95}
96
97#if 0
98 /* This code is slower because it multiplies memory accesses.
99 * It is left for educational purposes and because it may offer
100 * a better reference for writing arch-specific DSP functions. */
101static av_always_inline void autocorrelate(const float x[40][2],
102 float phi[3][2][2], int lag)
103{
104 int i;
105 float real_sum = 0.0f;
106 float imag_sum = 0.0f;
107 if (lag) {
108 for (i = 1; i < 38; i++) {
109 real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1];
110 imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0];
111 }
112 phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1];
113 phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0];
114 if (lag == 1) {
115 phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1];
116 phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0];
117 }
118 } else {
119 for (i = 1; i < 38; i++) {
120 real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1];
121 }
122 phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1];
123 phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1];
124 }
125}
126
127static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
128{
129 autocorrelate(x, phi, 0);
130 autocorrelate(x, phi, 1);
131 autocorrelate(x, phi, 2);
132}
133#else
134static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
135{
136 float real_sum2 = x[0][0] * x[2][0] + x[0][1] * x[2][1];
137 float imag_sum2 = x[0][0] * x[2][1] - x[0][1] * x[2][0];
138 float real_sum1 = 0.0f, imag_sum1 = 0.0f, real_sum0 = 0.0f;
139 int i;
140 for (i = 1; i < 38; i++) {
141 real_sum0 += x[i][0] * x[i ][0] + x[i][1] * x[i ][1];
142 real_sum1 += x[i][0] * x[i + 1][0] + x[i][1] * x[i + 1][1];
143 imag_sum1 += x[i][0] * x[i + 1][1] - x[i][1] * x[i + 1][0];
144 real_sum2 += x[i][0] * x[i + 2][0] + x[i][1] * x[i + 2][1];
145 imag_sum2 += x[i][0] * x[i + 2][1] - x[i][1] * x[i + 2][0];
146 }
147 phi[2 - 2][1][0] = real_sum2;
148 phi[2 - 2][1][1] = imag_sum2;
149 phi[2 ][1][0] = real_sum0 + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1];
150 phi[1 ][0][0] = real_sum0 + x[38][0] * x[38][0] + x[38][1] * x[38][1];
151 phi[2 - 1][1][0] = real_sum1 + x[ 0][0] * x[ 1][0] + x[ 0][1] * x[ 1][1];
152 phi[2 - 1][1][1] = imag_sum1 + x[ 0][0] * x[ 1][1] - x[ 0][1] * x[ 1][0];
153 phi[0 ][0][0] = real_sum1 + x[38][0] * x[39][0] + x[38][1] * x[39][1];
154 phi[0 ][0][1] = imag_sum1 + x[38][0] * x[39][1] - x[38][1] * x[39][0];
155}
156#endif
157
158static void sbr_hf_gen_c(float (*X_high)[2], const float (*X_low)[2],
159 const float alpha0[2], const float alpha1[2],
160 float bw, int start, int end)
161{
162 float alpha[4];
163 int i;
164
165 alpha[0] = alpha1[0] * bw * bw;
166 alpha[1] = alpha1[1] * bw * bw;
167 alpha[2] = alpha0[0] * bw;
168 alpha[3] = alpha0[1] * bw;
169
170 for (i = start; i < end; i++) {
171 X_high[i][0] =
172 X_low[i - 2][0] * alpha[0] -
173 X_low[i - 2][1] * alpha[1] +
174 X_low[i - 1][0] * alpha[2] -
175 X_low[i - 1][1] * alpha[3] +
176 X_low[i][0];
177 X_high[i][1] =
178 X_low[i - 2][1] * alpha[0] +
179 X_low[i - 2][0] * alpha[1] +
180 X_low[i - 1][1] * alpha[2] +
181 X_low[i - 1][0] * alpha[3] +
182 X_low[i][1];
183 }
184}
185
186static void sbr_hf_g_filt_c(float (*Y)[2], const float (*X_high)[40][2],
187 const float *g_filt, int m_max, intptr_t ixh)
188{
189 int m;
190
191 for (m = 0; m < m_max; m++) {
192 Y[m][0] = X_high[m][ixh][0] * g_filt[m];
193 Y[m][1] = X_high[m][ixh][1] * g_filt[m];
194 }
195}
196
197static av_always_inline void sbr_hf_apply_noise(float (*Y)[2],
198 const float *s_m,
199 const float *q_filt,
200 int noise,
201 float phi_sign0,
202 float phi_sign1,
203 int m_max)
204{
205 int m;
206
207 for (m = 0; m < m_max; m++) {
208 float y0 = Y[m][0];
209 float y1 = Y[m][1];
210 noise = (noise + 1) & 0x1ff;
211 if (s_m[m]) {
212 y0 += s_m[m] * phi_sign0;
213 y1 += s_m[m] * phi_sign1;
214 } else {
215 y0 += q_filt[m] * ff_sbr_noise_table[noise][0];
216 y1 += q_filt[m] * ff_sbr_noise_table[noise][1];
217 }
218 Y[m][0] = y0;
219 Y[m][1] = y1;
220 phi_sign1 = -phi_sign1;
221 }
222}
223
224#include "sbrdsp_template.c"
AAC definitions and structures.
#define Y
Definition boxblur.h:37
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define xi(width, name, var, range_min, range_max, subs,...)
Definition cbs_h264.c:115
static const int16_t alpha[]
Definition ilbcdata.h:55
#define W(a, i, v)
Definition jpegls.h:119
static av_always_inline void sbr_hf_apply_noise(float(*Y)[2], const float *s_m, const float *q_filt, int noise, float phi_sign0, float phi_sign1, int m_max)
Definition sbrdsp.c:197
static void sbr_qmf_pre_shuffle_c(float *z)
Definition sbrdsp.c:56
static float sbr_sum_square_c(float(*x)[2], int n)
Definition sbrdsp.c:30
static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
Definition sbrdsp.c:134
static void sbr_hf_g_filt_c(float(*Y)[2], const float(*X_high)[40][2], const float *g_filt, int m_max, intptr_t ixh)
Definition sbrdsp.c:186
static void sbr_qmf_deint_neg_c(float *v, const float *src)
Definition sbrdsp.c:86
static void sbr_hf_gen_c(float(*X_high)[2], const float(*X_low)[2], const float alpha0[2], const float alpha1[2], float bw, int start, int end)
Definition sbrdsp.c:158
static void sbr_neg_odd_64_c(float *x)
Definition sbrdsp.c:46
static void sbr_qmf_post_shuffle_c(float W[32][2], const float *z)
Definition sbrdsp.c:73
Macro definitions for various function/variable attributes.
#define av_always_inline
Definition attributes.h:72
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition noise.c:124
static av_always_inline void autocorrelate(const int x[40][2], SoftFloat phi[3][2][2], int lag)
#define src
Definition vp8dsp.c:248
uint32_t i
Definition intfloat.h:28