28 #if defined(TEMPLATE_RESAMPLE_DBL) 30 # define RENAME(N) N ## _double 31 # define FILTER_SHIFT 0 34 # define FELEM2 double 36 # define OUT(d, v) d = v 38 #elif defined(TEMPLATE_RESAMPLE_FLT) 40 # define RENAME(N) N ## _float 41 # define FILTER_SHIFT 0 46 # define OUT(d, v) d = v 48 #elif defined(TEMPLATE_RESAMPLE_S32) 50 # define RENAME(N) N ## _int32 51 # define FILTER_SHIFT 30 52 # define DELEM int32_t 53 # define FELEM int32_t 54 # define FELEM2 int64_t 55 # define FELEM_MAX INT32_MAX 56 # define FELEM_MIN INT32_MIN 57 # define FOFFSET (1<<(FILTER_SHIFT-1)) 58 # define OUT(d, v) (d) = av_clipl_int32((v)>>FILTER_SHIFT) 60 #elif defined(TEMPLATE_RESAMPLE_S16) 62 # define RENAME(N) N ## _int16 63 # define FILTER_SHIFT 15 64 # define DELEM int16_t 65 # define FELEM int16_t 66 # define FELEM2 int32_t 67 # define FELEML int64_t 68 # define FELEM_MAX INT16_MAX 69 # define FELEM_MIN INT16_MIN 70 # define FOFFSET (1<<(FILTER_SHIFT-1)) 71 # define OUT(d, v) (d) = av_clip_int16((v)>>FILTER_SHIFT) 76 int dst_size, int64_t index2, int64_t incr)
82 for (dst_index = 0; dst_index < dst_size; dst_index++) {
83 dst[dst_index] = src[index2 >> 32];
89 void *dest,
const void *
source,
90 int n,
int update_ctx)
99 while (index >=
c->phase_count) {
101 index -=
c->phase_count;
104 for (dst_index = 0; dst_index < n; dst_index++) {
110 for (i = 0; i + 1 <
c->filter_length; i+=2) {
111 val += src[sample_index +
i ] * (
FELEM2)filter[i ];
112 val2 += src[sample_index + i + 1] * (
FELEM2)filter[i + 1];
115 val += src[sample_index +
i ] * (
FELEM2)filter[i ];
119 OUT(dst[dst_index], val + val2);
122 frac +=
c->dst_incr_mod;
123 index +=
c->dst_incr_div;
124 if (frac >=
c->src_incr) {
129 while (index >=
c->phase_count) {
131 index -=
c->phase_count;
144 void *dest,
const void *
source,
145 int n,
int update_ctx)
152 int sample_index = 0;
153 #if FILTER_SHIFT == 0 154 double inv_src_incr = 1.0 /
c->src_incr;
157 while (index >=
c->phase_count) {
159 index -=
c->phase_count;
162 for (dst_index = 0; dst_index < n; dst_index++) {
167 for (i = 0; i <
c->filter_length; i++) {
168 val += src[sample_index +
i] * (
FELEM2)filter[i];
169 v2 += src[sample_index +
i] * (
FELEM2)filter[i +
c->filter_alloc];
172 val += (v2 -
val) * (
FELEML) frac /
c->src_incr;
174 # if FILTER_SHIFT == 0 175 val += (v2 -
val) * inv_src_incr * frac;
177 val += (v2 -
val) /
c->src_incr * frac;
180 OUT(dst[dst_index], val);
182 frac +=
c->dst_incr_mod;
183 index +=
c->dst_incr_div;
184 if (frac >=
c->src_incr) {
189 while (index >=
c->phase_count) {
191 index -=
c->phase_count;
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
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
static void SET_TYPE() resample_linear(ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
int(* resample_common)(struct ResampleContext *c, void *dst, const void *src, int n, int update_ctx)
static void SET_TYPE() resample_one(ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
static double val(void *priv, double ch)