c8af852b |
int channels;
int planes;
int ptr_align;
int samples_align;
int has_optimized_func;
const char *func_descr;
const char *func_descr_generic;
enum ConvFuncType func_type;
conv_func_flat *conv_flat;
conv_func_flat *conv_flat_generic;
conv_func_interleave *conv_interleave;
conv_func_interleave *conv_interleave_generic;
conv_func_deinterleave *conv_deinterleave;
conv_func_deinterleave *conv_deinterleave_generic;
};
void ff_audio_convert_set_func(AudioConvert *ac, enum AVSampleFormat out_fmt,
enum AVSampleFormat in_fmt, int channels,
int ptr_align, int samples_align,
const char *descr, void *conv)
{
int found = 0;
switch (ac->func_type) {
case CONV_FUNC_TYPE_FLAT:
if (av_get_packed_sample_fmt(ac->in_fmt) == in_fmt &&
av_get_packed_sample_fmt(ac->out_fmt) == out_fmt) {
ac->conv_flat = conv;
ac->func_descr = descr;
ac->ptr_align = ptr_align;
ac->samples_align = samples_align;
if (ptr_align == 1 && samples_align == 1) {
ac->conv_flat_generic = conv;
ac->func_descr_generic = descr;
} else {
ac->has_optimized_func = 1;
}
found = 1;
}
break;
case CONV_FUNC_TYPE_INTERLEAVE:
if (ac->in_fmt == in_fmt && ac->out_fmt == out_fmt &&
(!channels || ac->channels == channels)) {
ac->conv_interleave = conv;
ac->func_descr = descr;
ac->ptr_align = ptr_align;
ac->samples_align = samples_align;
if (ptr_align == 1 && samples_align == 1) {
ac->conv_interleave_generic = conv;
ac->func_descr_generic = descr;
} else {
ac->has_optimized_func = 1;
}
found = 1;
}
break;
case CONV_FUNC_TYPE_DEINTERLEAVE:
if (ac->in_fmt == in_fmt && ac->out_fmt == out_fmt &&
(!channels || ac->channels == channels)) {
ac->conv_deinterleave = conv;
ac->func_descr = descr;
ac->ptr_align = ptr_align;
ac->samples_align = samples_align;
if (ptr_align == 1 && samples_align == 1) {
ac->conv_deinterleave_generic = conv;
ac->func_descr_generic = descr;
} else {
ac->has_optimized_func = 1;
}
found = 1;
}
break;
}
if (found) {
av_log(ac->avr, AV_LOG_DEBUG, "audio_convert: found function: %-4s "
"to %-4s (%s)\n", av_get_sample_fmt_name(ac->in_fmt),
av_get_sample_fmt_name(ac->out_fmt), descr);
}
}
#define CONV_FUNC_NAME(dst_fmt, src_fmt) conv_ ## src_fmt ## _to_ ## dst_fmt
#define CONV_LOOP(otype, expr) \
do { \
*(otype *)po = expr; \
pi += is; \
po += os; \
} while (po < end); \
#define CONV_FUNC_FLAT(ofmt, otype, ifmt, itype, expr) \
static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t *out, const uint8_t *in, \
int len) \
{ \
int is = sizeof(itype); \
int os = sizeof(otype); \
const uint8_t *pi = in; \
uint8_t *po = out; \
uint8_t *end = out + os * len; \
CONV_LOOP(otype, expr) \
}
#define CONV_FUNC_INTERLEAVE(ofmt, otype, ifmt, itype, expr) \
static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t *out, const uint8_t **in, \
int len, int channels) \
{ \
int ch; \
int out_bps = sizeof(otype); \
int is = sizeof(itype); \
int os = channels * out_bps; \
for (ch = 0; ch < channels; ch++) { \
const uint8_t *pi = in[ch]; \
uint8_t *po = out + ch * out_bps; \
uint8_t *end = po + os * len; \
CONV_LOOP(otype, expr) \
} \
}
#define CONV_FUNC_DEINTERLEAVE(ofmt, otype, ifmt, itype, expr) \
static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t **out, const uint8_t *in, \
int len, int channels) \
{ \
int ch; \
int in_bps = sizeof(itype); \
int is = channels * in_bps; \
int os = sizeof(otype); \
for (ch = 0; ch < channels; ch++) { \
const uint8_t *pi = in + ch * in_bps; \
uint8_t *po = out[ch]; \
uint8_t *end = po + os * len; \
CONV_LOOP(otype, expr) \
} \
}
#define CONV_FUNC_GROUP(ofmt, otype, ifmt, itype, expr) \
CONV_FUNC_FLAT( ofmt, otype, ifmt, itype, expr) \
CONV_FUNC_INTERLEAVE( ofmt, otype, ifmt ## P, itype, expr) \
CONV_FUNC_DEINTERLEAVE(ofmt ## P, otype, ifmt, itype, expr)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_U8, uint8_t, *(const uint8_t *)pi)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8, uint8_t, (*(const uint8_t *)pi - 0x80) << 8)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_U8, uint8_t, (*(const uint8_t *)pi - 0x80) << 24)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t, (*(const uint8_t *)pi - 0x80) * (1.0f / (1 << 7)))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t, (*(const uint8_t *)pi - 0x80) * (1.0 / (1 << 7)))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t, (*(const int16_t *)pi >> 8) + 0x80)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi << 16)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi * (1.0f / (1 << 15)))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi * (1.0 / (1 << 15)))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t, (*(const int32_t *)pi >> 24) + 0x80)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi >> 16)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi * (1.0f / (1U << 31)))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi * (1.0 / (1U << 31)))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8( lrintf(*(const float *)pi * (1 << 7)) + 0x80))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16( lrintf(*(const float *)pi * (1 << 15))))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *)pi * (1U << 31))))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_FLT, float, *(const float *)pi)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_FLT, float, *(const float *)pi)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8( lrint(*(const double *)pi * (1 << 7)) + 0x80))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16( lrint(*(const double *)pi * (1 << 15))))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *)pi * (1U << 31))))
CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_DBL, double, *(const double *)pi)
CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_DBL, double, *(const double *)pi)
#define SET_CONV_FUNC_GROUP(ofmt, ifmt) \
ff_audio_convert_set_func(ac, ofmt, ifmt, 0, 1, 1, "C", CONV_FUNC_NAME(ofmt, ifmt)); \
ff_audio_convert_set_func(ac, ofmt ## P, ifmt, 0, 1, 1, "C", CONV_FUNC_NAME(ofmt ## P, ifmt)); \
ff_audio_convert_set_func(ac, ofmt, ifmt ## P, 0, 1, 1, "C", CONV_FUNC_NAME(ofmt, ifmt ## P));
static void set_generic_function(AudioConvert *ac)
{
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL)
SET_CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL)
}
|