]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
resample filter: Don't discard const.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 29 Dec 2017 13:50:28 +0000 (14:50 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 31 Dec 2017 13:52:32 +0000 (14:52 +0100)
Newer versions of libsamplerate made the data_in pointer const. This
causes the following warning:

In file included from resample_filter.c:6:0:
/usr/local/include/samplerate.h:177:6: note: expected 'float *' but argument is of type 'const float *'
 void src_short_to_float_array (const short *in, float *out, int len) ;
      ^
resample_filter.c:173:7: warning: passing argument 1 of 'free' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
In file included from para.h:11:0,
 from resample_filter.c:10:
/usr/include/stdlib.h:460:13: note: expected 'void *' but argument is of type 'const float *'
 extern void free (void *__ptr) __THROW;

The problem is that we first convert the input from int16 to float
and use the data_in pointer as the target for the conversion.

Fix this by introducing a temporary non-const variable for the
converted input.

resample_filter.c

index 1699ed2c03afcc84cc7b8b3e2e8a7f91aca13cc5..84a2ee700aae4c2d4dcbe50a186ccbcf54d0cdce 100644 (file)
@@ -166,6 +166,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;
 
@@ -177,11 +178,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);