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))
234 int compensation_distance)
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;
288 index += dst_index * dst_incr;
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 avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, int compensation_distance)
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
Audio buffer used for intermediate storage between conversion phases.
int avresample_get_delay(AVAudioResampleContext *avr)
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_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static __device__ float ceil(float a)
static void error(const char *err)
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.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int read_only
data is read-only
int compensation_distance
enum AVResampleFilterType filter_type
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
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.
static __device__ float fabs(float a)
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.
AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL
Blackman Nuttall Windowed Sinc.
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) ...
void(* set_filter)(void *filter, double *tab, int phase, int tap_count)
int in_sample_rate
input sample rate
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
void(* resample_nearest)(void *dst0, int dst_index, const void *src0, unsigned int index)
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 ...
AV_RESAMPLE_FILTER_TYPE_CUBIC
Cubic.
static const int factor[16]
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
void(* resample_one)(struct ResampleContext *c, void *dst0, int dst_index, const void *src0, unsigned int index, int frac)
int final_padding_samples
int allocated_samples
number of samples the buffer can hold
AV_RESAMPLE_FILTER_TYPE_KAISER
Kaiser Windowed Sinc.
static const struct twinvq_data tab
int out_sample_rate
output sample rate
void ff_audio_data_free(AudioData **a)
Free AudioData.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
static double bessel(double x)
av_cold void ff_audio_resample_init_aarch64(ResampleContext *c, enum AVSampleFormat sample_fmt)