@@ -302,7 +302,7 @@ fail:
static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta,
- double precision, int cheby, int exact_rational)
+ double precision, int cheby, int exact_rational, int force_comp)
{
double cutoff = cutoff0? cutoff0 : 0.97;
double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
@@ -316,6 +316,8 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r
if (phase_count_exact <= phase_count) {
phase_count_compensation = phase_count_exact * (phase_count / phase_count_exact);
phase_count = phase_count_exact;
+ if (force_comp)
+ phase_count = phase_count_compensation;
}
}
@@ -30,7 +30,7 @@
#include <soxr.h>
static struct ResampleContext *create(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
- double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, int exact_rational){
+ double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, int exact_rational, int force_comp){
soxr_error_t error;
soxr_datatype_t type =
@@ -265,7 +265,10 @@ av_cold int swr_init(struct SwrContext *s){
}
if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
- s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type, s->kaiser_beta, s->precision, s->cheby, s->exact_rational);
+ s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size,
+ s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type,
+ s->kaiser_beta, s->precision, s->cheby, s->exact_rational,
+ s->min_compensation < FLT_MAX && s->soft_compensation_duration && s->max_soft_compensation);
if (!s->resample) {
av_log(s, AV_LOG_ERROR, "Failed to initialize resampler\n");
return AVERROR(ENOMEM);
@@ -69,7 +69,8 @@ struct DitherContext {
};
typedef struct ResampleContext * (* resample_init_func)(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
- double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, int exact_rational);
+ double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby,
+ int exact_rational, int force_comp);
typedef void (* resample_free_func)(struct ResampleContext **c);
typedef int (* multiple_resample_func)(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed);
typedef int (* resample_flush_func)(struct SwrContext *c);
this allow to use phase_count_compensation on init (rather than rebuild on swr_set_compensation) when options suggest that soft compensation is enabled Signed-off-by: Muhammad Faiz <mfcc64@gmail.com> --- libswresample/resample.c | 4 +++- libswresample/soxr_resample.c | 2 +- libswresample/swresample.c | 5 ++++- libswresample/swresample_internal.h | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-)