31 #define CONFIG_RESAMPLE_DBL
33 #undef CONFIG_RESAMPLE_DBL
36 #define CONFIG_RESAMPLE_FLT
38 #undef CONFIG_RESAMPLE_FLT
41 #define CONFIG_RESAMPLE_S32
43 #undef CONFIG_RESAMPLE_S32
58 for (i = 1; v != lastv; i++) {
74 const int center = (tap_count - 1) / 2;
76 tab =
av_malloc(tap_count *
sizeof(*tab));
80 for (ph = 0; ph < phase_count; ph++) {
82 for (i = 0; i < tap_count; i++) {
83 x =
M_PI * ((double)(i - center) - (double)ph / phase_count) *
factor;
89 x = fabs(((
double)(i - center) - (
double)ph / phase_count) * factor);
90 if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);
91 else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);
95 w = 2.0 * x / (factor * tap_count) +
M_PI;
96 y *= 0.3635819 - 0.4891775 * cos( w) +
97 0.1365995 * cos(2 * w) -
98 0.0106411 * cos(3 * w);
101 w = 2.0 * x / (factor * tap_count *
M_PI);
110 for (i = 0; i < tap_count; i++)
111 tab[i] = tab[i] / norm;
193 in_rate * (int64_t)phase_count, INT32_MAX / 2))
238 if (compensation_distance < 0)
240 if (!compensation_distance && sample_delta)
249 if (compensation_distance) {
251 (int64_t)sample_delta / compensation_distance;
260 int *consumed,
int src_size,
int dst_size,
int update_ctx,
261 int nearest_neighbour)
273 if (nearest_neighbour) {
274 uint64_t index2 = ((uint64_t)index) << 32;
276 dst_size =
FFMIN(dst_size,
277 (src_size-1-index) * (int64_t)c->
src_incr /
281 for(dst_index = 0; dst_index < dst_size; dst_index++) {
286 dst_index = dst_size;
289 index += (frac + dst_index * (int64_t)dst_incr_frac) / c->
src_incr;
290 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->
src_incr;
292 for (dst_index = 0; dst_index < dst_size; dst_index++) {
301 frac += dst_incr_frac;
307 if (dst_index + 1 == compensation_distance) {
308 compensation_distance = 0;
320 if (compensation_distance) {
321 compensation_distance -= dst_index;
322 if (compensation_distance <= 0)
336 int ch, in_samples, in_leftover, consumed = 0, out_samples = 0;
350 }
else if (in_leftover <= c->final_padding_samples) {
368 memset(c->
buffer->
data[ch] + bps * i, 0, bps);
379 FFMAX(in_samples, in_leftover) +
388 if (in_leftover > i) {
389 memcpy(c->
buffer->
data[ch] + bps * (in_leftover + i),
390 c->
buffer->
data[ch] + bps * (in_leftover - i - 1),
393 memset(c->
buffer->
data[ch] + bps * (in_leftover + i),
407 INT_MAX, 0, nearest_neighbour);
422 if (out_samples < 0) {
int initial_padding_filled
int initial_padding_samples
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
Audio buffer used for intermediate storage between conversion phases.
void(* set_filter)(void *filter, double *tab, int phase, int tap_count)
AudioData * ff_audio_data_alloc(int channels, int nb_samples, enum AVSampleFormat sample_fmt, const char *name)
Allocate AudioData.
int allow_realloc
realloc is allowed
int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, int compensation_distance)
Set compensation for resampling.
double cutoff
resampling cutoff frequency.
int nb_samples
current number of samples
static int resample(ResampleContext *c, void *dst, const void *src, int *consumed, int src_size, int dst_size, int update_ctx, int nearest_neighbour)
AVAudioResampleContext * avr
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
int read_only
data is read-only
int compensation_distance
enum AVResampleFilterType filter_type
int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
Resample audio data.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int channels
channel count
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
int compensation_distance
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
ResampleContext * resample
resampling context
av_cold void ff_audio_resample_init_arm(ResampleContext *c, enum AVSampleFormat sample_fmt)
int phase_shift
log2 of the number of entries in the resampling polyphase filterbank
int ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src, int src_offset, int nb_samples)
Append data from one AudioData to the end of another.
void ff_audio_data_drain(AudioData *a, int nb_samples)
Drain samples from the start of the AudioData.
int linear_interp
if 1 then the resampling FIR filter will be linearly interpolated
int kaiser_beta
beta value for Kaiser window (only applicable if filter_type == AV_FILTER_TYPE_KAISER) ...
int in_sample_rate
input sample rate
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
void ff_audio_resample_free(ResampleContext **c)
Free a ResampleContext.
static int build_filter(ResampleContext *c, double factor)
uint8_t * data[AVRESAMPLE_MAX_CHANNELS]
data plane pointers
enum AVResampleFilterType filter_type
resampling filter type
enum AVSampleFormat internal_sample_fmt
internal sample format
Replacements for frequently missing libm functions.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
ResampleContext * ff_audio_resample_init(AVAudioResampleContext *avr)
Allocate and initialize a ResampleContext.
int filter_size
length of each FIR filter in the resampling filterbank relative to the cutoff frequency ...
Blackman Nuttall Windowed Sinc.
static const int factor[16]
void(* resample_one)(struct ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
common internal and external API header
int resample_channels
number of channels used for resampling
int resample_needed
resampling is needed
int final_padding_samples
int allocated_samples
number of samples the buffer can hold
static const struct twinvq_data tab
int out_sample_rate
output sample rate
void ff_audio_data_free(AudioData **a)
Free AudioData.
void(* resample_nearest)(void *dst0, int dst_index, const void *src0, unsigned int index)
static double bessel(double x)
av_cold void ff_audio_resample_init_aarch64(ResampleContext *c, enum AVSampleFormat sample_fmt)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...