From: Andre Noll Date: Tue, 27 Dec 2016 17:54:37 +0000 (+0100) Subject: make converter_arg in resamplefilter an enum option X-Git-Tag: v0.6.0~2^2~30 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=fb26e35b38544d4bb90fb80c6b4f68d9a76842c8;p=paraslash.git make converter_arg in resamplefilter an enum option --- diff --git a/filter.h b/filter.h index 03e79d91..ef8669a8 100644 --- a/filter.h +++ b/filter.h @@ -115,6 +115,9 @@ struct filter { void print_filter_helps(bool detailed); int filter_setup(const char *fa, void **conf, struct lls_parse_result **lprp); #define FILTER_CMD(_num) (lls_cmd(_num, filter_cmd_suite)) +#define FILTER_CMD_OPT(_cmd, _opt) (lls_opt( \ + LSG_FILTER_CMD_ ## _cmd ## _OPT_ ## _opt, \ + FILTER_CMD(LSG_FILTER_CMD_CMD_ ## _cmd))) #define FILTER_CMD_OPT_RESULT(_cmd, _opt, _lpr) \ (lls_opt_result(LSG_FILTER_CMD_ ## _cmd ## _OPT_ ## _opt, _lpr)) #define FILTER_CMD_OPT_GIVEN(_cmd, _opt, _lpr) \ diff --git a/m4/lls/filter_cmd.suite.m4 b/m4/lls/filter_cmd.suite.m4 index 4dda0bf9..d269d237 100644 --- a/m4/lls/filter_cmd.suite.m4 +++ b/m4/lls/filter_cmd.suite.m4 @@ -114,6 +114,14 @@ caption = filters typestr = type arg_info = required_arg arg_type = string + values = { + # RCT: resample conversion type + RCT_BEST = "best", + RCT_MEDIUM = "medium", + RCT_FASTEST = "fastest", + RCT_ZERO_ORDER_HOLD = "zero_order_hold", + RCT_LINEAR = "linear" + } default_val = medium [help] best: This is a bandlimited interpolator derived from the mathematical diff --git a/resample_filter.c b/resample_filter.c index e630596a..72a1864e 100644 --- a/resample_filter.c +++ b/resample_filter.c @@ -126,13 +126,25 @@ static int resample_set_params(struct filter_node *fn) static int resample_init(struct filter_node *fn) { - int ret, converter = *(int *)fn->conf; + int ret; + const uint32_t trafo[] = { + [RCT_BEST] = SRC_SINC_BEST_QUALITY, + [RCT_MEDIUM] = SRC_SINC_MEDIUM_QUALITY, + [RCT_FASTEST] = SRC_SINC_FASTEST, + [RCT_ZERO_ORDER_HOLD] = SRC_ZERO_ORDER_HOLD, + [RCT_LINEAR] = SRC_LINEAR + }; struct resample_context *ctx = fn->private_data; + const struct lls_option *o_c = FILTER_CMD_OPT(RESAMPLE, CONVERTER); + uint32_t converter = U32_OPTVAL(CONVERTER, fn->lpr); + PARA_INFO_LOG("converter type: %s\n", + lls_enum_string_val(converter, o_c)); ret = resample_set_params(fn); if (ret < 0) return ret; - ctx->src_state = src_new(converter, U32_OPTVAL(CHANNELS, fn->lpr), &ret); + ctx->src_state = src_new(trafo[converter], + U32_OPTVAL(CHANNELS, fn->lpr), &ret); if (!ctx->src_state) { PARA_ERROR_LOG("%s\n", src_strerror(ret)); return -E_LIBSAMPLERATE; @@ -233,8 +245,7 @@ out: static void *resample_setup(const struct lls_parse_result *lpr) { - int given, *converter; - const char *converter_arg; + int given; uint32_t u32; /* sanity checks */ @@ -256,23 +267,7 @@ static void *resample_setup(const struct lls_parse_result *lpr) PARA_EMERG_LOG("fatal: destination sample rate can not be 0\n"); exit(EXIT_FAILURE); } - converter = para_malloc(sizeof(int)); - converter_arg = FILTER_CMD_OPT_STRING_VAL(RESAMPLE, CONVERTER, lpr); - if (!strcmp(converter_arg, "best")) - *converter = SRC_SINC_BEST_QUALITY; - else if (!strcmp(converter_arg, "medium")) - *converter = SRC_SINC_MEDIUM_QUALITY; - else if (!strcmp(converter_arg, "fastest")) - *converter = SRC_SINC_FASTEST; - else if (!strcmp(converter_arg, "zero_order_hold")) - *converter = SRC_ZERO_ORDER_HOLD; - else if (!strcmp(converter_arg, "linear")) - *converter = SRC_LINEAR; - else { - PARA_EMERG_LOG("invalid converter type: %s\n", converter_arg); - exit(EXIT_FAILURE); - } - return converter; + return NULL; } static void resample_teardown(__a_unused const struct lls_parse_result *lpr,