25 #define FFT_FIXED_32 1
45 #define MAX_CHANNELS 6
46 #define DCA_MAX_FRAME_SIZE 16384
47 #define DCA_HEADER_SIZE 13
48 #define DCA_LFE_SAMPLES 8
50 #define DCAENC_SUBBANDS 32
52 #define SUBSUBFRAMES 2
53 #define SUBBAND_SAMPLES (SUBFRAMES * SUBSUBFRAMES * 8)
56 #define COS_T(x) (c->cos_table[(x) & 2047])
116 double f1 =
f / 1000;
118 return -3.64 * pow(f1, -0.8)
119 + 6.8 *
exp(-0.6 * (f1 - 3.4) * (f1 - 3.4))
120 - 6.0 *
exp(-0.15 * (f1 - 8.7) * (f1 - 8.7))
121 - 0.0006 * (f1 * f1) * (f1 * f1);
130 return 20 * log10(
h);
146 c->subband[ch][band] = bufer +
156 if (
c->subband[0][0]) {
159 c->subband[0][0] =
NULL;
167 int i, j, k, min_frame_bits;
173 c->fullband_channels =
c->channels = avctx->
channels;
175 c->band_interpolation =
c->band_interpolation_tab[1];
176 c->band_spectrum =
c->band_spectrum_tab[1];
177 c->worst_quantization_noise = -2047;
178 c->worst_noise_ever = -2047;
179 c->consumed_adpcm_bits = 0;
186 "encoder will guess the layout, but it "
187 "might be incorrect.\n");
201 if (
c->lfe_channel) {
202 c->fullband_channels--;
213 c->bit_allocation_sel[
i] = 6;
217 c->prediction_mode[
i][j] = -1;
222 for (
i = 0;
i < 9;
i++) {
228 c->samplerate_index =
i;
236 c->bitrate_index =
i;
238 min_frame_bits = 132 + (493 + 28 * 32) *
c->fullband_channels +
c->lfe_channel * 72;
242 c->frame_size = (
c->frame_bits + 7) / 8;
250 c->cos_table[0] = 0x7fffffff;
251 c->cos_table[512] = 0;
252 c->cos_table[1024] = -
c->cos_table[0];
253 for (
i = 1;
i < 512;
i++) {
255 c->cos_table[1024-
i] = -
c->cos_table[
i];
256 c->cos_table[1024+
i] = -
c->cos_table[
i];
257 c->cos_table[2048-
i] = +
c->cos_table[
i];
260 for (
i = 0;
i < 2048;
i++)
263 for (k = 0; k < 32; k++) {
264 for (j = 0; j < 8; j++) {
270 for (
i = 0;
i < 512;
i++) {
275 for (
i = 0;
i < 9;
i++) {
276 for (j = 0; j <
AUBANDS; j++) {
277 for (k = 0; k < 256; k++) {
285 for (
i = 0;
i < 256;
i++) {
289 for (j = 0; j < 8; j++) {
291 for (
i = 0;
i < 512;
i++) {
293 accum += reconst * cos(2 *
M_PI * (
i + 0.5 - 256) * (j + 0.5) / 512);
295 c->band_spectrum_tab[0][j] = (
int32_t)(200 * log10(accum));
297 for (j = 0; j < 8; j++) {
299 for (
i = 0;
i < 512;
i++) {
301 accum += reconst * cos(2 *
M_PI * (
i + 0.5 - 256) * (j + 0.5) / 512);
303 c->band_spectrum_tab[1][j] = (
int32_t)(200 * log10(accum));
321 int ch, subs,
i, k, j;
323 for (ch = 0; ch <
c->fullband_channels; ch++) {
327 const int chi =
c->channel_order_tab[ch];
329 memcpy(hist, &
c->history[ch][0], 512 *
sizeof(
int32_t));
337 memset(accum, 0, 64 *
sizeof(
int32_t));
339 for (k = 0,
i = hist_start, j = 0;
340 i < 512; k = (k + 1) & 63,
i++, j++)
341 accum[k] +=
mul32(hist[
i],
c->band_interpolation[j]);
342 for (
i = 0;
i < hist_start; k = (k + 1) & 63,
i++, j++)
343 accum[k] +=
mul32(hist[
i],
c->band_interpolation[j]);
345 for (k = 16; k < 32; k++)
346 accum[k] = accum[k] - accum[31 - k];
347 for (k = 32; k < 48; k++)
348 accum[k] = accum[k] + accum[95 - k];
350 for (band = 0; band < 32; band++) {
352 for (
i = 16;
i < 48;
i++) {
353 int s = (2 * band + 1) * (2 * (
i + 16) + 1);
357 c->subband[ch][band][subs] = ((band + 1) & 2) ? -resp : resp;
361 for (
i = 0;
i < 32;
i++)
362 hist[
i + hist_start] = input[(subs * 32 +
i) *
c->channels + chi];
364 hist_start = (hist_start + 32) & 511;
372 const int lfech =
lfe_index[
c->channel_config];
378 memcpy(hist, &
c->history[
c->channels - 1][0], 512 *
sizeof(
int32_t));
384 for (
i = hist_start, j = 0;
i < 512;
i++, j++)
385 accum +=
mul32(hist[
i],
c->lfe_fir_64i[j]);
386 for (
i = 0;
i < hist_start;
i++, j++)
387 accum +=
mul32(hist[
i],
c->lfe_fir_64i[j]);
389 c->downsampled_lfe[lfes] = accum;
392 for (
i = 0;
i < 64;
i++)
393 hist[
i + hist_start] = input[(lfes * 64 +
i) *
c->channels + lfech];
395 hist_start = (hist_start + 64) & 511;
404 for (
i = 1024;
i > 0;
i >>= 1) {
405 if (
c->cb_to_level[
i + res] >=
in)
418 return a +
c->cb_to_add[
a -
b];
428 for (
i = 0;
i < 512;
i++)
432 for (
i = 0;
i < 256;
i++) {
446 const int samplerate_index =
c->samplerate_index;
451 for (j = 0; j < 256; j++)
452 out_cb_unnorm[j] = -2047;
456 for (j = 0; j < 256; j++)
457 denom =
add_cb(
c, denom, power[j] +
c->auf[samplerate_index][
i][j]);
458 for (j = 0; j < 256; j++)
459 out_cb_unnorm[j] =
add_cb(
c, out_cb_unnorm[j],
460 -denom +
c->auf[samplerate_index][
i][j]);
463 for (j = 0; j < 256; j++)
464 out_cb[j] =
add_cb(
c, out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb);
477 for (
f = 0;
f < 4;
f++)
480 for (
f = 0;
f < 8;
f++)
481 walk(
c, band, band - 1, 8 * band - 4 +
f,
492 for (
f = 0;
f < 4;
f++)
495 for (
f = 0;
f < 8;
f++)
496 walk(
c, band, band + 1, 8 * band + 4 +
f,
507 if (value < c->band_masking_cb[band1])
508 c->band_masking_cb[band1] =
value;
513 int i, k, band, ch, ssf;
516 for (
i = 0;
i < 256;
i++)
518 c->masking_curve_cb[ssf][
i] = -2047;
521 for (ch = 0; ch <
c->fullband_channels; ch++) {
522 const int chi =
c->channel_order_tab[ch];
524 for (
i = 0, k = 128 + 256 * ssf; k < 512;
i++, k++)
525 data[
i] =
c->history[ch][k];
526 for (k -= 512;
i < 512;
i++, k++)
527 data[
i] = input[k *
c->channels + chi];
530 for (
i = 0;
i < 256;
i++) {
534 if (
c->masking_curve_cb[ssf][
i] < m)
535 m =
c->masking_curve_cb[ssf][
i];
536 c->eff_masking_curve_cb[
i] = m;
539 for (band = 0; band < 32; band++) {
540 c->band_masking_cb[band] = 2048;
562 for (ch = 0; ch <
c->fullband_channels; ch++) {
563 for (band = 0; band < 32; band++)
564 c->peak_cb[ch][band] =
find_peak(
c,
c->subband[ch][band],
579 c->consumed_adpcm_bits = 0;
580 for (ch = 0; ch <
c->fullband_channels; ch++) {
581 for (band = 0; band < 32; band++) {
585 if (pred_vq_id >= 0) {
586 c->prediction_mode[ch][band] = pred_vq_id;
587 c->consumed_adpcm_bits += 12;
588 c->diff_peak_cb[ch][band] =
find_peak(
c, estimated_diff, 16);
590 c->prediction_mode[ch][band] = -1;
597 #define USED_1ABITS 1
598 #define USED_26ABITS 4
604 if (
c->bitrate_index == 3)
616 int our_nscale, try_remove;
623 peak =
c->cb_to_level[-peak_cb];
625 for (try_remove = 64; try_remove > 0; try_remove >>= 1) {
632 our_nscale -= try_remove;
635 if (our_nscale >= 125)
648 int32_t diff_peak_cb =
c->diff_peak_cb[ch][band];
651 &
c->quant[ch][band]);
657 step_size,
c->adpcm_history[ch][band],
c->subband[ch][band],
658 c->adpcm_history[ch][band] + 4,
c->quantized[ch][band],
666 for (ch = 0; ch <
c->fullband_channels; ch++)
667 for (band = 0; band < 32; band++)
668 if (
c->prediction_mode[ch][band] >= 0)
676 for (ch = 0; ch <
c->fullband_channels; ch++) {
677 for (band = 0; band < 32; band++) {
678 if (
c->prediction_mode[ch][band] == -1) {
705 uint32_t t,
bits = 0;
710 if (vlc_bits[
i][0] == 0) {
717 best_sel_bits[
i] = vlc_bits[
i][0];
720 if (best_sel_bits[
i] > vlc_bits[
i][sel] && vlc_bits[
i][sel]) {
721 best_sel_bits[
i] = vlc_bits[
i][sel];
722 best_sel_id[
i] = sel;
727 t = best_sel_bits[
i] + 2;
728 if (t < clc_bits[
i]) {
729 res[
i] = best_sel_id[
i];
749 if (abits[
i] > 12 || abits[
i] == 0) {
772 uint32_t bits_counter = 0;
774 c->consumed_bits = 132 + 333 *
c->fullband_channels;
775 c->consumed_bits +=
c->consumed_adpcm_bits;
777 c->consumed_bits += 72;
780 for (ch = 0; ch <
c->fullband_channels; ch++) {
781 for (band = 0; band < 32; band++) {
782 int snr_cb =
c->peak_cb[ch][band] -
c->band_masking_cb[band] -
noise;
784 if (snr_cb >= 1312) {
785 c->abits[ch][band] = 26;
787 }
else if (snr_cb >= 222) {
788 c->abits[ch][band] = 8 +
mul32(snr_cb - 222, 69000000);
790 }
else if (snr_cb >= 0) {
791 c->abits[ch][band] = 2 +
mul32(snr_cb, 106000000);
793 }
else if (forbid_zero || snr_cb >= -140) {
794 c->abits[ch][band] = 1;
797 c->abits[ch][band] = 0;
802 &
c->bit_allocation_sel[ch]);
808 for (ch = 0; ch <
c->fullband_channels; ch++) {
809 for (band = 0; band < 32; band++) {
810 if (
c->prediction_mode[ch][band] == -1) {
813 &
c->quant[ch][band]);
822 for (ch = 0; ch <
c->fullband_channels; ch++) {
823 for (band = 0; band < 32; band++) {
826 c->quantized[ch][band],
827 huff_bit_count_accum[ch][
c->abits[ch][band] - 1]);
828 clc_bit_count_accum[ch][
c->abits[ch][band] - 1] +=
bit_consumption[
c->abits[ch][band]];
835 for (ch = 0; ch <
c->fullband_channels; ch++) {
837 clc_bit_count_accum[ch],
838 c->quant_index_sel[ch]);
841 c->consumed_bits += bits_counter;
854 low = high =
c->worst_quantization_noise;
855 if (
c->consumed_bits >
c->frame_bits) {
856 while (
c->consumed_bits >
c->frame_bits) {
866 while (
c->consumed_bits <=
c->frame_bits) {
876 for (down =
snr_fudge >> 1; down; down >>= 1) {
878 if (
c->consumed_bits <=
c->frame_bits)
883 c->worst_quantization_noise = high;
884 if (high >
c->worst_noise_ever)
885 c->worst_noise_ever = high;
892 for (k = 0; k < 512; k++)
893 for (ch = 0; ch <
c->channels; ch++) {
894 const int chi =
c->channel_order_tab[ch];
896 c->history[ch][k] = input[k *
c->channels + chi];
908 for (ch = 0; ch <
c->channels; ch++) {
909 for (band = 0; band < 32; band++) {
911 if (
c->prediction_mode[ch][band] == -1) {
915 c->quantized[ch][band]+12, step_size,
918 AV_COPY128U(
c->adpcm_history[ch][band],
c->adpcm_history[ch][band]+4);
928 samples[0] =
c->adpcm_history[ch][band][0] * (1 << 7);
929 samples[1] =
c->adpcm_history[ch][band][1] * (1 << 7);
930 samples[2] =
c->adpcm_history[ch][band][2] * (1 << 7);
931 samples[3] =
c->adpcm_history[ch][band][3] * (1 << 7);
1032 put_bits(&
c->pb, 3,
c->fullband_channels - 1);
1035 for (ch = 0; ch <
c->fullband_channels; ch++)
1039 for (ch = 0; ch <
c->fullband_channels; ch++)
1043 for (ch = 0; ch <
c->fullband_channels; ch++)
1047 for (ch = 0; ch <
c->fullband_channels; ch++)
1051 for (ch = 0; ch <
c->fullband_channels; ch++)
1055 for (ch = 0; ch <
c->fullband_channels; ch++)
1056 put_bits(&
c->pb, 3,
c->bit_allocation_sel[ch]);
1060 for (ch = 0; ch <
c->fullband_channels; ch++)
1065 for (ch = 0; ch <
c->fullband_channels; ch++)
1074 int i, j, sum,
bits, sel;
1077 sel =
c->quant_index_sel[ch][
c->abits[ch][band] - 1];
1081 sel,
c->abits[ch][band] - 1);
1086 if (
c->abits[ch][band] <= 7) {
1087 for (
i = 0;
i < 8;
i += 4) {
1089 for (j = 3; j >= 0; j--) {
1091 sum +=
c->quantized[ch][band][
ss * 8 +
i + j];
1100 for (
i = 0;
i < 8;
i++) {
1108 int i, band,
ss, ch;
1117 for (ch = 0; ch <
c->fullband_channels; ch++)
1119 put_bits(&
c->pb, 1, !(
c->prediction_mode[ch][band] == -1));
1122 for (ch = 0; ch <
c->fullband_channels; ch++)
1124 if (
c->prediction_mode[ch][band] >= 0)
1125 put_bits(&
c->pb, 12,
c->prediction_mode[ch][band]);
1128 for (ch = 0; ch <
c->fullband_channels; ch++) {
1129 if (
c->bit_allocation_sel[ch] == 6) {
1135 c->bit_allocation_sel[ch]);
1141 for (ch = 0; ch <
c->fullband_channels; ch++)
1143 if (
c->abits[ch][band])
1148 for (ch = 0; ch <
c->fullband_channels; ch++)
1150 if (
c->abits[ch][band])
1151 put_bits(&
c->pb, 7,
c->scale_factor[ch][band]);
1161 if (
c->lfe_channel) {
1169 for (ch = 0; ch <
c->fullband_channels; ch++)
1171 if (
c->abits[ch][band])
1195 if (
c->options.adpcm_mode)
1218 *got_packet_ptr = 1;
1222 #define DCAENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1230 .
class_name =
"DCA (DTS Coherent Acoustics)",
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
static const float bands[]
uint8_t pi<< 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_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_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_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)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
#define fc(width, name, range_min, range_max)
#define ss(width, name, subs,...)
audio channel layout utility functions
common internal and external API header
#define FFSWAP(type, a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void ff_dca_core_dequantize(int32_t *output, const int32_t *input, int32_t step_size, int32_t scale, int residual, int len)
static const int8_t channel_reorder_lfe[7][5]
static const uint8_t lfe_index[7]
static const int8_t channel_reorder_nolfe[7][5]
int ff_dcaadpcm_subband_analysis(const DCAADPCMEncContext *s, const int32_t *in, int len, int *diff)
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)
av_cold void ff_dcaadpcm_free(DCAADPCMEncContext *s)
av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS]
const float ff_dca_fir_32bands_nonperfect[512]
const uint32_t ff_dca_lossless_quant[32]
const uint32_t ff_dca_scale_factor_quant7[128]
const uint8_t ff_dca_quant_index_group_size[DCA_CODE_BOOKS]
const uint32_t ff_dca_lossy_quant[32]
const float ff_dca_fir_32bands_perfect[512]
const uint32_t ff_dca_quant_levels[32]
const float ff_dca_lfe_fir_64[256]
const uint32_t ff_dca_bit_rates[32]
static double hom(double f)
static const AVCodecDefault defaults[]
static void calc_lfe_scales(DCAEncContext *c)
static void put_frame_header(DCAEncContext *c)
static const int snr_fudge
static int encode_init(AVCodecContext *avctx)
static void walk_band_low(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
static void assign_bits(DCAEncContext *c)
#define DCA_MAX_FRAME_SIZE
static void shift_history(DCAEncContext *c, const int32_t *input)
static void calc_power(DCAEncContext *c, const int32_t in[2 *256], int32_t power[256])
static const AVOption options[]
static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero)
static void put_subframe(DCAEncContext *c, int subframe)
static void adjust_jnd(DCAEncContext *c, const int32_t in[512], int32_t out_cb[256])
void(* walk_band_t)(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
static int subband_bufer_alloc(DCAEncContext *c)
static int32_t get_step_size(DCAEncContext *c, int ch, int band)
static void adpcm_analysis(DCAEncContext *c)
static int32_t find_peak(DCAEncContext *c, const int32_t *in, int len)
static void quantize_pcm(DCAEncContext *c)
static av_cold int encode_close(AVCodecContext *avctx)
static void quantize_adpcm(DCAEncContext *c)
static int32_t add_cb(DCAEncContext *c, int32_t a, int32_t b)
static void subband_transform(DCAEncContext *c, const int32_t *input)
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])
static void put_primary_audio_header(DCAEncContext *c)
static void calc_masking(DCAEncContext *c, const int32_t *input)
static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
static double gammafilter(int i, double f)
static void lfe_downsample(DCAEncContext *c, const int32_t *input)
static void walk_band_high(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, uint32_t *result)
static const AVClass dcaenc_class
static int calc_one_scale(DCAEncContext *c, int32_t peak_cb, int abits, softfloat *quant)
static void update_band_masking(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
static int32_t get_cb(DCAEncContext *c, int32_t in)
static void subband_bufer_free(DCAEncContext *c)
static void fill_in_adpcm_bufer(DCAEncContext *c)
static void find_peaks(DCAEncContext *c)
static void quantize_adpcm_subband(DCAEncContext *c, int ch, int band)
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static int32_t quantize_value(int32_t value, softfloat quant)
static const softfloat scalefactor_inv[128]
static const int bit_consumption[27]
static const softfloat stepsize_inv[27]
static const uint8_t bitstream_sfreq[]
static const uint16_t erb[]
uint32_t ff_dca_vlc_calc_quant_bits(int *values, uint8_t n, uint8_t sel, uint8_t table)
void ff_dca_vlc_enc_alloc(PutBitContext *pb, int *values, uint8_t n, uint8_t sel)
uint32_t ff_dca_vlc_calc_alloc_bits(int *values, uint8_t n, uint8_t sel)
void ff_dca_vlc_enc_quant(PutBitContext *pb, int *values, uint8_t n, uint8_t sel, uint8_t table)
#define DCA_BITALLOC_12_COUNT
static int32_t mul32(int32_t a, int32_t b)
static int32_t norm__(int64_t a, int bits)
static float add(float src0, float src1)
channel
Use these values when setting the channel map with ebur128_set_channel().
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_5POINT1
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
#define LIBAVUTIL_VERSION_INT
#define AV_COPY128U(d, s)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#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 av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define LOCAL_ALIGNED_32(t, v,...)
static int noise(AVBSFContext *ctx, AVPacket *pkt)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
int frame_size
Number of samples per channel in an audio frame.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
const int32_t * band_interpolation
int scale_factor[MAX_CHANNELS][DCAENC_SUBBANDS]
int32_t eff_masking_curve_cb[256]
int32_t masking_curve_cb[SUBSUBFRAMES][256]
int32_t downsampled_lfe[DCA_LFE_SAMPLES]
int32_t peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
int32_t adpcm_history[MAX_CHANNELS][DCAENC_SUBBANDS][DCA_ADPCM_COEFFS *2]
int32_t quant_index_sel[MAX_CHANNELS][DCA_CODE_BOOKS]
int32_t prediction_mode[MAX_CHANNELS][DCAENC_SUBBANDS]
DCAADPCMEncContext adpcm_ctx
int32_t worst_quantization_noise
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
int32_t * subband[MAX_CHANNELS][DCAENC_SUBBANDS]
int32_t band_masking_cb[32]
int32_t band_spectrum_tab[2][8]
int32_t quantized[MAX_CHANNELS][DCAENC_SUBBANDS][SUBBAND_SAMPLES]
int abits[MAX_CHANNELS][DCAENC_SUBBANDS]
int consumed_adpcm_bits
Number of bits to transmit ADPCM related info.
int32_t cb_to_level[2048]
int32_t auf[9][AUBANDS][256]
int32_t diff_peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
expected peak of residual signal
int32_t band_interpolation_tab[2][512]
int32_t bit_allocation_sel[MAX_CHANNELS]
softfloat quant[MAX_CHANNELS][DCAENC_SUBBANDS]
int32_t history[MAX_CHANNELS][512]
const int32_t * band_spectrum
CompressionOptions options
static double cb(void *priv, double x, double y)
static const double coeff[2][5]