Line data Source code
1 : /******************************************************************************
2 : * ETSI TS 103 634 V1.5.1 *
3 : * Low Complexity Communication Codec Plus (LC3plus) *
4 : * *
5 : * Copyright licence is solely granted through ETSI Intellectual Property *
6 : * Rights Policy, 3rd April 2019. No patent licence is granted by implication, *
7 : * estoppel or otherwise. *
8 : ******************************************************************************/
9 :
10 : #include "options.h"
11 : #include "wmc_auto.h"
12 : #include "functions.h"
13 :
14 : static const LC3_INT gainMSBbits[4] = {1, 1, 2, 2};
15 : static const LC3_INT gainLSBbits[4] = {0, 1, 0, 1};
16 :
17 0 : void processEncoderEntropy_fl(LC3_UINT8* bytes, LC3_INT* bp_side, LC3_INT* mask_side, LC3_INT numbytes, LC3_INT bw_cutoff_bits,
18 : LC3_INT bw_cutoff_idx, LC3_INT lastnz, LC3_INT N, LC3_INT lsbMode, LC3_INT gg_idx, LC3_INT num_tns_filters,
19 : LC3_INT* tns_order, LC3_INT* ltpf_idx, LC3_INT* scf_idx, LC3_INT fac_ns_idx
20 : , LC3_INT bfi_ext, LC3_INT fs_idx
21 : )
22 : {
23 : LC3_UINT8* ptr;
24 : LC3_INT i, submodeMSB, submodeLSB, tmp, gainMSB, gainLSB;
25 :
26 :
27 0 : LC3_INT16 lastnzTrigger[5] = {63, 127, 127, 255, 255};
28 :
29 0 : *bp_side = numbytes - 1;
30 0 : *mask_side = 1;
31 0 : ptr = bytes;
32 :
33 : /* Bandwidth */
34 0 : if (bw_cutoff_bits > 0) {
35 0 : write_uint_backward_fl(ptr, bp_side, mask_side, bw_cutoff_idx, bw_cutoff_bits);
36 : }
37 :
38 : /* Last non zero touple */
39 0 : if (bfi_ext == 1) {
40 0 : write_uint_backward_fl(ptr, bp_side, mask_side, lastnzTrigger[fs_idx], ceil(LC3_LOGTWO(N >> 1)));
41 : }
42 : else
43 : {
44 0 : write_uint_backward_fl(ptr, bp_side, mask_side, lastnz / 2 - 1, ceil(LC3_LOGTWO(N >> 1)));
45 : }
46 :
47 : /* LSB mode bit */
48 0 : write_bit_backward_fl(ptr, bp_side, mask_side, lsbMode);
49 :
50 : /* Global gain */
51 0 : write_uint_backward_fl(ptr, bp_side, mask_side, gg_idx, 8);
52 :
53 : /* TNS activation flag */
54 0 : for (i = 0; i < num_tns_filters; i++) {
55 0 : write_bit_backward_fl(ptr, bp_side, mask_side, MIN(1, tns_order[i]));
56 : }
57 :
58 : /* LTPF activation flag */
59 0 : write_bit_backward_fl(ptr, bp_side, mask_side, ltpf_idx[0]);
60 :
61 : /* SNS-VQ 1st stage */
62 0 : write_uint_backward_fl(ptr, bp_side, mask_side, scf_idx[0], 5);
63 0 : write_uint_backward_fl(ptr, bp_side, mask_side, scf_idx[1], 5);
64 :
65 : /* SNS-VQ 2nd stage side-info (3-4 bits) */
66 0 : submodeMSB = scf_idx[2] / 2;
67 0 : submodeLSB = scf_idx[2] & 1;
68 0 : write_bit_backward_fl(ptr, bp_side, mask_side, submodeMSB);
69 0 : gainMSB = scf_idx[3] >> (gainLSBbits[scf_idx[2]]);
70 0 : gainLSB = scf_idx[3] & 1;
71 0 : write_uint_backward_fl(ptr, bp_side, mask_side, gainMSB, gainMSBbits[scf_idx[2]]);
72 0 : write_bit_backward_fl(ptr, bp_side, mask_side, scf_idx[4]);
73 :
74 : /* SNS-VQ 2nd stage MPVQ data (24-25 bits) */
75 0 : if (submodeMSB == 0) {
76 0 : if (submodeLSB == 0) {
77 0 : tmp = scf_idx[6] + 2;
78 : } else {
79 0 : tmp = gainLSB;
80 : }
81 :
82 0 : tmp = tmp * 2390004 + scf_idx[5];
83 0 : write_uint_backward_fl(ptr, bp_side, mask_side, tmp, 25);
84 : } else {
85 0 : tmp = scf_idx[5];
86 :
87 0 : if (submodeLSB != 0) {
88 0 : tmp = 2 * tmp + gainLSB + 15158272;
89 : }
90 :
91 0 : write_uint_backward_fl(ptr, bp_side, mask_side, tmp, 24);
92 : }
93 :
94 : /* LTPF data */
95 0 : if (ltpf_idx[0] == 1) {
96 0 : write_uint_backward_fl(ptr, bp_side, mask_side, ltpf_idx[1], 1);
97 0 : write_uint_backward_fl(ptr, bp_side, mask_side, ltpf_idx[2], 9);
98 : }
99 :
100 : /* Noise factor */
101 0 : write_uint_backward_fl(ptr, bp_side, mask_side, fac_ns_idx, 3);
102 0 : }
103 :
104 0 : void write_uint_backward_fl(LC3_UINT8* ptr, LC3_INT* bp_side, LC3_INT* mask_side, LC3_INT val, LC3_INT numbits)
105 : {
106 : LC3_INT k, bit;
107 :
108 0 : for (k = 0; k < numbits; k++) {
109 0 : bit = val & 1;
110 0 : write_bit_backward_fl(ptr, bp_side, mask_side, bit);
111 0 : val = val >> 1;
112 : }
113 0 : }
114 :
115 0 : void write_bit_backward_fl(LC3_UINT8* ptr, LC3_INT* bp_side, LC3_INT* mask_side, LC3_INT bit)
116 : {
117 0 : if (bit != 0) {
118 0 : ptr[*bp_side] = ptr[*bp_side] | *mask_side;
119 : }
120 :
121 0 : if (*mask_side == 128) {
122 0 : *mask_side = 1;
123 0 : *bp_side = *bp_side - 1;
124 : } else {
125 0 : *mask_side = *mask_side << 1;
126 : }
127 0 : }
|