FFmpeg
|
audio conversion More...
#include "libavutil/avstring.h"
#include "libavutil/avassert.h"
#include "libavutil/libm.h"
#include "libavutil/samplefmt.h"
#include "audioconvert.h"
Go to the source code of this file.
Macros | |
#define | CONV_FUNC_NAME(dst_fmt, src_fmt) conv_ ## src_fmt ## _to_ ## dst_fmt |
#define | CONV_FUNC(ofmt, otype, ifmt, expr) |
#define | FMT_PAIR_FUNC(out, in) [(out) + AV_SAMPLE_FMT_NB*(in)] = CONV_FUNC_NAME(out, in) |
Functions | |
CONV_FUNC (AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80U)<< 8) CONV_FUNC(AV_SAMPLE_FMT_S32 | |
if (off==len) | |
Variables | |
int32_t | |
AV_SAMPLE_FMT_U8 | |
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_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_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 |
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_FUN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SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_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 const uint8_t **in ch off *out | planar |
else | |
return | |
audio conversion
Definition in file audioconvert.c.
#define CONV_FUNC_NAME | ( | dst_fmt, | |
src_fmt | |||
) | conv_ ## src_fmt ## _to_ ## dst_fmt |
Definition at line 35 of file audioconvert.c.
#define CONV_FUNC | ( | ofmt, | |
otype, | |||
ifmt, | |||
expr | |||
) |
Definition at line 38 of file audioconvert.c.
#define FMT_PAIR_FUNC | ( | out, | |
in | |||
) | [(out) + AV_SAMPLE_FMT_NB*(in)] = CONV_FUNC_NAME(out, in) |
CONV_FUNC | ( | AV_SAMPLE_FMT_S16 | , |
int16_t | , | ||
AV_SAMPLE_FMT_U8 | , | ||
(*(const uint8_t *) pi-0x80U)<< | 8 | ||
) |
if | ( | off | = = len | ) |
Definition at line 232 of file audioconvert.c.
int32_t |
Definition at line 56 of file audioconvert.c.
AV_SAMPLE_FMT_U8 |
Definition at line 56 of file audioconvert.c.
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<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E_FMT_S32),FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64,AV_SAMPLE_FMT_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 const uint8_t** in ch ch |
Definition at line 56 of file audioconvert.c.
Referenced by aa_read_seek(), aac_encode_frame(), ac3_decode_frame(), acalc_magnitudes(), add_noise(), adjust_frame_information(), adpcm_analysis(), adpcm_decode_frame(), adpcm_encode_frame(), adx_decode(), adx_decode_frame(), adx_encode_frame(), aea_read_probe(), alac_decode_close(), alac_decode_frame(), alac_entropy_coder(), alac_linear_predictor(), alloc_buffers(), alloc_sample_buffer(), alloc_x96_sample_buffer(), allocate_buffers(), allocate_sample_buffers(), ape_decode_frame(), append_extra_bits(), apply_band_extension(), apply_channel_coupling(), apply_lpc(), apply_mdct(), apply_window_and_mdct(), asf_read_content_desc(), atrac1_decode_frame(), atrac3p_decode_init(), audiogen(), av_bprint_channel_layout(), av_dump_format(), av_frame_ref(), av_samples_fill_arrays(), avcodec_fill_audio_frame(), average_quantized_coeffs(), avresample_open(), avresample_set_channel_mapping(), bit_alloc(), bit_alloc_init(), bit_alloc_masking(), buf_set(), build_sb_samples_from_noise(), calc_channel_magnitudes(), calc_channel_phases(), calc_masking(), calc_predictor_params(), calc_transform_coeffs_cpl(), calculate_sign_huff(), cbr_bit_allocation(), celt_apply_preemph_filter(), celt_encode_frame(), celt_frame_mdct(), celt_frame_setup_input(), celt_gauge_psy_weight(), celt_quant_final(), celt_quant_fine(), channelmap_filter_frame(), check_append_extra_bits(), chs_assemble_freq_bands(), chs_assemble_msbs_lsbs(), chs_get_lsb_width(), combine_residual_frame(), compare_decoding_params(), compute_bit_allocation(), compute_chapters_end(), compute_exp_strategy(), config_input(), config_output(), convert_coeffs(), convert_pd2zp(), convert_pr2zp(), convert_samples(), convert_zp2tf(), convolve(), copy(), copy_input_samples(), copy_samples(), count_exponent_bits(), count_frame_bits(), count_mantissa_bits(), coupling_coordinates(), coupling_strategy(), crossover(), dec_bark_env(), decode(), decode_audio_block(), decode_audio_s16(), decode_block(), decode_channel(), decode_channel_residues(), decode_element(), decode_exp_vlc(), decode_frame(), decode_grid(), decode_lpc(), decode_part_stereo(), decode_residual_spectrum(), decode_str(), decode_transform_coeffs(), decode_transform_coeffs_ch(), decompose_zp2biquads(), depth_to_space(), deshake_transform_c(), do_imdct(), dpcm_decode_frame(), draw_curves(), draw_legend(), draw_response(), dsf_read_packet(), eightsvx_decode_frame(), encode_block(), encode_exp_vlc(), encode_exponents(), encode_frame(), encode_mb_internal(), encode_residual_ch(), erase_adpcm_history(), erase_x96_adpcm_history(), exp_quant_coarse(), extract_audio(), extract_exponents(), extract_line(), ff_aac_ltp_insert_new_frame(), ff_ac3_compute_coupling_strategy(), ff_ac3_encode_close(), ff_ac3_group_exponents(), ff_ac3_quantize_mantissas(), ff_adts_header_parse(), ff_audio_resample(), ff_boxblur_eval_filter_params(), ff_dca_core_filter_fixed(), ff_dca_lbr_flush(), ff_dca_lbr_parse(), ff_dither_alloc(), ff_dither_free(), ff_eac3_apply_spectral_extension(), ff_eac3_decode_transform_coeffs_aht_ch(), ff_eac3_get_frame_exp_strategy(), ff_eac3_output_frame_header(), ff_eac3_parse_header(), ff_eac3_set_cpl_states(), ff_mpc_dequantize_and_synth(), ff_opus_psy_init(), ff_psy_find_group(), ff_psy_preprocess(), ff_sbc_calculate_bits(), ff_sbr_apply(), fft_channel(), fill_coding_method_array(), fill_in_adpcm_bufer(), fill_tone_level_array(), filter(), filter_channel(), filter_frame(), filter_frame_fixed(), filter_frame_float(), filter_ts(), find_peaks(), fir_channel(), fix_coding_method_array(), force_lossy_output(), frame_configure_elements(), fsb_read_packet(), ftp_get_line(), generate_kernel(), genh_read_header(), genh_read_packet(), get(), get_asf_string(), get_audio_frame_duration(), get_nb_samples(), get_speaker_pos(), get_step_size(), http_get_line(), http_handshake(), idct_mb(), ifft_channel(), imc_decode_block(), imdct_and_window(), init_exp(), init_frame(), init_quantization_noise(), init_sample_buffers(), init_tone_level_dequantization(), inverse_channel_transform(), invert_initial_buffer(), join_config_output(), libopus_decode_init(), main(), map_prm_ch_to_spkr(), mcompand_channel(), mkv_write_tags(), mov_read_chapters(), move_audio(), mp3lame_encode_frame(), mp3lame_encode_init(), mp_decode_frame(), mp_decode_layer1(), mp_decode_layer2(), mp_decode_layer3(), mpc7_decode_frame(), mpc8_decode_frame(), mpc_synth(), mxf_utf16len(), nut_write_header(), on2avc_read_channel_data(), on2avc_reconstruct_channel_ext(), optimize_colors(), opus_encode_init(), output_audio_block(), output_frame(), parse_audio(), parse_ch(), parse_channel(), parse_coding_header(), parse_frame_data(), parse_grid_1_chunk(), parse_grid_2(), parse_grid_3(), parse_high_res_grid(), parse_lpc(), parse_subframe_audio(), parse_subframe_header(), parse_tonal(), parse_x96_coding_header(), parse_x96_frame_data(), parse_x96_subframe_audio(), parse_x96_subframe_header(), parse_xbr_subframe(), plot_channel(), plot_freq(), plot_freqs(), print_stats(), process_subpacket_9(), psy_3gpp_analyze(), push_single_pic(), put_primary_audio_header(), put_str16(), put_subframe(), put_subframe_samples(), qdm2_decode(), qdm2_fft_tone_synthesizer(), qdm2_synthesis_filter(), quantize_adpcm(), quantize_adpcm_subband(), quantize_pcm(), random_ts(), read16_fft_bin(), read8_fft_bin(), read_block_data(), read_channel_params(), read_custom_noise(), read_decoding_params(), read_fft_data(), read_header(), read_key(), read_map(), read_matrix_params(), read_noise_data(), read_restart_header(), reconstruct_frame(), remove_dithering(), remove_wasted_bits(), request_frame(), reset_block_bap(), revert_channel_correlation(), rsd_read_packet(), run_channel_fft(), sbc_analyze_audio(), sbc_calc_scalefactors(), sbc_decode_init(), sbc_pack_frame(), sbc_synthesize_audio(), sbc_synthesize_eight(), sbc_synthesize_four(), sbc_unpack_frame(), sbr_dequant(), scale_coefficients(), scale_magnitudes(), seek_chapter(), set(), set_bandwidth(), set_parameters(), shift(), shift_history(), spawn_empty_frame(), spx_coordinates(), spx_strategy(), step_collect_psy_metrics(), store_icy(), subband_bufer_alloc(), subband_transform(), swr_convert_internal(), swri_noise_shaping_TMPL(), synth_lpc(), synth_tones(), synth_window(), synthfilt_build_sb_samples(), transform_channel(), try_push_frame(), uninit(), update_frame_pool(), update_volume(), video_audio_display(), vorbis_decode_frame(), vorbis_parse_audio_packet(), vorbis_residue_decode_internal(), wma_decode_block(), wma_decode_frame(), write_block_data(), write_chapter(), write_char(), write_decoding_params(), write_frame(), write_restart_header(), write_subframes(), write_trailer(), and xwma_read_header().
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)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FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL,AV_SAMPLE_FMT_FLT),FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64,AV_SAMPLE_FMT_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 const uint8_t** in ch off* out planar |
Definition at line 56 of file audioconvert.c.
Referenced by av_get_packed_sample_fmt(), av_get_planar_sample_fmt(), av_samples_copy(), av_samples_fill_arrays(), av_samples_get_buffer_size(), av_samples_set_silence(), avcodec_fill_audio_frame(), avisynth_create_stream_video(), buffer_offset(), config_input(), config_output(), ff_frame_pool_audio_init(), ff_framequeue_skip_samples(), filter_frame(), flac_set_bps(), frame_copy_audio(), get_audio_buffer(), process_output(), and update_frame_pool().
else |
Definition at line 228 of file audioconvert.c.
return |
Definition at line 246 of file audioconvert.c.