MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / build_filter

Function build_filter

libavcodec/resample2.c:98–179  ·  view source on GitHub ↗

* builds a polyphase filterbank. * @param factor resampling factor * @param scale wanted sum of coefficients for each filter * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16 */

Source from the content-addressed store, hash-verified

96 * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16
97 */
98static void build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){
99 int ph, i;
100 double x, y, w, tab[tap_count];
101 const int center= (tap_count-1)/2;
102
103 /* if upsampling, only need to interpolate, no filter */
104 if (factor > 1.0)
105 factor = 1.0;
106
107 for(ph=0;ph<phase_count;ph++) {
108 double norm = 0;
109 for(i=0;i<tap_count;i++) {
110 x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
111 if (x == 0) y = 1.0;
112 else y = sin(x) / x;
113 switch(type){
114 case 0:{
115 const float d= -0.5; //first order derivative = -0.5
116 x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
117 if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
118 else y= d*(-4 + 8*x - 5*x*x + x*x*x);
119 break;}
120 case 1:
121 w = 2.0*x / (factor*tap_count) + M_PI;
122 y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);
123 break;
124 default:
125 w = 2.0*x / (factor*tap_count*M_PI);
126 y *= bessel(type*sqrt(FFMAX(1-w*w, 0)));
127 break;
128 }
129
130 tab[i] = y;
131 norm += y;
132 }
133
134 /* normalize so that an uniform color remains the same */
135 for(i=0;i<tap_count;i++) {
136#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
137 filter[ph * tap_count + i] = tab[i] / norm;
138#else
139 filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), FELEM_MIN, FELEM_MAX);
140#endif
141 }
142 }
143#if 0
144 {
145#define LEN 1024
146 int j,k;
147 double sine[LEN + tap_count];
148 double filtered[LEN];
149 double maxff=-2, minff=2, maxsf=-2, minsf=2;
150 for(i=0; i<LEN; i++){
151 double ss=0, sf=0, ff=0;
152 for(j=0; j<LEN+tap_count; j++)
153 sine[j]= cos(i*j*M_PI/LEN);
154 for(j=0; j<LEN; j++){
155 double sum=0;

Callers 1

av_resample_initFunction · 0.85

Calls 4

besselFunction · 0.85
av_clipFunction · 0.85
lrintfFunction · 0.85
av_logFunction · 0.85

Tested by

no test coverage detected