Go to the documentation of this file.
53 const float *coeffs =
s->coeffs;
60 nb_samples =
FFMIN(
s->nb_samples,
s->n -
s->pts);
61 if (nb_samples <= 0) {
69 memcpy(
frame->data[0], coeffs +
s->pts, nb_samples *
sizeof(
float));
97 static float *
make_lpf(
int num_taps,
float Fc,
float beta,
float rho,
98 float scale,
int dc_norm)
100 int i, m = num_taps - 1;
101 float *
h =
av_calloc(num_taps,
sizeof(*
h)), sum = 0;
109 for (
i = 0;
i <= m / 2;
i++) {
110 float z =
i - .5f * m, x = z *
M_PI, y = z * mult1;
111 h[
i] = x ?
sinf(Fc * x) / x : Fc;
119 for (
i = 0; dc_norm &&
i < num_taps;
i++)
128 static const float coefs[][4] = {
129 {-6.784957e-10, 1.02856e-05, 0.1087556, -0.8988365 + .001},
130 {-6.897885e-10, 1.027433e-05, 0.10876, -0.8994658 + .002},
131 {-1.000683e-09, 1.030092e-05, 0.1087677, -0.9007898 + .003},
132 {-3.654474e-10, 1.040631e-05, 0.1087085, -0.8977766 + .006},
133 {8.106988e-09, 6.983091e-06, 0.1091387, -0.9172048 + .015},
134 {9.519571e-09, 7.272678e-06, 0.1090068, -0.9140768 + .025},
135 {-5.626821e-09, 1.342186e-05, 0.1083999, -0.9065452 + .05},
136 {-9.965946e-08, 5.073548e-05, 0.1040967, -0.7672778 + .085},
137 {1.604808e-07, -5.856462e-05, 0.1185998, -1.34824 + .1},
138 {-1.511964e-07, 6.363034e-05, 0.1064627, -0.9876665 + .18},
140 float realm = logf(tr_bw / .0005
f) / logf(2.
f);
143 float b0 = ((c0[0] * att + c0[1]) * att + c0[2]) * att + c0[3];
144 float b1 = ((
c1[0] * att +
c1[1]) * att +
c1[2]) * att +
c1[3];
146 return b0 + (
b1 -
b0) * (realm - (
int)realm);
149 return .1102f * (att - 8.7f);
151 return .58417f *
powf(att - 20.96
f, .4
f) + .07886f * (att - 20.96f);
155 static void kaiser_params(
float att,
float Fc,
float tr_bw,
float *beta,
int *num_taps)
157 *beta = *beta < 0.f ?
kaiser_beta(att, tr_bw * .5
f / Fc): *beta;
158 att = att < 60.f ? (att - 7.95f) / (2.285
f *
M_PI * 2.
f) :
159 ((.0007528358f-1.577737e-05 * *beta) * *beta + 0.6248022
f) * *beta + .06186902f;
160 *num_taps = !*num_taps ?
ceilf(att/tr_bw + 1) : *num_taps;
163 static float *
lpf(
float Fn,
float Fc,
float tbw,
int *num_taps,
float att,
float *beta,
int round)
167 if ((Fc /= Fn) <= 0.
f || Fc >= 1.
f) {
172 att = att ? att : 120.f;
178 *num_taps =
av_clip(n, 11, 32767);
180 *num_taps = 1 + 2 * (int)((
int)((*num_taps / 2) * Fc + .5
f) / Fc + .5f);
183 return make_lpf(*num_taps |= 1, Fc, *beta, 0.
f, 1.
f, 0);
188 for (
int i = 0;
i < n;
i++)
194 #define SQR(a) ((a) * (a))
206 float *pi_wraps, *
work, phase1 = (phase > 50.f ? 100.f - phase : phase) / 50.
f;
207 int i, work_len, begin, end, imp_peak = 0, peak = 0,
ret;
208 float imp_sum = 0, peak_imp_sum = 0,
scale = 1.f;
209 float prev_angle2 = 0, cum_2pi = 0, prev_angle1 = 0, cum_1pi = 0;
211 for (
i = *
len, work_len = 2 * 2 * 8;
i > 1; work_len <<= 1, i >>= 1);
214 work =
av_calloc((work_len + 2) + (work_len / 2 + 1),
sizeof(
float));
217 pi_wraps = &
work[work_len + 2];
232 for (
i = 0;
i <= work_len;
i += 2) {
234 float detect = 2 *
M_PI;
235 float delta = angle - prev_angle2;
242 delta = angle - prev_angle1;
246 pi_wraps[
i >> 1] = cum_1pi;
254 for (
i = 0;
i < work_len;
i++)
255 work[
i] *= 2.
f / work_len;
257 for (
i = 1;
i < work_len / 2;
i++) {
259 work[
i + work_len / 2] = 0;
263 for (
i = 2;
i < work_len;
i += 2)
264 work[
i + 1] = phase1 *
i / work_len * pi_wraps[work_len >> 1] + (1 - phase1) * (
work[
i + 1] + pi_wraps[
i >> 1]) - pi_wraps[
i >> 1];
268 for (
i = 2;
i < work_len;
i += 2) {
276 for (
i = 0;
i < work_len;
i++)
277 work[
i] *= 2.
f / work_len;
280 for (
i = 0;
i <= (int) (pi_wraps[work_len >> 1] /
M_PI + .5
f);
i++) {
282 if (
fabs(imp_sum) >
fabs(peak_imp_sum)) {
283 peak_imp_sum = imp_sum;
296 }
else if (phase1 == 1) {
297 begin = peak - *
len / 2;
299 begin = (.997f - (2 - phase1) * .22
f) * *
len + .5f;
300 end = (.997f + (0 - phase1) * .22
f) * *
len + .5f;
301 begin = peak - (begin & ~3);
302 end = peak + 1 + ((end + 3) & ~3);
311 for (
i = 0;
i < *
len;
i++) {
312 (*h)[
i] =
work[(begin + (phase > 50.f ? *
len - 1 -
i :
i) + work_len) & (work_len - 1)];
314 *post_len = phase > 50 ? peak - begin : begin + *
len - (peak + 1);
317 work_len, pi_wraps[work_len >> 1] /
M_PI, peak, peak_imp_sum, imp_peak,
318 work[imp_peak], *
len, *post_len, 100.
f - 100.
f * *post_len / (*
len - 1));
330 float Fn =
s->sample_rate * .5f;
332 int i, n, post_peak, longer;
337 if (
s->Fc0 >= Fn ||
s->Fc1 >= Fn) {
339 "filter frequency must be less than %d/2.\n",
s->sample_rate);
343 h[0] =
lpf(Fn,
s->Fc0,
s->tbw0, &
s->num_taps[0],
s->att, &
s->beta,
s->round);
344 h[1] =
lpf(Fn,
s->Fc1,
s->tbw1, &
s->num_taps[1],
s->att, &
s->beta,
s->round);
349 longer =
s->num_taps[1] >
s->num_taps[0];
350 n =
s->num_taps[longer];
353 for (
i = 0;
i <
s->num_taps[!longer];
i++)
354 h[longer][
i + (n -
s->num_taps[!longer]) / 2] +=
h[!longer][
i];
362 if (
s->phase != 50.f) {
376 for (
i = 0;
i < n;
i++)
377 s->coeffs[
i] =
h[longer][
i];
403 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
404 #define OFFSET(x) offsetof(SincContext, x)
409 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
AF },
410 {
"n",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
AF },
417 {
"hptaps",
"set number of taps for high-pass filter",
OFFSET(num_taps[0]),
AV_OPT_TYPE_INT, {.i64=0}, 0, 32768,
AF },
418 {
"lptaps",
"set number of taps for low-pass filter",
OFFSET(num_taps[1]),
AV_OPT_TYPE_INT, {.i64=0}, 0, 32768,
AF },
426 .description =
NULL_IF_CONFIG_SMALL(
"Generate a sinc kaiser-windowed low-pass, high-pass, band-pass, or band-reject FIR coefficients."),
428 .priv_class = &sinc_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
#define AVERROR_EOF
End of file.
double av_bessel_i0(double x)
0th order modified bessel function of the first kind.
static const int sample_rates[]
This structure describes decoded (raw) audio or video data.
static float kaiser_beta(float att, float tr_bw)
const char * name
Filter name.
A link between two filters.
static __device__ float ceilf(float a)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
static float * lpf(float Fn, float Fc, float tbw, int *num_taps, float att, float *beta, int round)
static double b1(void *priv, double x, double y)
static float * make_lpf(int num_taps, float Fc, float beta, float rho, float scale, int dc_norm)
static __device__ float fabsf(float a)
A filter pad used for either input or output.
static int16_t mult(Float11 *f1, Float11 *f2)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
static int adjust(int x, int size)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FILTER_OUTPUTS(array)
const AVFilter ff_asrc_sinc
#define av_realloc_f(p, o, n)
static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, float phase)
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
static const AVFilterPad sinc_outputs[]
@ AV_TX_INPLACE
Allows for in-place transformations, where input == output.
must be printed separately If there s no standard function for printing the type you the WRITE_1D_FUNC_ARGV macro is a very quick way to create one See libavcodec dv_tablegen c for an example The h file This file should the initialization functions should not do and instead of the variable declarations the generated *_tables h file should be included Since that will be generated in the build the path must be i e not Makefile changes To make the automatic table creation work
static int activate(AVFilterContext *ctx)
static __device__ float sqrtf(float a)
static av_cold void uninit(AVFilterContext *ctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
static void kaiser_params(float att, float Fc, float tr_bw, float *beta, int *num_taps)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
AVFilterContext * src
source filter
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
int sample_rate
samples per second
#define i(width, name, range_min, range_max)
static av_always_inline av_const double round(double x)
static void invert(float *h, int n)
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static int config_output(AVFilterLink *outlink)
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
@ AV_OPT_TYPE_INT
Underlying C type is int.
static const AVOption sinc_options[]
#define AV_CHANNEL_LAYOUT_MONO
static void scale(int *out, const int *in, const int w, const int h, const int shift)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static float safe_log(float x)
static double b0(void *priv, double x, double y)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AVFILTER_DEFINE_CLASS(sinc)