Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters: Add Power of Blackman and Power of Garamond windows #220

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'],
7,
# API version
{
'342': 'add pl_filter_function_garamond',
'341': 're-add pl_filter_function_{bicubic,bcspline,catmull_rom,mitchell,robidoux,robidouxsharp} as deprecated',
'340': 'add pl_queue_params.drift_compensation, PL_QUEUE_DEFAULTS and pl_queue_pts_offset',
'339': 'add pl_peak_detect_params.black_cutoff',
Expand Down
28 changes: 24 additions & 4 deletions src/filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,22 @@ const struct pl_filter_function pl_filter_function_kaiser = {
.tunable = {true},
};

//Power of Blackman window
static double blackman(const struct pl_filter_ctx *f, double x)
{
double a = f->params[0];
double a0 = (1 - a) / 2.0, a1 = 1 / 2.0, a2 = a / 2.0;
double n = f->params[1];
double a0 = (1.0 - a) / 2.0, a1 = 1.0 / 2.0, a2 = a / 2.0;
x *= M_PI;
return a0 + a1 * cos(x) + a2 * cos(2 * x);
return pow(a0 + a1 * cos(x) + a2 * cos(2.0 * x), n);
}

const struct pl_filter_function pl_filter_function_blackman = {
.name = "blackman",
.weight = blackman,
.radius = 1.0,
.params = {0.16},
.tunable = {true},
.params = {0.16, 1.0},
.tunable = {true, true},
};

static double bohman(const struct pl_filter_ctx *f, double x)
Expand Down Expand Up @@ -399,6 +401,22 @@ const struct pl_filter_function pl_filter_function_gaussian = {
.tunable = {true},
};

//Power of Garamond window
static double garamond(const struct pl_filter_ctx *f, double x)
{
double n = f->params[0];
double m = f->params[1];
return pow(1.0 - pow(x, n), m);
}

const struct pl_filter_function pl_filter_function_garamond = {
.name = "garamond",
.weight = garamond,
.radius = 1.0,
.params = {2.0, 1.0},
.tunable = {true, true},
};

static double quadratic(const struct pl_filter_ctx *f, double x)
{
if (x < 0.5) {
Expand Down Expand Up @@ -623,6 +641,7 @@ const struct pl_filter_function * const pl_filter_functions[] = {
&pl_filter_function_blackman,
&pl_filter_function_bohman,
&pl_filter_function_gaussian,
&pl_filter_function_garamond,
&pl_filter_function_quadratic,
&filter_function_quadric, // alias
&pl_filter_function_sinc,
Expand Down Expand Up @@ -999,6 +1018,7 @@ const struct pl_filter_function_preset pl_filter_function_presets[] = {
{"blackman", &pl_filter_function_blackman},
{"bohman", &pl_filter_function_bohman},
{"gaussian", &pl_filter_function_gaussian},
{"garamond", &pl_filter_function_garamond},
{"quadratic", &pl_filter_function_quadratic},
{"quadric", &filter_function_quadric}, // alias
{"sinc", &pl_filter_function_sinc},
Expand Down
17 changes: 16 additions & 1 deletion src/include/libplacebo/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ PL_API extern const struct pl_filter_function pl_filter_function_welch;
// and the side lobes.
PL_API extern const struct pl_filter_function pl_filter_function_kaiser;

// Blackman filter: Cosine filter named after Ralph Beebe Blackman.
// Power of Blackman filter: Based on cosine filter named after Ralph Beebe Blackman.
// Parameter [0]: Scale (alpha). Influences the shape. The defaults result in
// zeros at the third and fourth sidelobes.
// Parameter [1]: Scale (n). Influences the shape. Controls main lobe width. Default 1.0.
// alpha = 0.0, n = 1.0: Hann filter.
// alpha = 0.0, n = 0.5: Cosine filter.
// n = 1.0: Blackman filter.
// n = 0.0: Box filter.
PL_API extern const struct pl_filter_function pl_filter_function_blackman;

// Bohman filter: 2nd order Cosine filter.
Expand All @@ -107,6 +112,16 @@ PL_API extern const struct pl_filter_function pl_filter_function_bohman;
// Parameter [0]: Scale (t), increasing makes the result blurrier.
PL_API extern const struct pl_filter_function pl_filter_function_gaussian;

// Power of Garamond function: Based on power filter named after Claude Garamond.
// Parameter [0]: Scale(n). Influences the shape. Default 2.0.
// Parameter [1]: Scale(m). Influences the shape. Default 1.0.
// n = 1.0, m = 1.0: Linear filter.
// n = 2.0, m = 1.0: Welch filter.
// n -> +inf, m <= 1.0: Box filter.
// m = 0.0: Box filter.
// m = 1.0: Garamond filter.
PL_API extern const struct pl_filter_function pl_filter_function_garamond;

// Quadratic function: 2nd order approximation of the gaussian function. Also
// sometimes called a "quadric" window.
PL_API extern const struct pl_filter_function pl_filter_function_quadratic;
Expand Down