35 #if FF_API_AUDIO_CONVERT
37 struct AVAudioConvert {
38 int in_channels, out_channels;
42 AVAudioConvert *av_audio_convert_alloc(
enum AVSampleFormat out_fmt,
int out_channels,
44 const float *matrix,
int flags)
47 if (in_channels!=out_channels)
52 ctx->in_channels = in_channels;
53 ctx->out_channels = out_channels;
58 void av_audio_convert_free(AVAudioConvert *ctx)
63 int av_audio_convert(AVAudioConvert *ctx,
64 void *
const out[6],
const int out_stride[6],
65 const void *
const in[6],
const int in_stride[6],
int len)
71 for(ch=0; ch<ctx->out_channels; ch++){
72 const int is= in_stride[ch];
73 const int os= out_stride[ch];
80 #define CONV(ofmt, otype, ifmt, expr)\
81 if(ctx->fmt_pair == ofmt + AV_SAMPLE_FMT_NB*ifmt){\
83 *(otype*)po = expr; pi += is; po += os;\
95 else CONV(AV_SAMPLE_FMT_U8 ,
uint8_t, AV_SAMPLE_FMT_S16, (*(const int16_t*)pi>>8) + 0x80)
96 else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi)
97 else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi<<16)
98 else CONV(AV_SAMPLE_FMT_FLT,
float , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15)))
99 else CONV(AV_SAMPLE_FMT_DBL,
double , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15)))
100 else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S32, (*(const int32_t*)pi>>24) + 0x80)
101 else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi>>16)
102 else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi)
103 else CONV(AV_SAMPLE_FMT_FLT,
float , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1
U<<31)))
104 else CONV(AV_SAMPLE_FMT_DBL,
double , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1
U<<31)))
105 else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(
lrintf(*(const
float*)pi * (1<<7)) + 0x80))
106 else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(
lrintf(*(const
float*)pi * (1<<15))))
107 else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const
float*)pi * (1
U<<31))))
108 else CONV(AV_SAMPLE_FMT_FLT,
float , AV_SAMPLE_FMT_FLT, *(const
float*)pi)
109 else CONV(AV_SAMPLE_FMT_DBL,
double , AV_SAMPLE_FMT_FLT, *(const
float*)pi)
110 else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(
lrint(*(const
double*)pi * (1<<7)) + 0x80))
111 else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(
lrint(*(const
double*)pi * (1<<15))))
112 else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const
double*)pi * (1
U<<31))))
113 else CONV(AV_SAMPLE_FMT_FLT,
float , AV_SAMPLE_FMT_DBL, *(const
double*)pi)
114 else CONV(AV_SAMPLE_FMT_DBL,
double , AV_SAMPLE_FMT_DBL, *(const
double*)pi)