Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-07-10 00:10:38 +0400
committerMichael Niedermayer <michaelni@gmx.at>2012-07-10 00:40:12 +0400
commitf8911b987de4a84ff8ae92f41ff492ece4acadb9 (patch)
tree0ebda51a6ba23d790da30a7168870928954da395 /libavresample
parentbf5386385dc504a076453ad58f61f808677be747 (diff)
parent5467742232c312b7d61dca7ac57447f728d8d6c9 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: mss3: use standard zigzag table mss3: split DSP functions that are used in MTS2(MSS4) into separate file motion-test: do not use getopt() tcp: add initial timeout limit for incoming connections configure: Change the rdtsc check to a linker check avconv: propagate fatal errors from lavfi. lavfi: add error handling to filter_samples(). fate-run: make avconv() properly deal with multiple inputs. asplit: don't leak the input buffer. af_resample: fix request_frame() behavior. af_asyncts: fix request_frame() behavior. libx264: support aspect ratio switching matroskadec: honor error_recognition when encountering unknown elements. lavr: resampling: add support for s32p, fltp, and dblp internal sample formats lavr: resampling: add filter type and Kaiser window beta to AVOptions lavr: Use AV_SAMPLE_FMT_NONE to auto-select the internal sample format lavr: mix: validate internal sample format in ff_audio_mix_init() Conflicts: ffmpeg.c ffplay.c libavcodec/libx264.c libavfilter/audio.c libavfilter/split.c libavformat/tcp.c tests/fate-run.sh Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavresample')
-rw-r--r--libavresample/audio_mix.c8
-rw-r--r--libavresample/avresample.h7
-rw-r--r--libavresample/internal.h2
-rw-r--r--libavresample/options.c7
-rw-r--r--libavresample/resample.c180
-rw-r--r--libavresample/resample_template.c102
-rw-r--r--libavresample/utils.c47
7 files changed, 246 insertions, 107 deletions
diff --git a/libavresample/audio_mix.c b/libavresample/audio_mix.c
index 93192221cd..2c2a356844 100644
--- a/libavresample/audio_mix.c
+++ b/libavresample/audio_mix.c
@@ -305,6 +305,14 @@ int ff_audio_mix_init(AVAudioResampleContext *avr)
{
int ret;
+ if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
+ avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {
+ av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "
+ "mixing: %s\n",
+ av_get_sample_fmt_name(avr->internal_sample_fmt));
+ return AVERROR(EINVAL);
+ }
+
/* build matrix if the user did not already set one */
if (!avr->am->matrix) {
int i, j;
diff --git a/libavresample/avresample.h b/libavresample/avresample.h
index 002bec21fb..b93aba5d73 100644
--- a/libavresample/avresample.h
+++ b/libavresample/avresample.h
@@ -45,6 +45,13 @@ enum AVMixCoeffType {
AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */
};
+/** Resampling Filter Types */
+enum AVResampleFilterType {
+ AV_RESAMPLE_FILTER_TYPE_CUBIC, /**< Cubic */
+ AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall Windowed Sinc */
+ AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */
+};
+
/**
* Return the LIBAVRESAMPLE_VERSION_INT constant.
*/
diff --git a/libavresample/internal.h b/libavresample/internal.h
index fa9499a8ef..7b7648f0be 100644
--- a/libavresample/internal.h
+++ b/libavresample/internal.h
@@ -50,6 +50,8 @@ struct AVAudioResampleContext {
int phase_shift; /**< log2 of the number of entries in the resampling polyphase filterbank */
int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */
double cutoff; /**< resampling cutoff frequency. 1.0 corresponds to half the output sample rate */
+ enum AVResampleFilterType filter_type; /**< resampling filter type */
+ int kaiser_beta; /**< beta value for Kaiser window (only applicable if filter_type == AV_FILTER_TYPE_KAISER) */
int in_channels; /**< number of input channels */
int out_channels; /**< number of output channels */
diff --git a/libavresample/options.c b/libavresample/options.c
index a1a0b0ca21..02e1f86308 100644
--- a/libavresample/options.c
+++ b/libavresample/options.c
@@ -39,7 +39,7 @@ static const AVOption options[] = {
{ "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM },
{ "out_sample_fmt", "Output Sample Format", OFFSET(out_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_NB-1, PARAM },
{ "out_sample_rate", "Output Sample Rate", OFFSET(out_sample_rate), AV_OPT_TYPE_INT, { 48000 }, 1, INT_MAX, PARAM },
- { "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_FLTP }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, PARAM },
+ { "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, PARAM },
{ "mix_coeff_type", "Mixing Coefficient Type", OFFSET(mix_coeff_type), AV_OPT_TYPE_INT, { AV_MIX_COEFF_TYPE_FLT }, AV_MIX_COEFF_TYPE_Q8, AV_MIX_COEFF_TYPE_NB-1, PARAM, "mix_coeff_type" },
{ "q8", "16-bit 8.8 Fixed-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_Q8 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
{ "q15", "32-bit 17.15 Fixed-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_Q15 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
@@ -56,6 +56,11 @@ static const AVOption options[] = {
{ "none", "None", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
{ "dolby", "Dolby", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
{ "dplii", "Dolby Pro Logic II", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DPLII }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
+ { "filter_type", "Filter Type", OFFSET(filter_type), AV_OPT_TYPE_INT, { AV_RESAMPLE_FILTER_TYPE_KAISER }, AV_RESAMPLE_FILTER_TYPE_CUBIC, AV_RESAMPLE_FILTER_TYPE_KAISER, PARAM, "filter_type" },
+ { "cubic", "Cubic", 0, AV_OPT_TYPE_CONST, { AV_RESAMPLE_FILTER_TYPE_CUBIC }, INT_MIN, INT_MAX, PARAM, "filter_type" },
+ { "blackman_nuttall", "Blackman Nuttall Windowed Sinc", 0, AV_OPT_TYPE_CONST, { AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL }, INT_MIN, INT_MAX, PARAM, "filter_type" },
+ { "kaiser", "Kaiser Windowed Sinc", 0, AV_OPT_TYPE_CONST, { AV_RESAMPLE_FILTER_TYPE_KAISER }, INT_MIN, INT_MAX, PARAM, "filter_type" },
+ { "kaiser_beta", "Kaiser Window Beta", OFFSET(kaiser_beta), AV_OPT_TYPE_INT, { 9 }, 2, 16, PARAM },
{ NULL },
};
diff --git a/libavresample/resample.c b/libavresample/resample.c
index 5529fafe8d..1c3d13ae0a 100644
--- a/libavresample/resample.c
+++ b/libavresample/resample.c
@@ -24,37 +24,10 @@
#include "internal.h"
#include "audio_data.h"
-#ifdef CONFIG_RESAMPLE_FLT
-/* float template */
-#define FILTER_SHIFT 0
-#define FELEM float
-#define FELEM2 float
-#define FELEML float
-#define WINDOW_TYPE 24
-#elifdef CONFIG_RESAMPLE_S32
-/* s32 template */
-#define FILTER_SHIFT 30
-#define FELEM int32_t
-#define FELEM2 int64_t
-#define FELEML int64_t
-#define FELEM_MAX INT32_MAX
-#define FELEM_MIN INT32_MIN
-#define WINDOW_TYPE 12
-#else
-/* s16 template */
-#define FILTER_SHIFT 15
-#define FELEM int16_t
-#define FELEM2 int32_t
-#define FELEML int64_t
-#define FELEM_MAX INT16_MAX
-#define FELEM_MIN INT16_MIN
-#define WINDOW_TYPE 9
-#endif
-
struct ResampleContext {
AVAudioResampleContext *avr;
AudioData *buffer;
- FELEM *filter_bank;
+ uint8_t *filter_bank;
int filter_length;
int ideal_dst_incr;
int dst_incr;
@@ -65,9 +38,35 @@ struct ResampleContext {
int phase_shift;
int phase_mask;
int linear;
+ enum AVResampleFilterType filter_type;
+ int kaiser_beta;
double factor;
+ void (*set_filter)(void *filter, double *tab, int phase, int tap_count);
+ void (*resample_one)(struct ResampleContext *c, int no_filter, void *dst0,
+ int dst_index, const void *src0, int src_size,
+ int index, int frac);
};
+
+/* double template */
+#define CONFIG_RESAMPLE_DBL
+#include "resample_template.c"
+#undef CONFIG_RESAMPLE_DBL
+
+/* float template */
+#define CONFIG_RESAMPLE_FLT
+#include "resample_template.c"
+#undef CONFIG_RESAMPLE_FLT
+
+/* s32 template */
+#define CONFIG_RESAMPLE_S32
+#include "resample_template.c"
+#undef CONFIG_RESAMPLE_S32
+
+/* s16 template */
+#include "resample_template.c"
+
+
/**
* 0th order modified bessel function of the first kind.
*/
@@ -95,17 +94,17 @@ static double bessel(double x)
* @param tap_count tap count
* @param phase_count phase count
* @param scale wanted sum of coefficients for each filter
- * @param type 0->cubic
- * 1->blackman nuttall windowed sinc
- * 2..16->kaiser windowed sinc beta=2..16
+ * @param filter_type filter type
+ * @param kaiser_beta kaiser window beta
* @return 0 on success, negative AVERROR code on failure
*/
-static int build_filter(FELEM *filter, double factor, int tap_count,
- int phase_count, int scale, int type)
+static int build_filter(ResampleContext *c)
{
int ph, i;
- double x, y, w;
+ double x, y, w, factor;
double *tab;
+ int tap_count = c->filter_length;
+ int phase_count = 1 << c->phase_shift;
const int center = (tap_count - 1) / 2;
tab = av_malloc(tap_count * sizeof(*tab));
@@ -113,8 +112,7 @@ static int build_filter(FELEM *filter, double factor, int tap_count,
return AVERROR(ENOMEM);
/* if upsampling, only need to interpolate, no filter */
- if (factor > 1.0)
- factor = 1.0;
+ factor = FFMIN(c->factor, 1.0);
for (ph = 0; ph < phase_count; ph++) {
double norm = 0;
@@ -122,39 +120,34 @@ static int build_filter(FELEM *filter, double factor, int tap_count,
x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
if (x == 0) y = 1.0;
else y = sin(x) / x;
- switch (type) {
- case 0: {
+ switch (c->filter_type) {
+ case AV_RESAMPLE_FILTER_TYPE_CUBIC: {
const float d = -0.5; //first order derivative = -0.5
x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);
else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);
break;
}
- case 1:
+ case AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL:
w = 2.0 * x / (factor * tap_count) + M_PI;
y *= 0.3635819 - 0.4891775 * cos( w) +
0.1365995 * cos(2 * w) -
0.0106411 * cos(3 * w);
break;
- default:
+ case AV_RESAMPLE_FILTER_TYPE_KAISER:
w = 2.0 * x / (factor * tap_count * M_PI);
- y *= bessel(type * sqrt(FFMAX(1 - w * w, 0)));
+ y *= bessel(c->kaiser_beta * sqrt(FFMAX(1 - w * w, 0)));
break;
}
tab[i] = y;
norm += y;
}
-
/* normalize so that an uniform color remains the same */
- for (i = 0; i < tap_count; i++) {
-#ifdef CONFIG_RESAMPLE_FLT
- filter[ph * tap_count + i] = tab[i] / norm;
-#else
- filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm),
- FELEM_MIN, FELEM_MAX);
-#endif
- }
+ for (i = 0; i < tap_count; i++)
+ tab[i] = tab[i] / norm;
+
+ c->set_filter(c->filter_bank, tab, ph, tap_count);
}
av_free(tab);
@@ -168,9 +161,12 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr)
int in_rate = avr->in_sample_rate;
double factor = FFMIN(out_rate * avr->cutoff / in_rate, 1.0);
int phase_count = 1 << avr->phase_shift;
+ int felem_size;
- /* TODO: add support for s32 and float internal formats */
- if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) {
+ if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
+ avr->internal_sample_fmt != AV_SAMPLE_FMT_S32P &&
+ avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP &&
+ avr->internal_sample_fmt != AV_SAMPLE_FMT_DBLP) {
av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "
"resampling: %s\n",
av_get_sample_fmt_name(avr->internal_sample_fmt));
@@ -186,18 +182,40 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr)
c->linear = avr->linear_interp;
c->factor = factor;
c->filter_length = FFMAX((int)ceil(avr->filter_size / factor), 1);
+ c->filter_type = avr->filter_type;
+ c->kaiser_beta = avr->kaiser_beta;
+
+ switch (avr->internal_sample_fmt) {
+ case AV_SAMPLE_FMT_DBLP:
+ c->resample_one = resample_one_dbl;
+ c->set_filter = set_filter_dbl;
+ break;
+ case AV_SAMPLE_FMT_FLTP:
+ c->resample_one = resample_one_flt;
+ c->set_filter = set_filter_flt;
+ break;
+ case AV_SAMPLE_FMT_S32P:
+ c->resample_one = resample_one_s32;
+ c->set_filter = set_filter_s32;
+ break;
+ case AV_SAMPLE_FMT_S16P:
+ c->resample_one = resample_one_s16;
+ c->set_filter = set_filter_s16;
+ break;
+ }
- c->filter_bank = av_mallocz(c->filter_length * (phase_count + 1) * sizeof(FELEM));
+ felem_size = av_get_bytes_per_sample(avr->internal_sample_fmt);
+ c->filter_bank = av_mallocz(c->filter_length * (phase_count + 1) * felem_size);
if (!c->filter_bank)
goto error;
- if (build_filter(c->filter_bank, factor, c->filter_length, phase_count,
- 1 << FILTER_SHIFT, WINDOW_TYPE) < 0)
+ if (build_filter(c) < 0)
goto error;
- memcpy(&c->filter_bank[c->filter_length * phase_count + 1],
- c->filter_bank, (c->filter_length - 1) * sizeof(FELEM));
- c->filter_bank[c->filter_length * phase_count] = c->filter_bank[c->filter_length - 1];
+ memcpy(&c->filter_bank[(c->filter_length * phase_count + 1) * felem_size],
+ c->filter_bank, (c->filter_length - 1) * felem_size);
+ memcpy(&c->filter_bank[c->filter_length * phase_count * felem_size],
+ &c->filter_bank[(c->filter_length - 1) * felem_size], felem_size);
c->compensation_distance = 0;
if (!av_reduce(&c->src_incr, &c->dst_incr, out_rate,
@@ -311,10 +329,10 @@ reinit_fail:
return ret;
}
-static int resample(ResampleContext *c, int16_t *dst, const int16_t *src,
+static int resample(ResampleContext *c, void *dst, const void *src,
int *consumed, int src_size, int dst_size, int update_ctx)
{
- int dst_index, i;
+ int dst_index;
int index = c->index;
int frac = c->frac;
int dst_incr_frac = c->dst_incr % c->src_incr;
@@ -334,7 +352,7 @@ static int resample(ResampleContext *c, int16_t *dst, const int16_t *src,
if (dst) {
for(dst_index = 0; dst_index < dst_size; dst_index++) {
- dst[dst_index] = src[index2 >> 32];
+ c->resample_one(c, 1, dst, dst_index, src, 0, index2 >> 32, 0);
index2 += incr;
}
} else {
@@ -345,42 +363,14 @@ static int resample(ResampleContext *c, int16_t *dst, const int16_t *src,
frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
} else {
for (dst_index = 0; dst_index < dst_size; dst_index++) {
- FELEM *filter = c->filter_bank +
- c->filter_length * (index & c->phase_mask);
int sample_index = index >> c->phase_shift;
- if (!dst && (sample_index + c->filter_length > src_size ||
- -sample_index >= src_size))
+ if (sample_index + c->filter_length > src_size ||
+ -sample_index >= src_size)
break;
- if (dst) {
- FELEM2 val = 0;
-
- if (sample_index < 0) {
- for (i = 0; i < c->filter_length; i++)
- val += src[FFABS(sample_index + i) % src_size] *
- (FELEM2)filter[i];
- } else if (sample_index + c->filter_length > src_size) {
- break;
- } else if (c->linear) {
- FELEM2 v2 = 0;
- for (i = 0; i < c->filter_length; i++) {
- val += src[abs(sample_index + i)] * (FELEM2)filter[i];
- v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
- }
- val += (v2 - val) * (FELEML)frac / c->src_incr;
- } else {
- for (i = 0; i < c->filter_length; i++)
- val += src[sample_index + i] * (FELEM2)filter[i];
- }
-
-#ifdef CONFIG_RESAMPLE_FLT
- dst[dst_index] = av_clip_int16(lrintf(val));
-#else
- val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
- dst[dst_index] = av_clip_int16(val);
-#endif
- }
+ if (dst)
+ c->resample_one(c, 0, dst, dst_index, src, src_size, index, frac);
frac += dst_incr_frac;
index += dst_incr;
@@ -451,8 +441,8 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src,
/* resample each channel plane */
for (ch = 0; ch < c->buffer->channels; ch++) {
- out_samples = resample(c, (int16_t *)dst->data[ch],
- (const int16_t *)c->buffer->data[ch], consumed,
+ out_samples = resample(c, (void *)dst->data[ch],
+ (const void *)c->buffer->data[ch], consumed,
c->buffer->nb_samples, dst->allocated_samples,
ch + 1 == c->buffer->channels);
}
diff --git a/libavresample/resample_template.c b/libavresample/resample_template.c
new file mode 100644
index 0000000000..06da90fe9f
--- /dev/null
+++ b/libavresample/resample_template.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if defined(CONFIG_RESAMPLE_DBL)
+#define SET_TYPE(func) func ## _dbl
+#define FELEM double
+#define FELEM2 double
+#define FELEML double
+#define OUT(d, v) d = v
+#define DBL_TO_FELEM(d, v) d = v
+#elif defined(CONFIG_RESAMPLE_FLT)
+#define SET_TYPE(func) func ## _flt
+#define FELEM float
+#define FELEM2 float
+#define FELEML float
+#define OUT(d, v) d = v
+#define DBL_TO_FELEM(d, v) d = v
+#elif defined(CONFIG_RESAMPLE_S32)
+#define SET_TYPE(func) func ## _s32
+#define FELEM int32_t
+#define FELEM2 int64_t
+#define FELEML int64_t
+#define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30)
+#define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30)));
+#else
+#define SET_TYPE(func) func ## _s16
+#define FELEM int16_t
+#define FELEM2 int32_t
+#define FELEML int64_t
+#define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15)
+#define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15)))
+#endif
+
+static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter,
+ void *dst0, int dst_index, const void *src0,
+ int src_size, int index, int frac)
+{
+ FELEM *dst = dst0;
+ const FELEM *src = src0;
+
+ if (no_filter) {
+ dst[dst_index] = src[index];
+ } else {
+ int i;
+ int sample_index = index >> c->phase_shift;
+ FELEM2 val = 0;
+ FELEM *filter = ((FELEM *)c->filter_bank) +
+ c->filter_length * (index & c->phase_mask);
+
+ if (sample_index < 0) {
+ for (i = 0; i < c->filter_length; i++)
+ val += src[FFABS(sample_index + i) % src_size] *
+ (FELEM2)filter[i];
+ } else if (c->linear) {
+ FELEM2 v2 = 0;
+ for (i = 0; i < c->filter_length; i++) {
+ val += src[abs(sample_index + i)] * (FELEM2)filter[i];
+ v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
+ }
+ val += (v2 - val) * (FELEML)frac / c->src_incr;
+ } else {
+ for (i = 0; i < c->filter_length; i++)
+ val += src[sample_index + i] * (FELEM2)filter[i];
+ }
+
+ OUT(dst[dst_index], val);
+ }
+}
+
+static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,
+ int tap_count)
+{
+ int i;
+ FELEM *filter = ((FELEM *)filter0) + phase * tap_count;
+ for (i = 0; i < tap_count; i++) {
+ DBL_TO_FELEM(filter[i], tab[i]);
+ }
+}
+
+#undef SET_TYPE
+#undef FELEM
+#undef FELEM2
+#undef FELEML
+#undef OUT
+#undef DBL_TO_FELEM
diff --git a/libavresample/utils.c b/libavresample/utils.c
index 21bb9309b3..caf9081e5d 100644
--- a/libavresample/utils.c
+++ b/libavresample/utils.c
@@ -57,18 +57,43 @@ int avresample_open(AVAudioResampleContext *avr)
avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate ||
avr->force_resampling;
- /* set sample format conversion parameters */
- /* override user-requested internal format to avoid unexpected failures
- TODO: support more internal formats */
- if (avr->resample_needed && avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) {
- av_log(avr, AV_LOG_WARNING, "Using s16p as internal sample format\n");
- avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;
- } else if (avr->mixing_needed &&
- avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
- avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {
- av_log(avr, AV_LOG_WARNING, "Using fltp as internal sample format\n");
- avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
+ /* select internal sample format if not specified by the user */
+ if (avr->internal_sample_fmt == AV_SAMPLE_FMT_NONE &&
+ (avr->mixing_needed || avr->resample_needed)) {
+ enum AVSampleFormat in_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
+ enum AVSampleFormat out_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
+ int max_bps = FFMAX(av_get_bytes_per_sample(in_fmt),
+ av_get_bytes_per_sample(out_fmt));
+ if (max_bps <= 2) {
+ avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;
+ } else if (avr->mixing_needed) {
+ avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
+ } else {
+ if (max_bps <= 4) {
+ if (in_fmt == AV_SAMPLE_FMT_S32P ||
+ out_fmt == AV_SAMPLE_FMT_S32P) {
+ if (in_fmt == AV_SAMPLE_FMT_FLTP ||
+ out_fmt == AV_SAMPLE_FMT_FLTP) {
+ /* if one is s32 and the other is flt, use dbl */
+ avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP;
+ } else {
+ /* if one is s32 and the other is s32, s16, or u8, use s32 */
+ avr->internal_sample_fmt = AV_SAMPLE_FMT_S32P;
+ }
+ } else {
+ /* if one is flt and the other is flt, s16 or u8, use flt */
+ avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
+ }
+ } else {
+ /* if either is dbl, use dbl */
+ avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP;
+ }
+ }
+ av_log(avr, AV_LOG_DEBUG, "Using %s as internal sample format\n",
+ av_get_sample_fmt_name(avr->internal_sample_fmt));
}
+
+ /* set sample format conversion parameters */
if (avr->in_channels == 1)
avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
if (avr->out_channels == 1)