]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
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 03e79d9167eb1e89b5eb4cd339e3345a6f20ed23..ef8669a8a8194cc93303c6f0a9a8ecd75117b7df 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))
 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) \
 #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 4dda0bf9dcd70d3dec7b7eafd81b52d45c681ae4..d269d2374176adef783ca1f78ee0ac4832eb86da 100644 (file)
@@ -114,6 +114,14 @@ caption = filters
                typestr = type
                arg_info = required_arg
                arg_type = string
                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
                default_val = medium
                [help]
                        best: This is a bandlimited interpolator derived from the mathematical
index e630596aaf9a244038b608533310c62e16763cca..72a1864eeafb69982cc1f0e49a1013eb81872341 100644 (file)
@@ -126,13 +126,25 @@ static int resample_set_params(struct filter_node *fn)
 
 static int resample_init(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;
        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;
        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;
        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)
 {
 
 static void *resample_setup(const struct lls_parse_result *lpr)
 {
-       int given, *converter;
-       const char *converter_arg;
+       int given;
        uint32_t u32;
 
        /* sanity checks */
        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);
        }
                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,
 }
 
 static void resample_teardown(__a_unused const struct lls_parse_result *lpr,