22 #include "libavutil/common.h"
24 #include "libavutil/log.h"
48 int dst_index,
const void *src0,
int src_size,
54 #define CONFIG_RESAMPLE_DBL
56 #undef CONFIG_RESAMPLE_DBL
59 #define CONFIG_RESAMPLE_FLT
61 #undef CONFIG_RESAMPLE_FLT
64 #define CONFIG_RESAMPLE_S32
66 #undef CONFIG_RESAMPLE_S32
81 for (i = 1; v != lastv; i++) {
97 const int center = (tap_count - 1) / 2;
99 tab =
av_malloc(tap_count *
sizeof(*tab));
106 for (ph = 0; ph < phase_count; ph++) {
108 for (i = 0; i < tap_count; i++) {
109 x =
M_PI * ((double)(i - center) - (double)ph / phase_count) *
factor;
114 const float d = -0.5;
115 x = fabs(((
double)(i - center) - (
double)ph / phase_count) * factor);
116 if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);
117 else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);
121 w = 2.0 * x / (factor * tap_count) +
M_PI;
122 y *= 0.3635819 - 0.4891775 * cos( w) +
123 0.1365995 * cos(2 * w) -
124 0.0106411 * cos(3 * w);
127 w = 2.0 * x / (factor * tap_count *
M_PI);
136 for (i = 0; i < tap_count; i++)
137 tab[i] = tab[i] / norm;
211 in_rate * (int64_t)phase_count, INT32_MAX / 2))
254 if (compensation_distance < 0)
256 if (!compensation_distance && sample_delta)
260 #if FF_API_RESAMPLE_CLOSE_OPEN
264 int restore_matrix = 0;
269 if (fifo_samples > 0) {
293 if (restore_matrix) {
305 if (fifo_samples > 0) {
319 if (compensation_distance) {
321 (int64_t)sample_delta / compensation_distance;
333 int *consumed,
int src_size,
int dst_size,
int update_ctx)
347 int64_t index2 = ((int64_t)index) << 32;
349 dst_size =
FFMIN(dst_size,
350 (src_size-1-index) * (int64_t)c->
src_incr /
354 for(dst_index = 0; dst_index < dst_size; dst_index++) {
355 c->
resample_one(c, 1, dst, dst_index, src, 0, index2 >> 32, 0);
359 dst_index = dst_size;
362 index += (frac + dst_index * (int64_t)dst_incr_frac) / c->
src_incr;
363 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->
src_incr;
365 for (dst_index = 0; dst_index < dst_size; dst_index++) {
369 -sample_index >= src_size)
373 c->
resample_one(c, 0, dst, dst_index, src, src_size, index, frac);
375 frac += dst_incr_frac;
381 if (dst_index + 1 == compensation_distance) {
382 compensation_distance = 0;
395 if (compensation_distance) {
396 compensation_distance -= dst_index;
397 if (compensation_distance <= 0)
411 int ch, in_samples, in_leftover, consumed = 0, out_samples = 0;
422 }
else if (!in_leftover) {
448 if (out_samples < 0) {
456 av_dlog(c->
avr,
"resampled %d in + %d leftover to %d out + %d leftover\n",
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
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.
Audio buffer used for intermediate storage between conversion phases.
void(* resample_one)(struct ResampleContext *c, int no_filter, void *dst0, int dst_index, const void *src0, int src_size, int index, int frac)
void(* set_filter)(void *filter, double *tab, int phase, int tap_count)
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
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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 *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
AVAudioResampleContext * avr
int out_channels
number of output channels
int read_only
data is read-only
int compensation_distance
enum AVResampleFilterType filter_type
static int resample(ResampleContext *c, void *dst, const void *src, int *consumed, int src_size, int dst_size, int update_ctx)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
AudioMix * am
channel mixing context
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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
AVResampleFilterType
Resampling Filter Types.
int channels
channel count
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples)
Read samples from an AVAudioFifo to AudioData.
static int build_filter(ResampleContext *c)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
ResampleContext * resample
resampling context
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 * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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 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.
void ff_audio_resample_free(ResampleContext **c)
Free a ResampleContext.
typedef void(RENAME(mix_any_func_type))
AVAudioFifo * out_fifo
FIFO for output samples.
uint8_t * data[AVRESAMPLE_MAX_CHANNELS]
data plane pointers
enum AVResampleFilterType filter_type
resampling filter type
#define AVRESAMPLE_MAX_CHANNELS
enum AVSampleFormat internal_sample_fmt
internal sample format
int force_resampling
force resampling
Replacements for frequently missing libm functions.
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]
enum AVSampleFormat out_sample_fmt
output sample format
int resample_channels
number of channels used for resampling
int resample_needed
resampling is needed
int allocated_samples
number of samples the buffer can hold
static struct twinvq_data tab
int out_sample_rate
output sample rate
void ff_audio_data_free(AudioData **a)
Free AudioData.
static double bessel(double x)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...