X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=resample_filter.c;h=bbdda51c525630c6d1411dfa547193f8ccdae9ce;hp=e630596aaf9a244038b608533310c62e16763cca;hb=62c0894fbb589dd45e69b7d9ef1fd152a9960d62;hpb=4adde8dae3317fa83b81e7a860c9ed9133e99bb0 diff --git a/resample_filter.c b/resample_filter.c index e630596a..bbdda51c 100644 --- a/resample_filter.c +++ b/resample_filter.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2012 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2012 Andre Noll , see file COPYING. */ /** \file resample_filter.c A sample rate converter based on libsamplerate. */ @@ -126,13 +122,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; @@ -147,6 +155,7 @@ static int resample_frames(int16_t *in, size_t num_frames, bool have_more, size_t *result_frames) { int ret, num_samples, out_samples; + float *in_float; int16_t *out; SRC_DATA data; @@ -158,11 +167,12 @@ static int resample_frames(int16_t *in, size_t num_frames, bool have_more, data.output_frames = num_frames * ctx->ratio + 1; out_samples = data.output_frames * ctx->channels; - data.data_in = para_malloc(num_samples * sizeof(float)); - src_short_to_float_array(in, data.data_in, num_samples); + in_float = para_malloc(num_samples * sizeof(float)); + src_short_to_float_array(in, in_float, num_samples); + data.data_in = in_float; data.data_out = para_malloc(out_samples * sizeof(float)); ret = src_process(ctx->src_state, &data); - free(data.data_in); + free(in_float); if (ret != 0) { PARA_ERROR_LOG("%s\n", src_strerror(ret)); free(data.data_out); @@ -233,8 +243,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 +265,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,