summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-04-11 19:24:40 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-04-11 19:34:03 +0200
commit671f9086571adc5de48ae1ef3be01cf194864a49 (patch)
treea1ce738a8c76ff8b4d6207ca4f55055ca431a6d4
parentc04961fa0ff63a87f07ba411f4f0a413a23ceea8 (diff)
parentf20892eb67a7b4b5a3c080388a35a3380516a805 (diff)
downloadffmpeg-671f9086571adc5de48ae1ef3be01cf194864a49.tar.gz
Merge commit 'f20892eb67a7b4b5a3c080388a35a3380516a805'
* commit 'f20892eb67a7b4b5a3c080388a35a3380516a805': resample: split the nearest neighbour path into a separate function pointer Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavresample/resample.c25
-rw-r--r--libavresample/resample_template.c13
2 files changed, 25 insertions, 13 deletions
diff --git a/libavresample/resample.c b/libavresample/resample.c
index 91093d9d26..b034279da8 100644
--- a/libavresample/resample.c
+++ b/libavresample/resample.c
@@ -44,9 +44,11 @@ struct ResampleContext {
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,
+ void (*resample_one)(struct ResampleContext *c, void *dst0,
int dst_index, const void *src0, int src_size,
int index, int frac);
+ void (*resample_nearest)(void *dst0, int dst_index,
+ const void *src0, int index);
int padding_size;
};
@@ -178,18 +180,22 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr)
switch (avr->internal_sample_fmt) {
case AV_SAMPLE_FMT_DBLP:
c->resample_one = resample_one_dbl;
+ c->resample_nearest = resample_nearest_dbl;
c->set_filter = set_filter_dbl;
break;
case AV_SAMPLE_FMT_FLTP:
c->resample_one = resample_one_flt;
+ c->resample_nearest = resample_nearest_flt;
c->set_filter = set_filter_flt;
break;
case AV_SAMPLE_FMT_S32P:
c->resample_one = resample_one_s32;
+ c->resample_nearest = resample_nearest_s32;
c->set_filter = set_filter_s32;
break;
case AV_SAMPLE_FMT_S16P:
c->resample_one = resample_one_s16;
+ c->resample_nearest = resample_nearest_s16;
c->set_filter = set_filter_s16;
break;
}
@@ -332,7 +338,8 @@ reinit_fail:
}
static int resample(ResampleContext *c, void *dst, const void *src,
- int *consumed, int src_size, int dst_size, int update_ctx)
+ int *consumed, int src_size, int dst_size, int update_ctx,
+ int nearest_neighbour)
{
int dst_index;
int index = c->index;
@@ -344,8 +351,7 @@ static int resample(ResampleContext *c, void *dst, const void *src,
if (!dst != !src)
return AVERROR(EINVAL);
- if (compensation_distance == 0 && c->filter_length == 1 &&
- c->phase_shift == 0) {
+ if (nearest_neighbour) {
int64_t index2 = ((int64_t)index) << 32;
int64_t incr = (1LL << 32) * c->dst_incr / c->src_incr;
dst_size = FFMIN(dst_size,
@@ -354,7 +360,7 @@ static int resample(ResampleContext *c, void *dst, const void *src,
if (dst) {
for(dst_index = 0; dst_index < dst_size; dst_index++) {
- c->resample_one(c, 1, dst, dst_index, src, 0, index2 >> 32, 0);
+ c->resample_nearest(dst, dst_index, src, index2 >> 32);
index2 += incr;
}
} else {
@@ -372,7 +378,7 @@ static int resample(ResampleContext *c, void *dst, const void *src,
break;
if (dst)
- c->resample_one(c, 0, dst, dst_index, src, src_size, index, frac);
+ c->resample_one(c, dst, dst_index, src, src_size, index, frac);
frac += dst_incr_frac;
index += dst_incr;
@@ -412,6 +418,9 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
{
int ch, in_samples, in_leftover, consumed = 0, out_samples = 0;
int ret = AVERROR(EINVAL);
+ int nearest_neighbour = (c->compensation_distance == 0 &&
+ c->filter_length == 1 &&
+ c->phase_shift == 0);
in_samples = src ? src->nb_samples : 0;
in_leftover = c->buffer->nb_samples;
@@ -432,7 +441,7 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
/* TODO: try to calculate this without the dummy resample() run */
if (!dst->read_only && dst->allow_realloc) {
out_samples = resample(c, NULL, NULL, NULL, c->buffer->nb_samples,
- INT_MAX, 0);
+ INT_MAX, 0, nearest_neighbour);
ret = ff_audio_data_realloc(dst, out_samples);
if (ret < 0) {
av_log(c->avr, AV_LOG_ERROR, "error reallocating output\n");
@@ -445,7 +454,7 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
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);
+ ch + 1 == c->buffer->channels, nearest_neighbour);
}
if (out_samples < 0) {
av_log(c->avr, AV_LOG_ERROR, "error during resampling\n");
diff --git a/libavresample/resample_template.c b/libavresample/resample_template.c
index 458944ebb2..6b2a6af433 100644
--- a/libavresample/resample_template.c
+++ b/libavresample/resample_template.c
@@ -54,16 +54,20 @@
#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,
+static void SET_TYPE(resample_nearest)(void *dst0, int dst_index, const void *src0, int index)
+{
+ FELEM *dst = dst0;
+ const FELEM *src = src0;
+ dst[dst_index] = src[index];
+}
+
+static void SET_TYPE(resample_one)(ResampleContext *c,
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;
@@ -87,7 +91,6 @@ static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter,
}
OUT(dst[dst_index], val);
- }
}
static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,