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 (AMR) speech codec
23 Available from http://www.3gpp.org
25 (C) 2004, 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: ets_to_wmf.cpp
37 ------------------------------------------------------------------------------
40 /*----------------------------------------------------------------------------
42 ----------------------------------------------------------------------------*/
43 #include "ets_to_wmf.h"
46 /*----------------------------------------------------------------------------
48 ; Define module specific macros here
49 ----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------
53 ; Include all pre-processor statements here. Include conditional
54 ; compile variables also.
55 ----------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------
59 ; LOCAL FUNCTION DEFINITIONS
60 ; Function Prototype declaration
61 ----------------------------------------------------------------------------*/
63 /*----------------------------------------------------------------------------
64 ; LOCAL VARIABLE DEFINITIONS
65 ; Variable declaration - defined here and used outside this module
66 ----------------------------------------------------------------------------*/
70 ------------------------------------------------------------------------------
71 FUNCTION NAME: ets_to_wmf
72 ------------------------------------------------------------------------------
73 INPUT AND OUTPUT DEFINITIONS
76 frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
77 ets_input_ptr = pointer to input encoded speech bits in ETS format (Word16)
78 wmf_output_ptr = pointer to output encoded speech bits in WMF format(UWord8)
81 wmf_output_ptr = pointer to encoded speech bits in the WMF format (UWord8)
86 Global Variables Used:
87 numOfBits = table of values that describe the number of bits per frame for
88 each 3GPP frame type mode. The table is type const Word16 and has
89 NUM_MODES elements. This table is located in bitreorder_tab.c.
90 reorderBits = table of pointers that point to tables used to reorder the
91 encoded speech bits when converting from ETS to WMF or IF2
92 format. The table is of type const Word16 * and contains
93 NUM_MODES-1 elements. This table is located in bitreorder_tab.c.
95 Local Variables Needed:
98 ------------------------------------------------------------------------------
101 This function performs a transformation on the data buffers. It converts the
102 data format from ETS (European Telecommunication Standard) to WMF (wireless
103 multimedia forum). ETS format has the encoded speech bits each separate with
104 only one bit stored in each word. WMF is the storage format where the frame
105 type is in the first four bits of the first byte. This first byte has the
106 upper four bits as padded zeroes. The following bytes contain the rest of the
107 encoded speech bits. The final byte has padded zeros to make the frame byte
109 ------------------------------------------------------------------------------
114 ------------------------------------------------------------------------------
119 ------------------------------------------------------------------------------
124 ------------------------------------------------------------------------------
126 [State any special notes, constraints or cautions for users of this function]
128 ------------------------------------------------------------------------------
132 enum Frame_Type_3GPP frame_type_3gpp,
133 Word16 *ets_input_ptr,
134 UWord8 *wmf_output_ptr,
135 CommonAmrTbls* common_amr_tbls)
143 const Word16* const* reorderBits_ptr = common_amr_tbls->reorderBits_ptr;
144 const Word16* numOfBits_ptr = common_amr_tbls->numOfBits_ptr;
146 wmf_output_ptr[j++] = (UWord8)(frame_type_3gpp) & 0x0f;
148 if (frame_type_3gpp < AMR_SID)
151 for (i = 0; i < numOfBits_ptr[frame_type_3gpp] - 7;)
154 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 7;
156 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 6;
158 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 5;
160 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 4;
162 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 3;
164 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 2;
166 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 1;
167 wmf_output_ptr[j++] |=
168 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]];
171 bits_left = numOfBits_ptr[frame_type_3gpp] -
172 (numOfBits_ptr[frame_type_3gpp] & 0xFFF8);
174 wmf_output_ptr[j] = 0;
176 for (k = 0; k < bits_left; k++)
179 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << (7 - k);
186 ptr_temp = &ets_input_ptr[0];
188 for (i = numOfBits_ptr[frame_type_3gpp] - 7; i > 0; i -= 8)
190 accum = (UWord8) * (ptr_temp++) << 7;
191 accum |= (UWord8) * (ptr_temp++) << 6;
192 accum |= (UWord8) * (ptr_temp++) << 5;
193 accum |= (UWord8) * (ptr_temp++) << 4;
194 accum |= (UWord8) * (ptr_temp++) << 3;
195 accum |= (UWord8) * (ptr_temp++) << 2;
196 accum |= (UWord8) * (ptr_temp++) << 1;
197 accum |= (UWord8) * (ptr_temp++);
199 wmf_output_ptr[j++] = accum;
202 bits_left = numOfBits_ptr[frame_type_3gpp] -
203 (numOfBits_ptr[frame_type_3gpp] & 0xFFF8);
205 wmf_output_ptr[j] = 0;
207 for (i = 0; i < bits_left; i++)
209 wmf_output_ptr[j] |= *(ptr_temp++) << (7 - i);
219 enum Frame_Type_3GPP frame_type_3gpp,
220 Word16 *ets_input_ptr,
221 UWord8 *ietf_output_ptr,
222 CommonAmrTbls* common_amr_tbls)
230 const Word16* const* reorderBits_ptr = common_amr_tbls->reorderBits_ptr;
231 const Word16* numOfBits_ptr = common_amr_tbls->numOfBits_ptr;
233 ietf_output_ptr[j++] = (UWord8)(frame_type_3gpp << 3);
235 if (frame_type_3gpp < AMR_SID)
237 for (i = 0; i < numOfBits_ptr[frame_type_3gpp] - 7;)
240 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 7;
241 ietf_output_ptr[j] |=
242 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 6;
243 ietf_output_ptr[j] |=
244 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 5;
245 ietf_output_ptr[j] |=
246 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 4;
247 ietf_output_ptr[j] |=
248 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 3;
249 ietf_output_ptr[j] |=
250 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 2;
251 ietf_output_ptr[j] |=
252 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << 1;
253 ietf_output_ptr[j++] |=
254 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]];
257 bits_left = numOfBits_ptr[frame_type_3gpp] -
258 (numOfBits_ptr[frame_type_3gpp] & 0xFFF8);
260 ietf_output_ptr[j] = 0;
262 for (k = 0; k < bits_left; k++)
264 ietf_output_ptr[j] |=
265 (UWord8) ets_input_ptr[reorderBits_ptr[frame_type_3gpp][i++]] << (7 - k);
272 ptr_temp = &ets_input_ptr[0];
274 for (i = numOfBits_ptr[frame_type_3gpp] - 7; i > 0; i -= 8)
276 accum = (UWord8) * (ptr_temp++) << 7;
277 accum |= (UWord8) * (ptr_temp++) << 6;
278 accum |= (UWord8) * (ptr_temp++) << 5;
279 accum |= (UWord8) * (ptr_temp++) << 4;
280 accum |= (UWord8) * (ptr_temp++) << 3;
281 accum |= (UWord8) * (ptr_temp++) << 2;
282 accum |= (UWord8) * (ptr_temp++) << 1;
283 accum |= (UWord8) * (ptr_temp++);
285 ietf_output_ptr[j++] = accum;
288 bits_left = numOfBits_ptr[frame_type_3gpp] -
289 (numOfBits_ptr[frame_type_3gpp] & 0xFFF8);
291 ietf_output_ptr[j] = 0;
293 for (i = 0; i < bits_left; i++)
295 ietf_output_ptr[j] |= *(ptr_temp++) << (7 - i);