47 int dst_index,
const void *src0,
int src_size,
53 #define CONFIG_RESAMPLE_DBL
55 #undef CONFIG_RESAMPLE_DBL
58 #define CONFIG_RESAMPLE_FLT
60 #undef CONFIG_RESAMPLE_FLT
63 #define CONFIG_RESAMPLE_S32
65 #undef CONFIG_RESAMPLE_S32
80 for (i = 1; v != lastv; i++) {
96 const int center = (tap_count - 1) / 2;
98 tab =
av_malloc(tap_count *
sizeof(*tab));
105 for (ph = 0; ph < phase_count; ph++) {
107 for (i = 0; i < tap_count; i++) {
108 x = M_PI * ((double)(i - center) - (double)ph / phase_count) *
factor;
113 const float d = -0.5;
114 x = fabs(((
double)(i - center) - (
double)ph / phase_count) * factor);
115 if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);
116 else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);
120 w = 2.0 * x / (factor * tap_count) + M_PI;
121 y *= 0.3635819 - 0.4891775 * cos( w) +
122 0.1365995 * cos(2 * w) -
123 0.0106411 * cos(3 * w);
126 w = 2.0 * x / (factor * tap_count * M_PI);
135 for (i = 0; i < tap_count; i++)
136 tab[i] = tab[i] / norm;
210 in_rate * (int64_t)phase_count, INT32_MAX / 2))
253 if (compensation_distance < 0)
255 if (!compensation_distance && sample_delta)
259 #if FF_API_RESAMPLE_CLOSE_OPEN
263 int restore_matrix = 0;
268 if (fifo_samples > 0) {
292 if (restore_matrix) {
304 if (fifo_samples > 0) {
318 if (compensation_distance) {
320 (int64_t)sample_delta / compensation_distance;
332 int *consumed,
int src_size,
int dst_size,
int update_ctx)
346 int64_t index2 = ((int64_t)index) << 32;
348 dst_size =
FFMIN(dst_size,
349 (src_size-1-index) * (int64_t)c->
src_incr /
353 for(dst_index = 0; dst_index < dst_size; dst_index++) {
354 c->
resample_one(c, 1, dst, dst_index, src, 0, index2 >> 32, 0);
358 dst_index = dst_size;
361 index += (frac + dst_index * (int64_t)dst_incr_frac) / c->
src_incr;
362 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->
src_incr;
364 for (dst_index = 0; dst_index < dst_size; dst_index++) {
368 -sample_index >= src_size)
372 c->
resample_one(c, 0, dst, dst_index, src, src_size, index, frac);
374 frac += dst_incr_frac;
380 if (dst_index + 1 == compensation_distance) {
381 compensation_distance = 0;
394 if (compensation_distance) {
395 compensation_distance -= dst_index;
396 if (compensation_distance <= 0)
410 int ch, in_samples, in_leftover, consumed = 0, out_samples = 0;
421 }
else if (!in_leftover) {
447 if (out_samples < 0) {
455 av_dlog(c->
avr,
"resampled %d in + %d leftover to %d out + %d leftover\n",
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.
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
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
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.
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
void av_log(void *avcl, int level, const char *fmt,...)
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 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) ...
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 avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, int stride)
Set channel mixing matrix.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
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.
AVAudioFifo * out_fifo
FIFO for output samples.
enum AVResampleFilterType filter_type
resampling filter type
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
#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.
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 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.
static double bessel(double x)
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
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