| 182 | } |
| 183 | |
| 184 | static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, |
| 185 | double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, |
| 186 | double precision, int cheby, int exact_rational) |
| 187 | { |
| 188 | double cutoff = cutoff0? cutoff0 : 0.97; |
| 189 | double factor= FFMIN(out_rate * cutoff / in_rate, 1.0); |
| 190 | int phase_count= 1<<phase_shift; |
| 191 | int phase_count_compensation = phase_count; |
| 192 | int filter_length = FFMAX((int)ceil(filter_size/factor), 1); |
| 193 | |
| 194 | if (filter_length > 1) |
| 195 | filter_length = FFALIGN(filter_length, 2); |
| 196 | |
| 197 | if (exact_rational) { |
| 198 | int phase_count_exact, phase_count_exact_den; |
| 199 | |
| 200 | av_reduce(&phase_count_exact, &phase_count_exact_den, out_rate, in_rate, INT_MAX); |
| 201 | if (phase_count_exact <= phase_count) { |
| 202 | phase_count_compensation = phase_count_exact * (phase_count / phase_count_exact); |
| 203 | phase_count = phase_count_exact; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if (!c || c->phase_count != phase_count || c->linear!=linear || c->factor != factor |
| 208 | || c->filter_length != filter_length || c->format != format |
| 209 | || c->filter_type != filter_type || c->kaiser_beta != kaiser_beta) { |
| 210 | resample_free(&c); |
| 211 | c = av_mallocz(sizeof(*c)); |
| 212 | if (!c) |
| 213 | return NULL; |
| 214 | |
| 215 | c->format= format; |
| 216 | |
| 217 | c->felem_size= av_get_bytes_per_sample(c->format); |
| 218 | |
| 219 | switch(c->format){ |
| 220 | case AV_SAMPLE_FMT_S16P: |
| 221 | c->filter_shift = 15; |
| 222 | break; |
| 223 | case AV_SAMPLE_FMT_S32P: |
| 224 | c->filter_shift = 30; |
| 225 | break; |
| 226 | case AV_SAMPLE_FMT_FLTP: |
| 227 | case AV_SAMPLE_FMT_DBLP: |
| 228 | c->filter_shift = 0; |
| 229 | break; |
| 230 | default: |
| 231 | av_log(NULL, AV_LOG_ERROR, "Unsupported sample format\n"); |
| 232 | av_assert0(0); |
| 233 | } |
| 234 | |
| 235 | if (filter_size/factor > INT32_MAX/256) { |
| 236 | av_log(NULL, AV_LOG_ERROR, "Filter length too large\n"); |
| 237 | goto error; |
| 238 | } |
| 239 | |
| 240 | c->phase_count = phase_count; |
| 241 | c->linear = linear; |
nothing calls this directly
no test coverage detected