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;
125 double factor =
FFMIN(out_rate * avr->
cutoff / in_rate, 1.0);
191 in_rate * (int64_t)phase_count, INT32_MAX / 2))
232 int compensation_distance)
238 if (compensation_distance < 0)
240 if (!compensation_distance && sample_delta)
244 #if FF_API_RESAMPLE_CLOSE_OPEN
248 int restore_matrix = 0;
253 if (fifo_samples > 0) {
277 if (restore_matrix) {
289 if (fifo_samples > 0) {
303 if (compensation_distance) {
305 (int64_t)sample_delta / compensation_distance;
317 int *consumed,
int src_size,
int dst_size,
int update_ctx,
318 int nearest_neighbour)
330 if (nearest_neighbour) {
331 uint64_t index2 = ((uint64_t)index) << 32;
333 dst_size =
FFMIN(dst_size,
334 (src_size-1-index) * (int64_t)c->
src_incr /
338 for(dst_index = 0; dst_index < dst_size; dst_index++) {
343 dst_index = dst_size;
345 index += dst_index * dst_incr;
346 index += (frac + dst_index * (int64_t)dst_incr_frac) / c->
src_incr;
347 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->
src_incr;
349 for (dst_index = 0; dst_index < dst_size; dst_index++) {
358 frac += dst_incr_frac;
364 if (dst_index + 1 == compensation_distance) {
365 compensation_distance = 0;
377 if (compensation_distance) {
378 compensation_distance -= dst_index;
379 if (compensation_distance <= 0)
393 int ch, in_samples, in_leftover, consumed = 0, out_samples = 0;
407 }
else if (in_leftover <= c->final_padding_samples) {
425 memset(c->
buffer->
data[ch] + bps * i, 0, bps);
443 if (in_leftover > i) {
444 memcpy(c->
buffer->
data[ch] + bps * (in_leftover + i),
445 c->
buffer->
data[ch] + bps * (in_leftover - i - 1),
448 memset(c->
buffer->
data[ch] + bps * (in_leftover + i),
462 INT_MAX, 0, nearest_neighbour);
477 if (out_samples < 0) {
486 av_dlog(c->
avr,
"resampled %d in + %d leftover to %d out + %d leftover\n",
int initial_padding_filled
int initial_padding_samples
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVAudioResampleContext * avr
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
Audio buffer used for intermediate storage between conversion phases.
int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset, int nb_samples)
Add samples in AudioData to an AVAudioFifo.
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
static double bessel(double x)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
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
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int out_channels
number of output channels
int read_only
data is read-only
enum AVResampleFilterType filter_type
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
AudioMix * am
channel mixing context
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int channels
channel count
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_log(void *avcl, int level, const char *fmt,...)
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 ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples)
Read samples from an AVAudioFifo to AudioData.
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
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
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
void(* resample_one)(struct ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
int kaiser_beta
beta value for Kaiser window (only applicable if filter_type == AV_FILTER_TYPE_KAISER) ...
void(* set_filter)(void *filter, double *tab, int phase, int tap_count)
int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, int stride)
Set channel mixing matrix.
int in_sample_rate
input sample rate
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix, int stride)
Get the current channel mixing matrix.
AVAudioFifo * out_fifo
FIFO for output samples.
enum AVResampleFilterType filter_type
resampling filter type
ResampleContext * ff_audio_resample_init(AVAudioResampleContext *avr)
Allocate and initialize a ResampleContext.
#define AVRESAMPLE_MAX_CHANNELS
enum AVSampleFormat internal_sample_fmt
internal sample format
int force_resampling
force resampling
void(* resample_nearest)(void *dst0, int dst_index, const void *src0, unsigned int index)
Replacements for frequently missing libm functions.
#define AVERROR_BUG
Bug detected, please report the issue.
int filter_size
length of each FIR filter in the resampling filterbank relative to the cutoff frequency ...
int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
Resample audio data.
Blackman Nuttall Windowed Sinc.
static int build_filter(ResampleContext *c, double factor)
void ff_audio_resample_init_aarch64(ResampleContext *c, enum AVSampleFormat sample_fmt)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
enum AVSampleFormat out_sample_fmt
output sample format
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 compensation_distance
int out_sample_rate
output sample rate
void ff_audio_data_free(AudioData **a)
Free AudioData.
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
void ff_audio_resample_free(ResampleContext **c)
Free a ResampleContext.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
uint8_t * data[AVRESAMPLE_MAX_CHANNELS]
data plane pointers
static int resample(ResampleContext *c, void *dst, const void *src, int *consumed, int src_size, int dst_size, int update_ctx, int nearest_neighbour)