spa: make cutoff configurable in spa-resample

This commit is contained in:
Wim Taymans 2025-11-24 16:49:25 +01:00
parent ed2889cecf
commit fc26e6321b
2 changed files with 18 additions and 13 deletions

View file

@ -567,8 +567,8 @@ int resample_native_init(struct resample *r)
return -ENOTSUP; return -ENOTSUP;
} }
spa_log_info(r->log, "native %p: q:%d w:%d in:%d out:%d gcd:%d n_taps:%d n_phases:%d features:%08x:%08x", spa_log_info(r->log, "native %p: c:%f q:%d w:%d in:%d out:%d gcd:%d n_taps:%d n_phases:%d features:%08x:%08x",
r, r->quality, c->window, r->i_rate, r->o_rate, gcd, n_taps, n_phases, r, c->cutoff, r->quality, c->window, r->i_rate, r->o_rate, gcd, n_taps, n_phases,
r->cpu_flags, d->info->cpu_flags); r->cpu_flags, d->info->cpu_flags);
r->cpu_flags = d->info->cpu_flags; r->cpu_flags = d->info->cpu_flags;

View file

@ -45,18 +45,19 @@ struct data {
#define STR_FMTS "(s8|s16|s32|f32|f64)" #define STR_FMTS "(s8|s16|s32|f32|f64)"
#define OPTIONS "hvr:f:q:c:w:p:t:" #define OPTIONS "hvc:r:f:w:q:u:t:p:"
static const struct option long_options[] = { static const struct option long_options[] = {
{ "help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h'},
{ "verbose", no_argument, NULL, 'v'}, { "verbose", no_argument, NULL, 'v'},
{ "cpuflags", required_argument, NULL, 'c' },
{ "rate", required_argument, NULL, 'r' }, { "rate", required_argument, NULL, 'r' },
{ "format", required_argument, NULL, 'f' }, { "format", required_argument, NULL, 'f' },
{ "window", required_argument, NULL, 'w' }, { "window", required_argument, NULL, 'w' },
{ "quality", required_argument, NULL, 'q' }, { "quality", required_argument, NULL, 'q' },
{ "param", required_argument, NULL, 'p' }, { "cutoff", required_argument, NULL, 'u' },
{ "taps", required_argument, NULL, 't' }, { "taps", required_argument, NULL, 't' },
{ "cpuflags", required_argument, NULL, 'c' }, { "param", required_argument, NULL, 'p' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -72,13 +73,13 @@ static void show_usage(const char *name, bool is_error)
fprintf(fp, fprintf(fp,
" -h, --help Show this help\n" " -h, --help Show this help\n"
" -v --verbose Be verbose\n" " -v --verbose Be verbose\n"
" -c --cpuflags CPU flags (default 0)\n"
"\n"); "\n");
fprintf(fp, fprintf(fp,
" -r --rate Output sample rate (default as input)\n" " -r --rate Output sample rate (default as input)\n"
" -f --format Output sample format %s (default as input)\n" " -f --format Output sample format %s (default as input)\n\n"
" -q --quality Resampler quality (default %u)\n"
" -w --window Window function (default %s)\n", " -w --window Window function (default %s)\n",
STR_FMTS, DEFAULT_QUALITY, resample_window_name(RESAMPLE_WINDOW_DEFAULT)); STR_FMTS, resample_window_name(RESAMPLE_WINDOW_DEFAULT));
for (i = 0; i < SPA_N_ELEMENTS(resample_window_info); i++) { for (i = 0; i < SPA_N_ELEMENTS(resample_window_info); i++) {
fprintf(fp, fprintf(fp,
" %s: %s\n", " %s: %s\n",
@ -86,17 +87,17 @@ static void show_usage(const char *name, bool is_error)
resample_window_info[i].description); resample_window_info[i].description);
} }
fprintf(fp, fprintf(fp,
" -q --quality Resampler quality (default %u)\n"
" -u --cutoff Cutoff frequency [0.0..1.0] (default from quality)\n"
" -t --taps Resampler taps (default from quality)\n" " -t --taps Resampler taps (default from quality)\n"
" -p --param Resampler param <name>=<value> (default from quality)\n"); " -p --param Resampler param <name>=<value> (default from quality)\n",
DEFAULT_QUALITY);
for (i = 0; i < SPA_N_ELEMENTS(resample_param_info); i++) { for (i = 0; i < SPA_N_ELEMENTS(resample_param_info); i++) {
fprintf(fp, fprintf(fp,
" %s\n", " %s\n",
resample_param_info[i].label); resample_param_info[i].label);
} }
fprintf(fp, fprintf(fp, "\n");
" -c --cpuflags CPU flags (default 0)\n"
"\n");
} }
static inline const char * static inline const char *
@ -356,6 +357,10 @@ int main(int argc, char *argv[])
case 'c': case 'c':
data.cpu_flags = strtol(optarg, NULL, 0); data.cpu_flags = strtol(optarg, NULL, 0);
break; break;
case 'u':
data.config.cutoff = strtod(optarg, NULL);
fprintf(stderr, "%f\n", data.config.cutoff);
break;
case 'w': case 'w':
data.config.window = resample_window_from_label(optarg); data.config.window = resample_window_from_label(optarg);
break; break;