FFmpeg
synth_filter.c
Go to the documentation of this file.
1 /*
2  * copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (C) 2016 foo86
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "dcadct.h"
23 #include "dcamath.h"
24 #include "synth_filter.h"
25 
26 static void synth_filter_float(AVTXContext *imdct,
27  float *synth_buf_ptr, int *synth_buf_offset,
28  float synth_buf2[32], const float window[512],
29  float out[32], float in[32], float scale,
30  av_tx_fn imdct_fn)
31 {
32  float *synth_buf = synth_buf_ptr + *synth_buf_offset;
33  int i, j;
34 
35  imdct_fn(imdct, synth_buf, in, sizeof(float));
36 
37  for (i = 0; i < 16; i++) {
38  float a = synth_buf2[i ];
39  float b = synth_buf2[i + 16];
40  float c = 0;
41  float d = 0;
42  for (j = 0; j < 512 - *synth_buf_offset; j += 64) {
43  a += window[i + j ] * (-synth_buf[15 - i + j ]);
44  b += window[i + j + 16] * ( synth_buf[ i + j ]);
45  c += window[i + j + 32] * ( synth_buf[16 + i + j ]);
46  d += window[i + j + 48] * ( synth_buf[31 - i + j ]);
47  }
48  for ( ; j < 512; j += 64) {
49  a += window[i + j ] * (-synth_buf[15 - i + j - 512]);
50  b += window[i + j + 16] * ( synth_buf[ i + j - 512]);
51  c += window[i + j + 32] * ( synth_buf[16 + i + j - 512]);
52  d += window[i + j + 48] * ( synth_buf[31 - i + j - 512]);
53  }
54  out[i ] = a * scale;
55  out[i + 16] = b * scale;
56  synth_buf2[i ] = c;
57  synth_buf2[i + 16] = d;
58  }
59 
60  *synth_buf_offset = (*synth_buf_offset - 32) & 511;
61 }
62 
64  float *synth_buf_ptr, int *synth_buf_offset,
65  float synth_buf2[64], const float window[1024],
66  float out[64], float in[64], float scale,
67  av_tx_fn imdct_fn)
68 {
69  float *synth_buf = synth_buf_ptr + *synth_buf_offset;
70  int i, j;
71 
72  imdct_fn(imdct, synth_buf, in, sizeof(float));
73 
74  for (i = 0; i < 32; i++) {
75  float a = synth_buf2[i ];
76  float b = synth_buf2[i + 32];
77  float c = 0;
78  float d = 0;
79  for (j = 0; j < 1024 - *synth_buf_offset; j += 128) {
80  a += window[i + j ] * (-synth_buf[31 - i + j ]);
81  b += window[i + j + 32] * ( synth_buf[ i + j ]);
82  c += window[i + j + 64] * ( synth_buf[32 + i + j ]);
83  d += window[i + j + 96] * ( synth_buf[63 - i + j ]);
84  }
85  for ( ; j < 1024; j += 128) {
86  a += window[i + j ] * (-synth_buf[31 - i + j - 1024]);
87  b += window[i + j + 32] * ( synth_buf[ i + j - 1024]);
88  c += window[i + j + 64] * ( synth_buf[32 + i + j - 1024]);
89  d += window[i + j + 96] * ( synth_buf[63 - i + j - 1024]);
90  }
91  out[i ] = a * scale;
92  out[i + 32] = b * scale;
93  synth_buf2[i ] = c;
94  synth_buf2[i + 32] = d;
95  }
96 
97  *synth_buf_offset = (*synth_buf_offset - 64) & 1023;
98 }
99 
101  int32_t *synth_buf_ptr, int *synth_buf_offset,
102  int32_t synth_buf2[32], const int32_t window[512],
103  int32_t out[32], const int32_t in[32])
104 {
105  int32_t *synth_buf = synth_buf_ptr + *synth_buf_offset;
106  int i, j;
107 
108  imdct->imdct_half[0](synth_buf, in);
109 
110  for (i = 0; i < 16; i++) {
111  int64_t a = synth_buf2[i ] * (INT64_C(1) << 21);
112  int64_t b = synth_buf2[i + 16] * (INT64_C(1) << 21);
113  int64_t c = 0;
114  int64_t d = 0;
115  for (j = 0; j < 512 - *synth_buf_offset; j += 64) {
116  a += (int64_t)window[i + j ] * synth_buf[ i + j ];
117  b += (int64_t)window[i + j + 16] * synth_buf[15 - i + j ];
118  c += (int64_t)window[i + j + 32] * synth_buf[16 + i + j ];
119  d += (int64_t)window[i + j + 48] * synth_buf[31 - i + j ];
120  }
121  for ( ; j < 512; j += 64) {
122  a += (int64_t)window[i + j ] * synth_buf[ i + j - 512];
123  b += (int64_t)window[i + j + 16] * synth_buf[15 - i + j - 512];
124  c += (int64_t)window[i + j + 32] * synth_buf[16 + i + j - 512];
125  d += (int64_t)window[i + j + 48] * synth_buf[31 - i + j - 512];
126  }
127  out[i ] = clip23(norm21(a));
128  out[i + 16] = clip23(norm21(b));
129  synth_buf2[i ] = norm21(c);
130  synth_buf2[i + 16] = norm21(d);
131  }
132 
133  *synth_buf_offset = (*synth_buf_offset - 32) & 511;
134 }
135 
137  int32_t *synth_buf_ptr, int *synth_buf_offset,
138  int32_t synth_buf2[64], const int32_t window[1024],
139  int32_t out[64], const int32_t in[64])
140 {
141  int32_t *synth_buf = synth_buf_ptr + *synth_buf_offset;
142  int i, j;
143 
144  imdct->imdct_half[1](synth_buf, in);
145 
146  for (i = 0; i < 32; i++) {
147  int64_t a = synth_buf2[i ] * (INT64_C(1) << 20);
148  int64_t b = synth_buf2[i + 32] * (INT64_C(1) << 20);
149  int64_t c = 0;
150  int64_t d = 0;
151  for (j = 0; j < 1024 - *synth_buf_offset; j += 128) {
152  a += (int64_t)window[i + j ] * synth_buf[ i + j ];
153  b += (int64_t)window[i + j + 32] * synth_buf[31 - i + j ];
154  c += (int64_t)window[i + j + 64] * synth_buf[32 + i + j ];
155  d += (int64_t)window[i + j + 96] * synth_buf[63 - i + j ];
156  }
157  for ( ; j < 1024; j += 128) {
158  a += (int64_t)window[i + j ] * synth_buf[ i + j - 1024];
159  b += (int64_t)window[i + j + 32] * synth_buf[31 - i + j - 1024];
160  c += (int64_t)window[i + j + 64] * synth_buf[32 + i + j - 1024];
161  d += (int64_t)window[i + j + 96] * synth_buf[63 - i + j - 1024];
162  }
163  out[i ] = clip23(norm20(a));
164  out[i + 32] = clip23(norm20(b));
165  synth_buf2[i ] = norm20(c);
166  synth_buf2[i + 32] = norm20(d);
167  }
168 
169  *synth_buf_offset = (*synth_buf_offset - 64) & 1023;
170 }
171 
173 {
174  c->synth_filter_float = synth_filter_float;
175  c->synth_filter_float_64 = synth_filter_float_64;
176  c->synth_filter_fixed = synth_filter_fixed;
177  c->synth_filter_fixed_64 = synth_filter_fixed_64;
178 
179 #if ARCH_AARCH64
181 #elif ARCH_ARM
183 #elif ARCH_X86
185 #endif
186 }
dcamath.h
out
FILE * out
Definition: movenc.c:54
AVTXContext
Definition: tx_priv.h:235
synth_filter.h
dcadct.h
b
#define b
Definition: input.c:41
ff_synth_filter_init_aarch64
av_cold void ff_synth_filter_init_aarch64(SynthFilterContext *s)
Definition: synth_filter_init.c:34
synth_filter_fixed_64
static void synth_filter_fixed_64(DCADCTContext *imdct, int32_t *synth_buf_ptr, int *synth_buf_offset, int32_t synth_buf2[64], const int32_t window[1024], int32_t out[64], const int32_t in[64])
Definition: synth_filter.c:136
norm20
static int32_t norm20(int64_t a)
Definition: dcamath.h:42
ff_synth_filter_init
av_cold void ff_synth_filter_init(SynthFilterContext *c)
Definition: synth_filter.c:172
window
static SDL_Window * window
Definition: ffplay.c:364
SynthFilterContext
Definition: synth_filter.h:27
clip23
static int32_t clip23(int32_t a)
Definition: dcamath.h:54
av_cold
#define av_cold
Definition: attributes.h:90
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
DCADCTContext
Definition: dcadct.h:27
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:291
synth_filter_float
static void synth_filter_float(AVTXContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[32], const float window[512], float out[32], float in[32], float scale, av_tx_fn imdct_fn)
Definition: synth_filter.c:26
ff_synth_filter_init_arm
av_cold void ff_synth_filter_init_arm(SynthFilterContext *s)
Definition: synth_filter_init_arm.c:40
DCADCTContext::imdct_half
void(* imdct_half[2])(int32_t *output, const int32_t *input)
Definition: dcadct.h:28
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
synth_filter_float_64
static void synth_filter_float_64(AVTXContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[64], const float window[1024], float out[64], float in[64], float scale, av_tx_fn imdct_fn)
Definition: synth_filter.c:63
norm21
static int32_t norm21(int64_t a)
Definition: dcamath.h:43
synth_filter_fixed
static void synth_filter_fixed(DCADCTContext *imdct, int32_t *synth_buf_ptr, int *synth_buf_offset, int32_t synth_buf2[32], const int32_t window[512], int32_t out[32], const int32_t in[32])
Definition: synth_filter.c:100
d
d
Definition: ffmpeg_filter.c:425
int32_t
int32_t
Definition: audioconvert.c:56
ff_synth_filter_init_x86
void ff_synth_filter_init_x86(SynthFilterContext *c)
Definition: synth_filter_init.c:52