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);
147 int ph_nb = phase_count % 2 ? phase_count : phase_count / 2 + 1;
148 double x, y,
w, t,
s;
151 const int center= (tap_count-1)/2;
155 if (!tab || !sin_lut)
158 av_assert0(tap_count == 1 || tap_count % 2 == 0);
165 for (ph = 0; ph < ph_nb; ph++)
166 sin_lut[ph] = sin(
M_PI * ph / phase_count) * (center & 1 ? 1 : -1);
168 for(ph = 0; ph < ph_nb; ph++) {
170 for(i=0;i<tap_count;i++) {
171 x =
M_PI * ((double)(i - center) - (double)ph / phase_count) *
factor;
173 else if (factor == 1.0)
180 x =
fabs(((
double)(i - center) - (
double)ph / phase_count) * factor);
181 if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
182 else y= d*(-4 + 8*x - 5*x*x + x*x*x);
185 w = 2.0*x / (factor*tap_count);
187 y *= 0.3635819 - 0.4891775 * t + 0.1365995 * (2*t*t-1) - 0.0106411 * (4*t*t*t - 3*t);
190 w = 2.0*x / (factor*tap_count*
M_PI);
206 for(i=0;i<tap_count;i++)
208 if (phase_count % 2)
break;
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];
213 for(i=0;i<tap_count;i++)
215 if (phase_count % 2)
break;
216 for (i = 0; i < tap_count; i++)
220 for(i=0;i<tap_count;i++)
221 ((
float*)
filter)[ph * alloc + i] = tab[i] * scale / norm;
222 if (phase_count % 2)
break;
223 for (i = 0; i < tap_count; i++)
224 ((
float*)
filter)[(phase_count-ph) * alloc + tap_count-1-
i] = ((
float*)filter)[ph * alloc +
i];
227 for(i=0;i<tap_count;i++)
228 ((
double*)
filter)[ph * alloc + i] = tab[i] * scale / norm;
229 if (phase_count % 2)
break;
230 for (i = 0; i < tap_count; i++)
231 ((
double*)
filter)[(phase_count-ph) * alloc + tap_count-1-
i] = ((
double*)filter)[ph * alloc +
i];
239 double sine[
LEN + tap_count];
240 double filtered[
LEN];
241 double maxff=-2, minff=2, maxsf=-2, minsf=2;
242 for(i=0; i<
LEN; i++){
243 double ss=0, sf=0, ff=0;
244 for(j=0; j<LEN+tap_count; j++)
245 sine[j]= cos(i*j*
M_PI/LEN);
246 for(j=0; j<
LEN; j++){
249 for(k=0; k<tap_count; k++)
250 sum += filter[ph * tap_count + k] * sine[k+j];
251 filtered[j]= sum / (1<<FILTER_SHIFT);
252 ss+= sine[j + center] * sine[j + center];
253 ff+= filtered[j] * filtered[j];
254 sf+= sine[j + center] * filtered[j];
259 maxff=
FFMAX(maxff, ff);
260 minff=
FFMIN(minff, ff);
261 maxsf=
FFMAX(maxsf, sf);
262 minsf=
FFMIN(minsf, sf);
264 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);
289 double precision,
int cheby,
int exact_rational)
291 double cutoff = cutoff0? cutoff0 : 0.97;
292 double factor=
FFMIN(out_rate * cutoff / in_rate, 1.0);
293 int phase_count= 1<<phase_shift;
294 int phase_count_compensation = phase_count;
295 int filter_length =
FFMAX((
int)
ceil(filter_size/factor), 1);
297 if (filter_length > 1)
298 filter_length =
FFALIGN(filter_length, 2);
300 if (exact_rational) {
301 int phase_count_exact, phase_count_exact_den;
303 av_reduce(&phase_count_exact, &phase_count_exact_den, out_rate, in_rate, INT_MAX);
304 if (phase_count_exact <= phase_count) {
305 phase_count_compensation = phase_count_exact * (phase_count / phase_count_exact);
306 phase_count = phase_count_exact;
338 if (filter_size/factor > INT32_MAX/256) {
386 int new_src_incr, new_dst_incr;
396 if (!new_filter_bank)
434 if (compensation_distance && sample_delta) {
441 if (compensation_distance)
461 src_size =
FFMIN(src_size, max_src_size);
470 dst_size =
FFMAX(
FFMIN(dst_size, new_size), 0);
472 for (i = 0; i < dst->
ch_count; i++) {
478 *consumed = c->
index;
489 const void *
src,
int n,
int update_ctx);
491 dst_size =
FFMAX(
FFMIN(dst_size, delta_n), 0);
497 for (i = 0; i < dst->ch_count; i++)
498 *consumed = resample_func(c, dst->ch[i], src->ch[i], dst_size, i+1 == dst->ch_count);
556 for(j=0; j<reflection; j++){
567 int in_count,
int *out_idx,
int *out_sz)
578 for (n = *out_sz; n < num; n++) {
579 for (ch = 0; ch < src->
ch_count; ch++) {
594 for (ch = 0; ch < src->
ch_count; ch++) {
603 while (c->
index < 0) {
610 return FFMAX(res, 0);
static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed)
static int rebuild_filter_bank_with_compensation(ResampleContext *c)
int out_sample_rate
output sample rate
Audio buffer used for intermediate storage between conversion phases.
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.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
int in_buffer_index
cached buffer position
static float kaiser_beta(float att, float tr_bw)
#define FF_ARRAY_ELEMS(a)
AudioData in_buffer
cached audio data (convert and resample purpose)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
struct ResampleContext * resample
resampling context
static __device__ float ceil(float a)
static const uint8_t q1[256]
static void error(const char *err)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
#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.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static double bessel(double x)
0th order modified bessel function of the first kind.
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)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
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)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce 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
static __device__ float fabs(float a)
The libswresample context.
simple assert() macros that are a bit more flexible than ISO C assert().
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, int exact_rational)
#define ss(width, name, subs,...)
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(* resample_common)(struct ResampleContext *c, void *dst, const void *src, int n, int update_ctx)
int in_sample_rate
input sample rate
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 void resample_free(ResampleContext **cc)
AVSampleFormat
Audio sample formats.
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.
static int64_t get_out_samples(struct SwrContext *s, int in_samples)
int(* resample_linear)(struct ResampleContext *c, void *dst, const void *src, int n, int update_ctx)
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.
int phase_count_compensation
void(* resample_one)(struct ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
struct ResampleContext::@316 dsp
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)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
uint8_t * ch[SWR_CH_MAX]
samples buffer per channel