38     return 2.0 * (
av_lfg_get(lfg) / (double)UINT_MAX) - 1.0;
 
   41 #define PUT_FUNC(name, fmt, type, expr)                                     \ 
   42 static void put_sample_ ## name(void **data, enum AVSampleFormat sample_fmt,\ 
   43                                 int channels, int sample, int ch,           \ 
   47     type **out = (type **)data;                                             \ 
   48     if (av_sample_fmt_is_planar(sample_fmt))                                \ 
   49         out[ch][sample] = v;                                                \ 
   51         out[0][sample * channels + ch] = v;                                 \ 
   61                        int channels, 
int sample, 
int ch, 
double v_dbl)
 
   65         put_sample_u8(data, sample_fmt, channels, sample, ch, v_dbl);
 
   67     case AV_SAMPLE_FMT_S16:
 
   68         put_sample_s16(data, sample_fmt, channels, sample, ch, v_dbl);
 
   70     case AV_SAMPLE_FMT_S32:
 
   71         put_sample_s32(data, sample_fmt, channels, sample, ch, v_dbl);
 
   73     case AV_SAMPLE_FMT_FLT:
 
   74         put_sample_flt(data, sample_fmt, channels, sample, ch, v_dbl);
 
   76     case AV_SAMPLE_FMT_DBL:
 
   77         put_sample_dbl(data, sample_fmt, channels, sample, ch, v_dbl);
 
   91 #define PUT_SAMPLE put_sample(data, sample_fmt, channels, k, ch, v); 
   97     for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
 
   99         for (ch = 0; ch < channels; ch++)
 
  101         a += 
M_PI * 1000.0 * 2.0 / sample_rate;
 
  106     for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
 
  108         for (ch = 0; ch < channels; ch++)
 
  110         f  = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
 
  115     for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
 
  117         for (ch = 0; ch < channels; ch++)
 
  122     for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
 
  124         for (ch = 0; ch < channels; ch++)
 
  129     for (ch = 0; ch < channels; ch++) {
 
  134     for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
 
  135         for (ch = 0; ch < channels; ch++) {
 
  136             v = sin(taba[ch]) * 0.30;
 
  146     for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
 
  147         for (ch = 0; ch < channels; ch++) {
 
  148             double amp = (1.0 + sin(ampa)) * 0.15;
 
  189 int main(
int argc, 
char **argv)
 
  196     unsigned int in_buf_size;
 
  197     unsigned int out_buf_size;
 
  202     uint64_t in_ch_layout;
 
  206     uint64_t out_ch_layout;
 
  210     int num_formats, num_rates, num_layouts;
 
  211     int i, j, k, l, m, 
n;
 
  219                    "[<num sample rates> [<num channel layouts>]]]\n" 
  220                    "Default is 2 2 2\n");
 
  223         num_formats = strtol(argv[1], 
NULL, 0);
 
  227         num_rates = strtol(argv[2], 
NULL, 0);
 
  231         num_layouts = strtol(argv[3], 
NULL, 0);
 
  241     out_buf_size = in_buf_size;
 
  257     for (i = 0; i < num_formats; i++) {
 
  259         for (k = 0; k < num_layouts; k++) {
 
  260             in_ch_layout = layouts[k];
 
  262             for (m = 0; m < num_rates; m++) {
 
  266                                              in_channels, in_rate * 6,
 
  272                 audiogen(&rnd, (
void **)in_data, in_fmt, in_channels, in_rate, in_rate * 6);
 
  274                 for (j = 0; j < num_formats; j++) {
 
  275                     out_fmt = formats[j];
 
  276                     for (l = 0; l < num_layouts; l++) {
 
  277                         out_ch_layout = layouts[l];
 
  279                         for (n = 0; n < num_rates; n++) {
 
  284                                    in_channels, out_channels, in_rate, out_rate);
 
  287                                                          out_buf, out_channels,
 
  288                                                          out_rate * 6, out_fmt, 0);
 
  310                                                          in_data,  in_linesize,  in_rate * 6);
 
#define AV_CH_LAYOUT_7POINT1
 
ptrdiff_t const GLvoid * data
 
int avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t *const *input, int in_plane_size, int in_samples)
Convert input samples and write them to the output FIFO. 
 
Memory handling functions. 
 
void av_log_set_level(int level)
Set the log level. 
 
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare. 
 
#define AV_CH_LAYOUT_STEREO
 
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values. 
 
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout. 
 
static av_cold int end(AVCodecContext *avctx)
 
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_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_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
 
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext. 
 
#define AV_CH_LAYOUT_5POINT1
 
static double dbl_rand(AVLFG *lfg)
 
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered. 
 
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers. 
 
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
 
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. 
 
static const uint64_t layouts[]
 
#define FF_ARRAY_ELEMS(a)
 
int main(int argc, char **argv)
 
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer. 
 
int avresample_available(AVAudioResampleContext *avr)
Return the number of available samples in the output FIFO. 
 
#define AV_LOG_INFO
Standard information. 
 
AVSampleFormat
Audio sample formats. 
 
#define AVRESAMPLE_MAX_CHANNELS
 
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG. 
 
Replacements for frequently missing libm functions. 
 
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters. 
 
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
 
static void audiogen(AVLFG *rnd, void **data, enum AVSampleFormat sample_fmt, int channels, int sample_rate, int nb_samples)
 
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf. 
 
AVAudioResampleContext * avresample_alloc_context(void)
Allocate AVAudioResampleContext and set options. 
 
common internal and external API header 
 
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format. 
 
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill plane data pointers and linesize for samples with sample format sample_fmt. 
 
#define AV_CH_LAYOUT_MONO
 
#define PUT_FUNC(name, fmt, type, expr)
 
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.