[Libav-user] Using rematrix_maxval
gaetan.dubreil at free.fr
gaetan.dubreil at free.fr
Wed Dec 6 23:08:35 EET 2017
The following code reproduce the case.
Compiled with:
gcc -I/usr/include/i386-linux-gnu -lswresample -lavutil maxval.c -o maxval
The output :
> ./maxval
out_data[20] = 1.015233e+00
maxval.c :
#include <libavutil/samplefmt.h>
#include <libavutil/channel_layout.h>
#include <libavutil/opt.h>
#include <libswresample/swresample.h>
short in_data[] = {239, 2636, 2533, 5831, 6008, 6265, 6645, 6029, 8964, 6434, 9401, 9177, 8343, 26449, 31949, 29097, 31855, 30691, 32767, 31569, 27407, 26242, 26228, 27271, 24970, 25523, 19161, 14040, 16603, 10531, 7981, 9135, 8237, 8872, 8585, 8116, 6679, 6078};
#define in_data_size 38
double out_data[96000] = {0};
int main(int argc, char ** argv) {
short * p_in_data = in_data;
int in_size = in_data_size;
double * p_out_data = out_data;
int ret;
SwrContext *ctx = swr_alloc();
av_opt_set_channel_layout(ctx, "in_channel_layout", AV_CH_LAYOUT_MONO, 0);
av_opt_set_sample_fmt(ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
av_opt_set_int(ctx, "in_sample_rate", 44100, 0);
av_opt_set_channel_layout(ctx, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);
av_opt_set_sample_fmt(ctx, "out_sample_fmt", AV_SAMPLE_FMT_DBL, 0);
av_opt_set_int(ctx, "out_sample_rate", 48000, 0);
ret = av_opt_set_double(ctx, "rematrix_maxval", 1, 0);
if(ret != 0) return ret;
ret = swr_init(ctx);
if(ret < 0) return ret;
ret = swr_convert(ctx, (uint8_t **) &p_out_data, 96000,
(const uint8_t **) &p_in_data, in_size);
for(int j = 0; j < ret; j++) {
double d = out_data[j];
if(d > 1) {
printf("out_data[%d] = %e\n", j, d);
}
}
return 0;
}
----- Mail original -----
De: "Paul B Mahol" <onemda at gmail.com>
À: "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <libav-user at ffmpeg.org>
Envoyé: Lundi 4 Décembre 2017 21:42:57
Objet: Re: [Libav-user] Using rematrix_maxval
On 12/4/17, gaetan.dubreil at free.fr <gaetan.dubreil at free.fr> wrote:
> Hello,
>
> When I resample an audio file to the AV_SAMPLE_FMT_DBLP sample format with
> libswresample, I get some values out of the interval -1, 1. It happens when
> I resample from 44100 to 48000 for example. I tried to use the
> rematrix_maxval option like this :
>
> SwrContext *ctx = swr_alloc();
> ...
> av_opt_set_double(ctx, "rematrix_maxval", 1, 0);
> swr_init(ctx);
>
> but it have no effect.
> Does the way I use it are supposed to guarantee values between -1 and 1 or
> did I not understand its purpose?
> I can solve the problem by setting the rematrix_volume option to 0.96 but
> I'm not sure it will work in all cases.
>
> I wonder if being in 32 bits can be the cause of the problem.
I belive this is normal behaviour, to tell more we would need sample
that exhibits
this issue.
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
More information about the Libav-user
mailing list