25 #define FFT_FIXED_32 1
44 #define MAX_CHANNELS 6
45 #define DCA_MAX_FRAME_SIZE 16384
46 #define DCA_HEADER_SIZE 13
47 #define DCA_LFE_SAMPLES 8
49 #define DCAENC_SUBBANDS 32
51 #define SUBSUBFRAMES 2
52 #define SUBBAND_SAMPLES (SUBFRAMES * SUBSUBFRAMES * 8)
55 #define COS_T(x) (c->cos_table[(x) & 2047])
115 double f1 = f / 1000;
117 return -3.64 * pow(f1, -0.8)
118 + 6.8 *
exp(-0.6 * (f1 - 3.4) * (f1 - 3.4))
119 - 6.0 *
exp(-0.15 * (f1 - 8.7) * (f1 - 8.7))
120 - 0.0006 * (f1 * f1) * (f1 * f1);
125 double h = (f -
fc[i]) /
erb[i];
129 return 20 * log10(h);
166 int i, j, k, min_frame_bits;
185 "encoder will guess the layout, but it "
186 "might be incorrect.\n");
221 for (i = 0; i < 9; i++) {
252 for (i = 1; i < 512; i++) {
259 for (i = 0; i < 2048; i++)
262 for (k = 0; k < 32; k++) {
263 for (j = 0; j < 8; j++) {
269 for (i = 0; i < 512; i++) {
274 for (i = 0; i < 9; i++) {
275 for (j = 0; j <
AUBANDS; j++) {
276 for (k = 0; k < 256; k++) {
284 for (i = 0; i < 256; i++) {
285 double add = 1 +
ff_exp10(-0.01 * i);
288 for (j = 0; j < 8; j++) {
290 for (i = 0; i < 512; i++) {
292 accum += reconst * cos(2 *
M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
296 for (j = 0; j < 8; j++) {
298 for (i = 0; i < 512; i++) {
300 accum += reconst * cos(2 *
M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
320 int ch, subs, i, k, j;
336 memset(accum, 0, 64 *
sizeof(
int32_t));
338 for (k = 0, i = hist_start, j = 0;
339 i < 512; k = (k + 1) & 63, i++, j++)
341 for (i = 0; i < hist_start; k = (k + 1) & 63, i++, j++)
344 for (k = 16; k < 32; k++)
345 accum[k] = accum[k] - accum[31 - k];
346 for (k = 32; k < 48; k++)
347 accum[k] = accum[k] + accum[95 - k];
349 for (band = 0; band < 32; band++) {
351 for (i = 16; i < 48; i++) {
352 int s = (2 * band + 1) * (2 * (i + 16) + 1);
356 c->
subband[
ch][band][subs] = ((band + 1) & 2) ? -resp : resp;
360 for (i = 0; i < 32; i++)
361 hist[i + hist_start] = input[(subs * 32 + i) * c->
channels + chi];
363 hist_start = (hist_start + 32) & 511;
383 for (i = hist_start, j = 0; i < 512; i++, j++)
385 for (i = 0; i < hist_start; i++, j++)
391 for (i = 0; i < 64; i++)
392 hist[i + hist_start] = input[(lfes * 64 + i) * c->
channels + lfech];
394 hist_start = (hist_start + 64) & 511;
403 for (i = 1024; i > 0; i >>= 1) {
427 for (i = 0; i < 512; i++)
431 for (i = 0; i < 256; i++) {
433 power[i] =
add_cb(c, cb, cb);
450 for (j = 0; j < 256; j++)
451 out_cb_unnorm[j] = -2047;
453 for (i = 0; i <
AUBANDS; i++) {
455 for (j = 0; j < 256; j++)
456 denom =
add_cb(c, denom, power[j] + c->
auf[samplerate_index][i][j]);
457 for (j = 0; j < 256; j++)
458 out_cb_unnorm[j] =
add_cb(c, out_cb_unnorm[j],
459 -denom + c->
auf[samplerate_index][i][j]);
462 for (j = 0; j < 256; j++)
463 out_cb[j] =
add_cb(c, out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb);
476 for (f = 0; f < 4; f++)
477 walk(c, 0, 0, f, 0, -2047, channel, arg);
479 for (f = 0; f < 8; f++)
480 walk(c, band, band - 1, 8 * band - 4 + f,
491 for (f = 0; f < 4; f++)
492 walk(c, 31, 31, 256 - 4 + f, 0, -2047, channel, arg);
494 for (f = 0; f < 8; f++)
495 walk(c, band, band + 1, 8 * band + 4 + f,
512 int i, k, band,
ch, ssf;
515 for (i = 0; i < 256; i++)
523 for (i = 0, k = 128 + 256 * ssf; k < 512; i++, k++)
525 for (k -= 512; i < 512; i++, k++)
526 data[i] = input[k * c->
channels + chi];
529 for (i = 0; i < 256; i++) {
538 for (band = 0; band < 32; band++) {
549 for (sample = 0; sample <
len; sample++) {
562 for (band = 0; band < 32; band++)
580 for (band = 0; band < 32; band++) {
584 if (pred_vq_id >= 0) {
596 #define USED_1ABITS 1
597 #define USED_26ABITS 4
615 int our_nscale, try_remove;
624 for (try_remove = 64; try_remove > 0; try_remove >>= 1) {
631 our_nscale -= try_remove;
634 if (our_nscale >= 125)
650 &c->
quant[ch][band]);
666 for (band = 0; band < 32; band++)
676 for (band = 0; band < 32; band++) {
698 uint32_t clc_bits[DCA_CODE_BOOKS],
704 uint32_t t, bits = 0;
708 av_assert0(!((!!vlc_bits[i][0]) ^ (!!clc_bits[i])));
709 if (vlc_bits[i][0] == 0) {
716 best_sel_bits[i] = vlc_bits[i][0];
719 if (best_sel_bits[i] > vlc_bits[i][sel] && vlc_bits[i][sel]) {
720 best_sel_bits[i] = vlc_bits[i][sel];
721 best_sel_id[i] = sel;
726 t = best_sel_bits[i] + 2;
727 if (t < clc_bits[i]) {
728 res[i] = best_sel_id[i];
731 res[i] = ff_dca_quant_index_group_size[i];
747 for (i = 0; i <
bands; i++) {
748 if (abits[i] > 12 || abits[i] == 0) {
771 uint32_t bits_counter = 0;
780 for (band = 0; band < 32; band++) {
783 if (snr_cb >= 1312) {
786 }
else if (snr_cb >= 222) {
789 }
else if (snr_cb >= 0) {
792 }
else if (forbid_zero || snr_cb >= -140) {
808 for (band = 0; band < 32; band++) {
812 &c->
quant[ch][band]);
822 for (band = 0; band < 32; band++) {
826 huff_bit_count_accum[ch][c->
abits[ch][band] - 1]);
836 clc_bit_count_accum[ch],
875 for (down =
snr_fudge >> 1; down; down >>= 1) {
891 for (k = 0; k < 512; k++)
892 for (ch = 0; ch < c->
channels; ch++) {
907 for (ch = 0; ch < c->
channels; ch++) {
908 for (band = 0; band < 32; band++) {
1073 int i, j, sum, bits, sel;
1080 sel, c->
abits[ch][band] - 1);
1085 if (c->
abits[ch][band] <= 7) {
1086 for (i = 0; i < 8; i += 4) {
1088 for (j = 3; j >= 0; j--) {
1099 for (i = 0; i < 8; i++) {
1107 int i, band,
ss,
ch;
1142 if (c->
abits[ch][band])
1149 if (c->
abits[ch][band])
1170 if (c->
abits[ch][band])
1217 *got_packet_ptr = 1;
1221 #define DCAENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1229 .
class_name =
"DCA (DTS Coherent Acoustics)",
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
static int32_t find_peak(DCAEncContext *c, const int32_t *in, int len)
const char const char void * val
int32_t diff_peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
expected peak of residual signal
This structure describes decoded (raw) audio or video data.
uint32_t ff_dca_vlc_calc_alloc_bits(int *values, uint8_t n, uint8_t sel)
ptrdiff_t const GLvoid * data
int32_t eff_masking_curve_cb[256]
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
static void put_frame_header(DCAEncContext *c)
const uint32_t ff_dca_lossy_quant[32]
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
static const uint8_t bitstream_sfreq[]
const char * av_default_item_name(void *ptr)
Return the context name.
static const uint16_t erb[]
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
static int calc_one_scale(DCAEncContext *c, int32_t peak_cb, int abits, softfloat *quant)
static void shift_history(DCAEncContext *c, const int32_t *input)
#define AV_CH_LAYOUT_STEREO
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static void walk_band_high(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
#define AV_CH_LAYOUT_5POINT0
CompressionOptions options
int abits[MAX_CHANNELS][DCAENC_SUBBANDS]
static av_cold int encode_close(AVCodecContext *avctx)
const float ff_dca_fir_32bands_nonperfect[512]
static void walk_band_low(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int ff_dcaadpcm_do_real(int pred_vq_index, softfloat quant, int32_t scale_factor, int32_t step_size, const int32_t *prev_hist, const int32_t *in, int32_t *next_hist, int32_t *out, int len, int32_t peak)
static int32_t quantize_value(int32_t value, softfloat quant)
softfloat quant[MAX_CHANNELS][DCAENC_SUBBANDS]
static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, uint32_t *result)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int32_t get_cb(DCAEncContext *c, int32_t in)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static double cb(void *priv, double x, double y)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static void calc_masking(DCAEncContext *c, const int32_t *input)
static const softfloat stepsize_inv[27]
const uint32_t ff_dca_bit_rates[32]
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int32_t masking_curve_cb[SUBSUBFRAMES][256]
int32_t cb_to_level[2048]
static void adjust_jnd(DCAEncContext *c, const int32_t in[512], int32_t out_cb[256])
static void ff_dca_core_dequantize(int32_t *output, const int32_t *input, int32_t step_size, int32_t scale, int residual, int len)
#define AV_COPY128U(d, s)
int scale_factor[MAX_CHANNELS][DCAENC_SUBBANDS]
static void adpcm_analysis(DCAEncContext *c)
#define AV_CH_LAYOUT_5POINT1
static const softfloat scalefactor_inv[128]
static void lfe_downsample(DCAEncContext *c, const int32_t *input)
#define fc(width, name, range_min, range_max)
static double hom(double f)
int32_t band_masking_cb[32]
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void put_subframe(DCAEncContext *c, int subframe)
int32_t auf[9][AUBANDS][256]
static const int snr_fudge
const uint8_t ff_dca_quant_index_group_size[DCA_CODE_BOOKS]
const uint32_t ff_dca_lossless_quant[32]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
const float ff_dca_lfe_fir_64[256]
static void update_band_masking(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
const uint32_t ff_dca_quant_levels[32]
static int32_t add_cb(DCAEncContext *c, int32_t a, int32_t b)
uint64_t channel_layout
Audio channel layout.
static int put_bits_count(PutBitContext *s)
#define ss(width, name, subs,...)
static void assign_bits(DCAEncContext *c)
audio channel layout utility functions
static int subband_bufer_alloc(DCAEncContext *c)
int32_t prediction_mode[MAX_CHANNELS][DCAENC_SUBBANDS]
static void calc_lfe_scales(DCAEncContext *c)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLsizei GLboolean const GLfloat * value
DCAADPCMEncContext adpcm_ctx
uint32_t ff_dca_vlc_calc_quant_bits(int *values, uint8_t n, uint8_t sel, uint8_t table)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void quantize_adpcm_subband(DCAEncContext *c, int ch, int band)
#define DCA_MAX_FRAME_SIZE
int consumed_adpcm_bits
Number of bits to transmit ADPCM related info.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
const uint32_t ff_dca_scale_factor_quant7[128]
static int32_t mul32(int32_t a, int32_t b)
int frame_size
Number of samples per channel in an audio frame.
int32_t band_spectrum_tab[2][8]
static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero)
static const int8_t channel_reorder_lfe[7][5]
static void put_primary_audio_header(DCAEncContext *c)
static void find_peaks(DCAEncContext *c)
void ff_dca_vlc_enc_quant(PutBitContext *pb, int *values, uint8_t n, uint8_t sel, uint8_t table)
Libavcodec external API header.
const int32_t * band_spectrum
AVSampleFormat
Audio sample formats.
int32_t history[MAX_CHANNELS][512]
int sample_rate
samples per second
main external API structure.
static const float bands[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
static void quantize_adpcm(DCAEncContext *c)
static void calc_power(DCAEncContext *c, const int32_t in[2 *256], int32_t power[256])
Describe the class of an AVClass context structure.
static const AVOption options[]
int ff_dcaadpcm_subband_analysis(const DCAADPCMEncContext *s, const int32_t *in, int len, int *diff)
const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS]
int32_t worst_quantization_noise
static int encode_init(AVCodecContext *avctx)
static void fill_in_adpcm_bufer(DCAEncContext *c)
static void quantize_pcm(DCAEncContext *c)
#define DCA_BITALLOC_12_COUNT
static int noise(AVBSFContext *ctx, AVPacket *pkt)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void subband_transform(DCAEncContext *c, const int32_t *input)
#define LOCAL_ALIGNED_32(t, v,...)
internal math functions header
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
common internal and external API header
channel
Use these values when setting the channel map with ebur128_set_channel().
static void subband_bufer_free(DCAEncContext *c)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
int32_t quant_index_sel[MAX_CHANNELS][DCA_CODE_BOOKS]
int32_t quantized[MAX_CHANNELS][DCAENC_SUBBANDS][SUBBAND_SAMPLES]
int channels
number of audio channels
void(* walk_band_t)(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
static int32_t norm__(int64_t a, int bits)
int32_t * subband[MAX_CHANNELS][DCAENC_SUBBANDS]
static const double coeff[2][5]
static const int8_t channel_reorder_nolfe[7][5]
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
static enum AVSampleFormat sample_fmts[]
static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7], uint32_t clc_bits[DCA_CODE_BOOKS], int32_t res[DCA_CODE_BOOKS])
const int32_t * band_interpolation
int32_t downsampled_lfe[DCA_LFE_SAMPLES]
int32_t peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
int32_t bit_allocation_sel[MAX_CHANNELS]
av_cold void ff_dcaadpcm_free(DCAADPCMEncContext *s)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define FFSWAP(type, a, b)
static const AVCodecDefault defaults[]
static const uint8_t lfe_index[7]
static const int bit_consumption[27]
const float ff_dca_fir_32bands_perfect[512]
int32_t adpcm_history[MAX_CHANNELS][DCAENC_SUBBANDS][DCA_ADPCM_COEFFS *2]
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
static const AVClass dcaenc_class
void ff_dca_vlc_enc_alloc(PutBitContext *pb, int *values, uint8_t n, uint8_t sel)
int nb_samples
number of audio samples (per channel) described by this frame
static double gammafilter(int i, double f)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int32_t band_interpolation_tab[2][512]
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
static int32_t get_step_size(DCAEncContext *c, int ch, int band)