33 double sum = coeff[size-1];
35 for (i = size-2; i >= 0; --i) {
76 static const double p1[] = {
77 -2.2335582639474375249e+15,
78 -5.5050369673018427753e+14,
79 -3.2940087627407749166e+13,
80 -8.4925101247114157499e+11,
81 -1.1912746104985237192e+10,
82 -1.0313066708737980747e+08,
83 -5.9545626019847898221e+05,
84 -2.4125195876041896775e+03,
85 -7.0935347449210549190e+00,
86 -1.5453977791786851041e-02,
87 -2.5172644670688975051e-05,
88 -3.0517226450451067446e-08,
89 -2.6843448573468483278e-11,
90 -1.5982226675653184646e-14,
91 -5.2487866627945699800e-18,
93 static const double q1[] = {
94 -2.2335582639474375245e+15,
95 7.8858692566751002988e+12,
96 -1.2207067397808979846e+10,
97 1.0377081058062166144e+07,
98 -4.8527560179962773045e+03,
101 static const double p2[] = {
102 -2.2210262233306573296e-04,
103 1.3067392038106924055e-02,
104 -4.4700805721174453923e-01,
105 5.5674518371240761397e+00,
106 -2.3517945679239481621e+01,
107 3.1611322818701131207e+01,
108 -9.6090021968656180000e+00,
110 static const double q2[] = {
111 -5.5194330231005480228e-04,
112 3.2547697594819615062e-02,
113 -1.1151759188741312645e+00,
114 1.3982595353892851542e+01,
115 -6.0228002066743340583e+01,
116 8.5539563258012929600e+01,
117 -3.1446690275135491500e+01,
129 y = 1 / x - 1.0 / 15;
131 factor =
exp(x) / sqrt(x);
145 int filter_type,
double kaiser_beta){
147 double x, y, w, t,
s;
149 double *sin_lut =
av_malloc_array(phase_count / 2 + 1,
sizeof(*sin_lut));
150 const int center= (tap_count-1)/2;
152 if (!tab || !sin_lut)
159 av_assert0(phase_count == 1 || phase_count % 2 == 0);
162 for (ph = 0; ph <= phase_count / 2; ph++)
163 sin_lut[ph] = sin(
M_PI * ph / phase_count);
165 for(ph = 0; ph <= phase_count / 2; ph++) {
168 for(i=0;i<=tap_count;i++) {
169 x =
M_PI * ((double)(i - center) - (double)ph / phase_count) *
factor;
171 else if (factor == 1.0)
178 x = fabs(((
double)(i - center) - (
double)ph / phase_count) * factor);
179 if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
180 else y= d*(-4 + 8*x - 5*x*x + x*x*x);
183 w = 2.0*x / (factor*tap_count);
185 y *= 0.3635819 - 0.4891775 * t + 0.1365995 * (2*t*t-1) - 0.0106411 * (4*t*t*t - 3*t);
188 w = 2.0*x / (factor*tap_count*
M_PI);
204 for(i=0;i<tap_count;i++)
205 ((int16_t*)filter)[ph * alloc + i] = av_clip_int16(
lrintf(tab[i] * scale / norm));
206 if (tap_count % 2 == 0) {
207 for (i = 0; i < tap_count; i++)
208 ((int16_t*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((int16_t*)
filter)[ph * alloc + i];
211 for (i = 1; i <= tap_count; i++)
212 ((int16_t*)
filter)[(phase_count-ph) * alloc + tap_count-i] =
213 av_clip_int16(
lrintf(tab[i] * scale / (norm - tab[0] + tab[tap_count])));
217 for(i=0;i<tap_count;i++)
218 ((
int32_t*)filter)[ph * alloc + i] = av_clipl_int32(
llrint(tab[i] * scale / norm));
219 if (tap_count % 2 == 0) {
220 for (i = 0; i < tap_count; i++)
221 ((
int32_t*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((
int32_t*)
filter)[ph * alloc + i];
224 for (i = 1; i <= tap_count; i++)
226 av_clipl_int32(
llrint(tab[i] * scale / (norm - tab[0] + tab[tap_count])));
230 for(i=0;i<tap_count;i++)
231 ((
float*)filter)[ph * alloc + i] = tab[i] * scale / norm;
232 if (tap_count % 2 == 0) {
233 for (i = 0; i < tap_count; i++)
234 ((
float*)filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((
float*)
filter)[ph * alloc + i];
237 for (i = 1; i <= tap_count; i++)
238 ((
float*)
filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / (norm - tab[0] + tab[tap_count]);
242 for(i=0;i<tap_count;i++)
243 ((
double*)
filter)[ph * alloc + i] = tab[i] * scale / norm;
244 if (tap_count % 2 == 0) {
245 for (i = 0; i < tap_count; i++)
246 ((
double*)
filter)[(phase_count-ph) * alloc + tap_count-1-i] = ((
double*)filter)[ph * alloc + i];
249 for (i = 1; i <= tap_count; i++)
250 ((
double*)
filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / (norm - tab[0] + tab[tap_count]);
259 double sine[
LEN + tap_count];
260 double filtered[
LEN];
261 double maxff=-2, minff=2, maxsf=-2, minsf=2;
262 for(i=0; i<
LEN; i++){
263 double ss=0, sf=0, ff=0;
264 for(j=0; j<LEN+tap_count; j++)
265 sine[j]= cos(i*j*
M_PI/LEN);
266 for(j=0; j<
LEN; j++){
269 for(k=0; k<tap_count; k++)
270 sum += filter[ph * tap_count + k] * sine[k+j];
272 ss+= sine[j + center] * sine[j + center];
273 ff+= filtered[j] * filtered[j];
274 sf+= sine[j + center] * filtered[j];
279 maxff=
FFMAX(maxff, ff);
280 minff=
FFMIN(minff, ff);
281 maxsf=
FFMAX(maxsf, sf);
282 minsf=
FFMIN(minsf, sf);
284 av_log(
NULL,
AV_LOG_ERROR,
"i:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", i, ss, maxff, minff, maxsf, minsf);
300 double precision,
int cheby)
302 double cutoff = cutoff0? cutoff0 : 0.97;
303 double factor=
FFMIN(out_rate * cutoff / in_rate, 1.0);
333 if (filter_size/factor > INT32_MAX/256) {
387 if (compensation_distance)
400 int src_size,
int dst_size,
int update_ctx)
409 dst_size=
FFMIN(dst_size, new_size);
425 dst_size =
FFMIN(dst_size, delta_n);
427 *consumed = c->
dsp.
resample(c, dst, src, dst_size, update_ctx);
445 src_size =
FFMIN(src_size, max_src_size);
449 consumed, src_size, dst_size, i+1==dst->
ch_count);
513 int in_count,
int *out_idx,
int *out_sz)
524 for (n = *out_sz; n < num; n++) {
525 for (ch = 0; ch < src->
ch_count; ch++) {
540 for (ch = 0; ch < src->
ch_count; ch++) {
553 return FFMAX(res, 0);
static ResampleContext * resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby)
static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed)
int out_sample_rate
output sample rate
Audio buffer used for intermediate storage between conversion phases.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
int ch_count
number of channels
SwrFilterType
Resampling Filter Types.
#define AV_CPU_FLAG_MMX2
SSE integer functions or AMD MMX ext.
int in_buffer_index
cached buffer position
AudioData in_buffer
cached audio data (convert and resample purpose)
struct ResampleContext * resample
resampling context
static const uint8_t q1[256]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum AVSampleFormat format
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static int swri_resample(ResampleContext *c, uint8_t *dst, const uint8_t *src, int *consumed, int src_size, int dst_size, int update_ctx)
static void resample_free(ResampleContext **c)
static double bessel(double x)
0th order modified bessel function of the first kind.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
int swri_realloc_audio(AudioData *a, int count)
int compensation_distance
static int set_compensation(ResampleContext *c, int sample_delta, int compensation_distance)
enum AVResampleFilterType filter_type
struct Resampler const swri_resampler
static int invert_initial_buffer(ResampleContext *c, AudioData *dst, const AudioData *src, int in_count, int *out_idx, int *out_sz)
static double eval_poly(const double *coeff, int size, double x)
int in_buffer_count
cached buffer length
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Blackman Nuttall windowed sinc.
static int resample_flush(struct SwrContext *s)
The libswresample context.
simple assert() macros that are a bit more flexible than ISO C assert().
int compensation_distance
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int64_t get_delay(struct SwrContext *s, int64_t base)
int in_sample_rate
input sample rate
#define FF_ARRAY_ELEMS(a)
struct ResampleContext::@202 dsp
AVSampleFormat
Audio sample formats.
static const char * format
void swri_resample_dsp_init(ResampleContext *c)
static const int factor[16]
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
int(* resample)(struct ResampleContext *c, void *dst, const void *src, int n, int update_ctx)
static int64_t get_out_samples(struct SwrContext *s, int in_samples)
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
void(* resample_one)(struct ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static int build_filter(ResampleContext *c, void *filter, double factor, int tap_count, int alloc, int phase_count, int scale, int filter_type, double kaiser_beta)
builds a polyphase filterbank.
static const double coeff[2][5]
static const struct twinvq_data tab
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
int planar
1 if planar audio, 0 otherwise
#define av_malloc_array(a, b)
uint8_t * ch[SWR_CH_MAX]
samples buffer per channel
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...