make converter_arg in resamplefilter an enum option
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 27 Dec 2016 17:54:37 +0000 (18:54 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Mar 2017 09:02:28 +0000 (11:02 +0200)
filter.h
m4/lls/filter_cmd.suite.m4
resample_filter.c

index 03e79d9..ef8669a 100644 (file)
--- 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) \
index 4dda0bf..d269d23 100644 (file)
@@ -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
index e630596..72a1864 100644 (file)
@@ -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,