1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: dec_acelp_4p_in_64.cpp
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
39 int16 index[], (i) : index (20): 5+5+5+5 = 20 bits.
40 (i) : index (36): 9+9+9+9 = 36 bits.
41 (i) : index (44): 13+9+13+9 = 44 bits.
42 (i) : index (52): 13+13+13+13 = 52 bits.
43 (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits.
44 (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits.
45 (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits.
46 int16 nbbits, (i) : 20, 36, 44, 52, 64, 72 or 88 bits
47 int16 code[] (o) Q9: algebraic (fixed) codebook excitation
49 ------------------------------------------------------------------------------
52 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook decoder.
53 4 tracks x 16 positions per track = 64 samples.
55 20 bits --> 4 pulses in a frame of 64 samples.
56 36 bits --> 8 pulses in a frame of 64 samples.
57 44 bits --> 10 pulses in a frame of 64 samples.
58 52 bits --> 12 pulses in a frame of 64 samples.
59 64 bits --> 16 pulses in a frame of 64 samples.
60 72 bits --> 18 pulses in a frame of 64 samples.
61 88 bits --> 24 pulses in a frame of 64 samples.
63 All pulses can have two (2) possible amplitudes: +1 or -1.
64 Each pulse can have sixteen (16) possible positions.
66 ------------------------------------------------------------------------------
70 ------------------------------------------------------------------------------
73 ------------------------------------------------------------------------------
76 ------------------------------------------------------------------------------
80 /*----------------------------------------------------------------------------
82 ----------------------------------------------------------------------------*/
84 #include "pv_amr_wb_type_defs.h"
85 #include "pvamrwbdecoder_basic_op.h"
86 #include "pvamrwbdecoder_cnst.h"
87 #include "pvamrwbdecoder_acelp.h"
91 /*----------------------------------------------------------------------------
93 ; Define module specific macros here
94 ----------------------------------------------------------------------------*/
97 /*----------------------------------------------------------------------------
99 ; Include all pre-processor statements here. Include conditional
100 ; compile variables also.
101 ----------------------------------------------------------------------------*/
102 #define L_CODE 64 /* codevector length */
103 #define NB_TRACK 4 /* number of track */
104 #define NB_POS 16 /* number of position */
106 /*----------------------------------------------------------------------------
107 ; LOCAL FUNCTION DEFINITIONS
108 ; Function Prototype declaration
109 ----------------------------------------------------------------------------*/
115 void add_pulses(int16 pos[], int16 nb_pulse, int16 track, int16 code[]);
121 /*----------------------------------------------------------------------------
122 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
123 ; Variable declaration - defined here and used outside this module
124 ----------------------------------------------------------------------------*/
126 /*----------------------------------------------------------------------------
127 ; EXTERNAL FUNCTION REFERENCES
128 ; Declare functions defined elsewhere and referenced in this module
129 ----------------------------------------------------------------------------*/
131 /*----------------------------------------------------------------------------
132 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
133 ; Declare variables used in this module but defined elsewhere
134 ----------------------------------------------------------------------------*/
136 /*----------------------------------------------------------------------------
138 ----------------------------------------------------------------------------*/
140 void dec_acelp_4p_in_64(
141 int16 index[], /* (i) : index (20): 5+5+5+5 = 20 bits. */
142 /* (i) : index (36): 9+9+9+9 = 36 bits. */
143 /* (i) : index (44): 13+9+13+9 = 44 bits. */
144 /* (i) : index (52): 13+13+13+13 = 52 bits. */
145 /* (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits. */
146 /* (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits. */
147 /* (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
148 int16 nbbits, /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits */
149 int16 code[] /* (o) Q9: algebraic (fixed) codebook excitation */
154 pv_memset(code, 0, L_CODE*sizeof(*code));
156 /* decode the positions and signs of pulses and build the codeword */
162 for (k = 0; k < NB_TRACK; k++)
165 dec_1p_N1(L_index, 4, 0, pos);
166 add_pulses(pos, 1, k, code);
171 for (k = 0; k < NB_TRACK; k++)
174 dec_2p_2N1(L_index, 4, 0, pos);
175 add_pulses(pos, 2, k, code);
179 for (k = 0; k < NB_TRACK - 2; k++)
182 dec_3p_3N1(L_index, 4, 0, pos);
183 add_pulses(pos, 3, k, code);
185 for (k = 2; k < NB_TRACK; k++)
188 dec_2p_2N1(L_index, 4, 0, pos);
189 add_pulses(pos, 2, k, code);
193 for (k = 0; k < NB_TRACK; k++)
196 dec_3p_3N1(L_index, 4, 0, pos);
197 add_pulses(pos, 3, k, code);
201 for (k = 0; k < NB_TRACK; k++)
203 L_index = ((int32)index[k] << 14) + index[k + NB_TRACK];
204 dec_4p_4N(L_index, 4, 0, pos);
205 add_pulses(pos, 4, k, code);
209 for (k = 0; k < NB_TRACK - 2; k++)
211 L_index = ((int32)index[k] << 10) + index[k + NB_TRACK];
212 dec_5p_5N(L_index, 4, 0, pos);
213 add_pulses(pos, 5, k, code);
215 for (k = 2; k < NB_TRACK; k++)
217 L_index = ((int32)index[k] << 14) + index[k + NB_TRACK];
218 dec_4p_4N(L_index, 4, 0, pos);
219 add_pulses(pos, 4, k, code);
223 for (k = 0; k < NB_TRACK; k++)
225 L_index = ((int32)index[k] << 11) + index[k + NB_TRACK];
226 dec_6p_6N_2(L_index, 4, 0, pos);
227 add_pulses(pos, 6, k, code);
238 void add_pulses(int16 pos[], int16 nb_pulse, int16 track, int16 code[])
242 for (k = 0; k < nb_pulse; k++)
244 /* i = ((pos[k] & (NB_POS-1))*NB_TRACK) + track; */
245 i = ((pos[k] & (NB_POS - 1)) << 2) + track;
247 if ((pos[k] & NB_POS) == 0)