libavresample/resample_template.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #if defined(CONFIG_RESAMPLE_DBL)
22 #define SET_TYPE(func) func ## _dbl
23 #define FELEM double
24 #define FELEM2 double
25 #define FELEML double
26 #define OUT(d, v) d = v
27 #define DBL_TO_FELEM(d, v) d = v
28 #elif defined(CONFIG_RESAMPLE_FLT)
29 #define SET_TYPE(func) func ## _flt
30 #define FELEM float
31 #define FELEM2 float
32 #define FELEML float
33 #define OUT(d, v) d = v
34 #define DBL_TO_FELEM(d, v) d = v
35 #elif defined(CONFIG_RESAMPLE_S32)
36 #define SET_TYPE(func) func ## _s32
37 #define FELEM int32_t
38 #define FELEM2 int64_t
39 #define FELEML int64_t
40 #define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30)
41 #define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30)));
42 #else
43 #define SET_TYPE(func) func ## _s16
44 #define FELEM int16_t
45 #define FELEM2 int32_t
46 #define FELEML int64_t
47 #define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15)
48 #define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15)))
49 #endif
50 
51 static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter,
52  void *dst0, int dst_index, const void *src0,
53  int src_size, int index, int frac)
54 {
55  FELEM *dst = dst0;
56  const FELEM *src = src0;
57 
58  if (no_filter) {
59  dst[dst_index] = src[index];
60  } else {
61  int i;
62  int sample_index = index >> c->phase_shift;
63  FELEM2 val = 0;
64  FELEM *filter = ((FELEM *)c->filter_bank) +
65  c->filter_length * (index & c->phase_mask);
66 
67  if (sample_index < 0) {
68  for (i = 0; i < c->filter_length; i++)
69  val += src[FFABS(sample_index + i) % src_size] *
70  (FELEM2)filter[i];
71  } else if (c->linear) {
72  FELEM2 v2 = 0;
73  for (i = 0; i < c->filter_length; i++) {
74  val += src[abs(sample_index + i)] * (FELEM2)filter[i];
75  v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
76  }
77  val += (v2 - val) * (FELEML)frac / c->src_incr;
78  } else {
79  for (i = 0; i < c->filter_length; i++)
80  val += src[sample_index + i] * (FELEM2)filter[i];
81  }
82 
83  OUT(dst[dst_index], val);
84  }
85 }
86 
87 static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,
88  int tap_count)
89 {
90  int i;
91  FELEM *filter = ((FELEM *)filter0) + phase * tap_count;
92  for (i = 0; i < tap_count; i++) {
93  DBL_TO_FELEM(filter[i], tab[i]);
94  }
95 }
96 
97 #undef SET_TYPE
98 #undef FELEM
99 #undef FELEM2
100 #undef FELEML
101 #undef OUT
102 #undef DBL_TO_FELEM
#define OUT(d, v)
#define DBL_TO_FELEM(d, v)
static void SET_TYPE() set_filter(void *filter0, double *tab, int phase, int tap_count)
static void SET_TYPE() resample_one(ResampleContext *c, int no_filter, void *dst0, int dst_index, const void *src0, int src_size, int index, int frac)
the mask is usually to keep the same permissions Filters should remove permissions on reference they give to output whenever necessary It can be automatically done by setting the rej_perms field on the output pad Here are a few guidelines corresponding to common 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
#define FFABS(a)
Definition: common.h:53
AVS_Value src
Definition: avisynth_c.h:523
#define SET_TYPE(func)
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
static double c[64]
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
static const struct twinvq_data tab