Commit c2500d62 authored by Daniil Cherednik's avatar Daniil Cherednik Committed by Rostislav Pehlivanov

dcaenc: Implementation of Huffman codes for DCA encoder

Reviewed-by: 's avatarRostislav Pehlivanov <atomnuker@gmail.com>
parent a6191d09
......@@ -235,7 +235,7 @@ OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o
OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadata.o dcahuff.o \
dca_core.o dca_exss.o dca_xll.o dca_lbr.o \
dcadsp.o dcadct.o synth_filter.o
OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o
OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o dca.o dcadata.o dcahuff.o
OBJS-$(CONFIG_DDS_DECODER) += dds.o
OBJS-$(CONFIG_DIRAC_DECODER) += diracdec.o dirac.o diracdsp.o diractab.o \
dirac_arith.o dirac_dwt.o dirac_vlc.o
......
......@@ -92,14 +92,6 @@ static const uint8_t block_code_nbits[7] = {
7, 10, 12, 13, 15, 17, 19
};
static const uint8_t quant_index_sel_nbits[DCA_CODE_BOOKS] = {
1, 2, 2, 2, 2, 3, 3, 3, 3, 3
};
static const uint8_t quant_index_group_size[DCA_CODE_BOOKS] = {
1, 3, 3, 3, 3, 7, 7, 7, 7, 7
};
static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i)
{
return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth) + v->offset;
......@@ -400,12 +392,12 @@ static int parse_coding_header(DCACoreDecoder *s, enum HeaderType header, int xc
// Quantization index codebook select
for (n = 0; n < DCA_CODE_BOOKS; n++)
for (ch = xch_base; ch < s->nchannels; ch++)
s->quant_index_sel[ch][n] = get_bits(&s->gb, quant_index_sel_nbits[n]);
s->quant_index_sel[ch][n] = get_bits(&s->gb, ff_dca_quant_index_sel_nbits[n]);
// Scale factor adjustment index
for (n = 0; n < DCA_CODE_BOOKS; n++)
for (ch = xch_base; ch < s->nchannels; ch++)
if (s->quant_index_sel[ch][n] < quant_index_group_size[n])
if (s->quant_index_sel[ch][n] < ff_dca_quant_index_group_size[n])
s->scale_factor_adj[ch][n] = ff_dca_scale_factor_adj[get_bits(&s->gb, 2)];
if (header == HEADER_XXCH) {
......@@ -663,7 +655,7 @@ static inline int extract_audio(DCACoreDecoder *s, int32_t *audio, int abits, in
if (abits <= DCA_CODE_BOOKS) {
int sel = s->quant_index_sel[ch][abits - 1];
if (sel < quant_index_group_size[abits - 1]) {
if (sel < ff_dca_quant_index_group_size[abits - 1]) {
// Huffman codes
return parse_huffman_codes(s, audio, abits, sel);
}
......@@ -1562,7 +1554,7 @@ static int parse_x96_coding_header(DCACoreDecoder *s, int exss, int xch_base)
// Quantization index codebook select
for (n = 0; n < 6 + 4 * s->x96_high_res; n++)
for (ch = xch_base; ch < s->x96_nchannels; ch++)
s->quant_index_sel[ch][n] = get_bits(&s->gb, quant_index_sel_nbits[n]);
s->quant_index_sel[ch][n] = get_bits(&s->gb, ff_dca_quant_index_sel_nbits[n]);
if (exss) {
// Reserved
......
......@@ -50,6 +50,14 @@ const uint8_t ff_dca_dmix_primary_nch[8] = {
1, 2, 2, 3, 3, 4, 4, 0
};
const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS] = {
1, 2, 2, 2, 2, 3, 3, 3, 3, 3
};
const uint8_t ff_dca_quant_index_group_size[DCA_CODE_BOOKS] = {
1, 3, 3, 3, 3, 7, 7, 7, 7, 7
};
/* ADPCM data */
/* 16 bits signed fractional Q13 binary codes */
......
......@@ -23,6 +23,8 @@
#include <stdint.h>
#include "dcahuff.h"
extern const uint32_t ff_dca_bit_rates[32];
extern const uint8_t ff_dca_channels[16];
......@@ -31,6 +33,9 @@ extern const uint8_t ff_dca_bits_per_sample[8];
extern const uint8_t ff_dca_dmix_primary_nch[8];
extern const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS];
extern const uint8_t ff_dca_quant_index_group_size[DCA_CODE_BOOKS];
extern const int16_t ff_dca_adpcm_vb[4096][4];
extern const uint32_t ff_dca_scale_factor_quant6[64];
......
This diff is collapsed.
......@@ -95,7 +95,6 @@ static const softfloat scalefactor_inv[128] = {
/* manually derived from
* Table B.5: Selection of quantization levels and codebooks
* FIXME: will become invalid when Huffman codes are introduced.
*/
static const int bit_consumption[27] = {
-8, 28, 40, 48, 52, 60, 68, 76, 80, 96,
......
......@@ -1335,3 +1335,25 @@ av_cold void ff_dca_init_vlcs(void)
vlcs_initialized = 1;
}
uint32_t ff_dca_vlc_calc_quant_bits(int *values, uint8_t n, uint8_t sel, uint8_t table)
{
uint8_t i, id;
uint32_t sum = 0;
for (i = 0; i < n; i++) {
id = values[i] - bitalloc_offsets[table];
av_assert0(id < bitalloc_sizes[table]);
sum += bitalloc_bits[table][sel][id];
}
return sum;
}
void ff_dca_vlc_enc_quant(PutBitContext *pb, int *values, uint8_t n, uint8_t sel, uint8_t table)
{
uint8_t i, id;
for (i = 0; i < n; i++) {
id = values[i] - bitalloc_offsets[table];
av_assert0(id < bitalloc_sizes[table]);
put_bits(pb, bitalloc_bits[table][sel][id], bitalloc_codes[table][sel][id]);
}
}
......@@ -27,6 +27,7 @@
#include "avcodec.h"
#include "get_bits.h"
#include "put_bits.h"
#define DCA_CODE_BOOKS 10
......@@ -55,5 +56,7 @@ extern VLC ff_dca_vlc_grid_3;
extern VLC ff_dca_vlc_rsd;
av_cold void ff_dca_init_vlcs(void);
uint32_t ff_dca_vlc_calc_quant_bits(int *values, uint8_t n, uint8_t sel, uint8_t abits);
void ff_dca_vlc_enc_quant(PutBitContext *pb, int *values, uint8_t n, uint8_t sel, uint8_t abits);
#endif /* AVCODEC_DCAHUFF_H */
......@@ -104,7 +104,7 @@ fate-acodec-dca: tests/data/asynth-44100-2.wav
fate-acodec-dca: SRC = tests/data/asynth-44100-2.wav
fate-acodec-dca: CMD = md5 -i $(TARGET_PATH)/$(SRC) -c:a dca -strict -2 -f dts -flags +bitexact
fate-acodec-dca: CMP = oneline
fate-acodec-dca: REF = 7ffdefdf47069289990755c79387cc90
fate-acodec-dca: REF = 7cd79a3717943a06b217f1130223a86f
FATE_ACODEC-$(call ENCDEC, DCA, WAV) += fate-acodec-dca2
fate-acodec-dca2: CMD = enc_dec_pcm dts wav s16le $(SRC) -c:a dca -strict -2 -flags +bitexact
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment