44 int len,
int channels);
73 const char *descr,
void *conv)
85 if (ptr_align == 1 && samples_align == 1) {
96 (!channels || ac->
channels == channels)) {
101 if (ptr_align == 1 && samples_align == 1) {
112 (!channels || ac->
channels == channels)) {
117 if (ptr_align == 1 && samples_align == 1) {
134 #define CONV_FUNC_NAME(dst_fmt, src_fmt) conv_ ## src_fmt ## _to_ ## dst_fmt
136 #define CONV_LOOP(otype, expr) \
138 *(otype *)po = expr; \
141 } while (po < end); \
143 #define CONV_FUNC_FLAT(ofmt, otype, ifmt, itype, expr) \
144 static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t *out, const uint8_t *in, \
147 int is = sizeof(itype); \
148 int os = sizeof(otype); \
149 const uint8_t *pi = in; \
151 uint8_t *end = out + os * len; \
152 CONV_LOOP(otype, expr) \
155 #define CONV_FUNC_INTERLEAVE(ofmt, otype, ifmt, itype, expr) \
156 static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t *out, const uint8_t **in, \
157 int len, int channels) \
160 int out_bps = sizeof(otype); \
161 int is = sizeof(itype); \
162 int os = channels * out_bps; \
163 for (ch = 0; ch < channels; ch++) { \
164 const uint8_t *pi = in[ch]; \
165 uint8_t *po = out + ch * out_bps; \
166 uint8_t *end = po + os * len; \
167 CONV_LOOP(otype, expr) \
171 #define CONV_FUNC_DEINTERLEAVE(ofmt, otype, ifmt, itype, expr) \
172 static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t **out, const uint8_t *in, \
173 int len, int channels) \
176 int in_bps = sizeof(itype); \
177 int is = channels * in_bps; \
178 int os = sizeof(otype); \
179 for (ch = 0; ch < channels; ch++) { \
180 const uint8_t *pi = in + ch * in_bps; \
181 uint8_t *po = out[ch]; \
182 uint8_t *end = po + os * len; \
183 CONV_LOOP(otype, expr) \
187 #define CONV_FUNC_GROUP(ofmt, otype, ifmt, itype, expr) \
188 CONV_FUNC_FLAT( ofmt, otype, ifmt, itype, expr) \
189 CONV_FUNC_INTERLEAVE( ofmt, otype, ifmt ## P, itype, expr) \
190 CONV_FUNC_DEINTERLEAVE(ofmt ## P, otype, ifmt, itype, expr)
197 CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t, (*(const int16_t *)pi >> 8) + 0x80)
198 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi)
199 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi << 16)
200 CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT,
float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi * (1.0f / (1 << 15)))
201 CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL,
double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *)pi * (1.0 / (1 << 15)))
202 CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t, (*(const int32_t *)pi >> 24) + 0x80)
203 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi >> 16)
204 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi)
205 CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT,
float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi * (1.0f / (1
U << 31)))
206 CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL,
double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *)pi * (1.0 / (1
U << 31)))
207 CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT,
float, av_clip_uint8(
lrintf(*(const
float *)pi * (1 << 7)) + 0x80))
208 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT,
float, av_clip_int16(
lrintf(*(const
float *)pi * (1 << 15))))
209 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT,
float, av_clipl_int32(
llrintf(*(const
float *)pi * (1
U << 31))))
210 CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT,
float, AV_SAMPLE_FMT_FLT,
float, *(const
float *)pi)
211 CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL,
double, AV_SAMPLE_FMT_FLT,
float, *(const
float *)pi)
212 CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL,
double, av_clip_uint8(
lrint(*(const
double *)pi * (1 << 7)) + 0x80))
213 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL,
double, av_clip_int16(
lrint(*(const
double *)pi * (1 << 15))))
214 CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL,
double, av_clipl_int32(
llrint(*(const
double *)pi * (1
U << 31))))
215 CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT,
float, AV_SAMPLE_FMT_DBL,
double, *(const
double *)pi)
216 CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL,
double, AV_SAMPLE_FMT_DBL,
double, *(const
double *)pi)
218 #define SET_CONV_FUNC_GROUP(ofmt, ifmt) \
219 ff_audio_convert_set_func(ac, ofmt, ifmt, 0, 1, 1, "C", CONV_FUNC_NAME(ofmt, ifmt)); \
220 ff_audio_convert_set_func(ac, ofmt ## P, ifmt, 0, 1, 1, "C", CONV_FUNC_NAME(ofmt ## P, ifmt)); \
221 ff_audio_convert_set_func(ac, ofmt, ifmt ## P, 0, 1, 1, "C", CONV_FUNC_NAME(ofmt, ifmt ## P));
263 int channels,
int sample_rate)
266 int in_planar, out_planar;
291 if (in_planar == out_planar) {
294 }
else if (in_planar)
299 set_generic_function(ac);
316 av_dlog(ac->
avr,
"%d samples - audio_convert: %s to %s (dithered)\n",
329 if (!(ptr_align % ac->
ptr_align) && samples_align >= aligned_len) {
334 av_dlog(ac->
avr,
"%d samples - audio_convert: %s to %s (%s)\n", len,
345 for (p = 0; p < ac->
planes; p++)
348 for (p = 0; p < ac->
planes; p++)
AVAudioResampleContext * avr
Audio buffer used for intermediate storage between conversion phases.
conv_func_deinterleave * conv_deinterleave
memory handling functions
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
Convert audio data from one sample format to another.
void( conv_func_interleave)(uint8_t *out, uint8_t *const *in, int len, int channels)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
DitherContext * ff_dither_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate)
Allocate and initialize a DitherContext.
void ff_audio_convert_init_x86(AudioConvert *ac)
int nb_samples
current number of samples
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
conv_func_interleave * conv_interleave
enum AVResampleDitherMethod dither_method
dither method
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
av_cold void ff_audio_convert_init_arm(AudioConvert *ac)
void( conv_func_flat)(uint8_t *out, const uint8_t *in, int len)
int channels
channel count
void av_log(void *avcl, int level, const char *fmt,...)
void ff_audio_convert_free(AudioConvert **ac)
Free AudioConvert.
void( conv_func_deinterleave)(uint8_t **out, const uint8_t *in, int len, int channels)
int is_planar
sample format is planar
#define SET_CONV_FUNC_GROUP(ofmt, ifmt)
conv_func_flat * conv_flat
int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src)
Convert audio sample format with dithering.
void ff_dither_free(DitherContext **cp)
Free a DitherContext.
static av_always_inline av_const long int lrintf(float x)
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
#define CONV_FUNC_GROUP(ofmt, otype, ifmt, itype, expr)
conv_func_interleave * conv_interleave_generic
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.
AudioConvert * ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate)
Allocate and initialize AudioConvert context for sample format conversion.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
Replacements for frequently missing libm functions.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
static av_always_inline av_const long int lrint(double x)
conv_func_flat * conv_flat_generic
int samples_align
allocated samples alignment
const char * func_descr_generic
common internal and external API header
AVSampleFormat
Audio Sample Formats.
enum ConvFuncType func_type
enum AVSampleFormat out_fmt
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)
Set conversion function if the parameters match.
enum AVSampleFormat in_fmt
int ptr_align
minimum data pointer alignment
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
uint8_t * data[AVRESAMPLE_MAX_CHANNELS]
data plane pointers