resample2.c File Reference

audio resampling More...

#include "avcodec.h"
#include "dsputil.h"

Go to the source code of this file.

Data Structures

struct  AVResampleContext

Macros

#define FILTER_SHIFT   15
#define FELEM   int16_t
#define FELEM2   int32_t
#define FELEML   int64_t
#define FELEM_MAX   INT16_MAX
#define FELEM_MIN   INT16_MIN
#define WINDOW_TYPE   9

Typedefs

typedef struct AVResampleContext AVResampleContext

Functions

static double bessel (double x)
 0th order modified bessel function of the first kind.
static int build_filter (FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type)
 Build a polyphase filterbank.
AVResampleContextav_resample_init (int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff)
 Initialize an audio resampler.
void av_resample_close (AVResampleContext *c)
void av_resample_compensate (AVResampleContext *c, int sample_delta, int compensation_distance)
 Compensate samplerate/timestamp drift.
int av_resample (AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx)
 Resample an array of samples using a previously configured context.

Detailed Description

audio resampling

Author
Michael Niedermayer micha.nosp@m.elni.nosp@m.@gmx..nosp@m.at

Definition in file resample2.c.

Macro Definition Documentation

#define FELEM   int16_t

Definition at line 34 of file resample2.c.

Referenced by av_resample(), and av_resample_init().

#define FELEM2   int32_t

Definition at line 35 of file resample2.c.

Referenced by av_resample().

#define FELEM_MAX   INT16_MAX

Definition at line 37 of file resample2.c.

Referenced by build_filter().

#define FELEM_MIN   INT16_MIN

Definition at line 38 of file resample2.c.

Referenced by build_filter().

#define FELEML   int64_t

Definition at line 36 of file resample2.c.

Referenced by av_resample().

#define FILTER_SHIFT   15

Definition at line 32 of file resample2.c.

Referenced by av_resample(), av_resample_init(), and build_filter().

#define WINDOW_TYPE   9

Definition at line 39 of file resample2.c.

Referenced by av_resample_init().

Typedef Documentation

Function Documentation

int av_resample ( struct AVResampleContext c,
short *  dst,
short *  src,
int *  consumed,
int  src_size,
int  dst_size,
int  update_ctx 
)

Resample an array of samples using a previously configured context.

Parameters
srcan array of unconsumed samples
consumedthe number of samples of src which have been consumed are returned here
src_sizethe number of unconsumed samples available
dst_sizethe amount of space in samples available in dst
update_ctxIf this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
Returns
the number of samples written in dst or -1 if an error occurred

Definition at line 232 of file resample2.c.

Referenced by audio_resample().

void av_resample_close ( AVResampleContext c)

Definition at line 221 of file resample2.c.

Referenced by audio_resample_close().

void av_resample_compensate ( struct AVResampleContext c,
int  sample_delta,
int  compensation_distance 
)

Compensate samplerate/timestamp drift.

The compensation is done by changing the resampler parameters, so no audible clicks or similar distortions occur

Parameters
compensation_distancedistance in output samples over which the compensation should be performed
sample_deltanumber of output samples which should be output less

example: av_resample_compensate(c, 10, 500) here instead of 510 samples only 500 samples would be output

note, due to rounding the actual compensation might be slightly different, especially if the compensation_distance is large and the in_rate used during init is small

Definition at line 226 of file resample2.c.

Referenced by av_resample(), and do_audio_out().

AVResampleContext* av_resample_init ( int  out_rate,
int  in_rate,
int  filter_length,
int  log2_phase_count,
int  linear,
double  cutoff 
)
read

Initialize an audio resampler.

Note, if either rate is not an integer then simply scale both rates up so they are.

Parameters
filter_lengthlength of each FIR filter in the filterbank relative to the cutoff freq
log2_phase_countlog2 of the number of entries in the polyphase filterbank
linearIf 1 then the used FIR filter will be linearly interpolated between the 2 closest, if 0 the closest will be used
cutoffcutoff frequency, 1.0 corresponds to half the output sampling rate

Definition at line 189 of file resample2.c.

Referenced by av_audio_resample_init().

static double bessel ( double  x)
static

0th order modified bessel function of the first kind.

Definition at line 77 of file resample2.c.

Referenced by build_filter(), and ff_kbd_window_init().

static int build_filter ( FELEM filter,
double  factor,
int  tap_count,
int  phase_count,
int  scale,
int  type 
)
static

Build a polyphase filterbank.

Parameters
factorresampling factor
scalewanted sum of coefficients for each filter
type0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16
Returns
0 on success, negative on error

Definition at line 99 of file resample2.c.

Referenced by av_resample_init().