History

swresample/resample: do not allow odd filter_length

except filter_length == 1 odd filter_length gives worse frequency response, even when compared with shorter filter_length also makes build_filter simpler

Muhammad Faiz committed 9 years ago

Commit 53a5cea1 parent 3016e912 files · +56 −76Browse files

Showing the changes to libswresample (1 of 2 files). Show all

Unified · Split

libswresample/resample.c+18−38
@@ -155,6 +155,8 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap · 154 unmodified lines
155155 if (!tab || !sin_lut)
156156 goto fail;
157157
158+ av_assert0(tap_count == 1 || tap_count % 2 == 0);
159+
158160 /* if upsampling, only need to interpolate, no filter */
159161 if (factor > 1.0)
160162 factor = 1.0;
@@ -165,7 +167,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap · 4 unmodified lines
165167 }
166168 for(ph = 0; ph < ph_nb; ph++) {
167169 s = sin_lut[ph];
168− for(i=0;i<=tap_count;i++) {
170+ for(i=0;i<tap_count;i++) {
169171 x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
170172 if (x == 0) y = 1.0;
171173 else if (factor == 1.0)
@@ -194,7 +196,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap · 22 unmodified lines
194196
195197 tab[i] = y;
196198 s = -s;
197− if (!ph && i < tap_count)
199+ if (!ph)
198200 norm += y;
199201 }
200202
@@ -204,55 +206,29 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap · 3 unmodified lines
204206 for(i=0;i<tap_count;i++)
205207 ((int16_t*)filter)[ph * alloc + i] = av_clip_int16(lrintf(tab[i] * scale / norm));
206208 if (phase_count % 2) break;
207− if (tap_count % 2 == 0 || tap_count == 1) {
208− for (i = 0; i < tap_count; i++)
209− ((int16_t*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((int16_t*)filter)[ph * alloc + i];
210− }
211− else {
212− for (i = 1; i <= tap_count; i++)
213− ((int16_t*)filter)[(phase_count-ph) * alloc + tap_count-i] =
214− av_clip_int16(lrintf(tab[i] * scale / norm));
215− }
209+ for (i = 0; i < tap_count; i++)
210+ ((int16_t*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((int16_t*)filter)[ph * alloc + i];
216211 break;
217212 case AV_SAMPLE_FMT_S32P:
218213 for(i=0;i<tap_count;i++)
219214 ((int32_t*)filter)[ph * alloc + i] = av_clipl_int32(llrint(tab[i] * scale / norm));
220215 if (phase_count % 2) break;
221− if (tap_count % 2 == 0 || tap_count == 1) {
222− for (i = 0; i < tap_count; i++)
223− ((int32_t*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((int32_t*)filter)[ph * alloc + i];
224− }
225− else {
226− for (i = 1; i <= tap_count; i++)
227− ((int32_t*)filter)[(phase_count-ph) * alloc + tap_count-i] =
228− av_clipl_int32(llrint(tab[i] * scale / norm));
229− }
216+ for (i = 0; i < tap_count; i++)
217+ ((int32_t*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((int32_t*)filter)[ph * alloc + i];
230218 break;
231219 case AV_SAMPLE_FMT_FLTP:
232220 for(i=0;i<tap_count;i++)
233221 ((float*)filter)[ph * alloc + i] = tab[i] * scale / norm;
234222 if (phase_count % 2) break;
235− if (tap_count % 2 == 0 || tap_count == 1) {
236− for (i = 0; i < tap_count; i++)
237− ((float*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((float*)filter)[ph * alloc + i];
238− }
239− else {
240− for (i = 1; i <= tap_count; i++)
241− ((float*)filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / norm;
242− }
223+ for (i = 0; i < tap_count; i++)
224+ ((float*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((float*)filter)[ph * alloc + i];
243225 break;
244226 case AV_SAMPLE_FMT_DBLP:
245227 for(i=0;i<tap_count;i++)
246228 ((double*)filter)[ph * alloc + i] = tab[i] * scale / norm;
247229 if (phase_count % 2) break;
248− if (tap_count % 2 == 0 || tap_count == 1) {
249− for (i = 0; i < tap_count; i++)
250− ((double*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((double*)filter)[ph * alloc + i];
251− }
252− else {
253− for (i = 1; i <= tap_count; i++)
254− ((double*)filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / norm;
255− }
230+ for (i = 0; i < tap_count; i++)
231+ ((double*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((double*)filter)[ph * alloc + i];
256232 break;
257233 }
258234 }
@@ -308,6 +284,10 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r · 49 unmodified lines
308284 double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
309285 int phase_count= 1<<phase_shift;
310286 int phase_count_compensation = phase_count;
287+ int filter_length = FFMAX((int)ceil(filter_size/factor), 1);
288+
289+ if (filter_length > 1)
290+ filter_length = FFALIGN(filter_length, 2);
311291
312292 if (exact_rational) {
313293 int phase_count_exact, phase_count_exact_den;
@@ -320,7 +300,7 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r · 6 unmodified lines
320300 }
321301
322302 if (!c || c->phase_count != phase_count || c->linear!=linear || c->factor != factor
323− || c->filter_length != FFMAX((int)ceil(filter_size/factor), 1) || c->format != format
303+ || c->filter_length != filter_length || c->format != format
324304 || c->filter_type != filter_type || c->kaiser_beta != kaiser_beta) {
325305 c = av_mallocz(sizeof(*c));
326306 if (!c)
@@ -354,7 +334,7 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r · 27 unmodified lines
354334 c->phase_count = phase_count;
355335 c->linear = linear;
356336 c->factor = factor;
357− c->filter_length = FFMAX((int)ceil(filter_size/factor), 1);
337+ c->filter_length = filter_length;
358338 c->filter_alloc = FFALIGN(c->filter_length, 8);
359339 c->filter_bank = av_calloc(c->filter_alloc, (phase_count+1)*c->felem_size);
360340 c->filter_type = filter_type;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t