• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20 
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24 
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 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31 
32 
33 
34  Pathname: ./audio/gsm-amr/c/src/ets_to_wmf.c
35  Funtions: ets_to_wmf
36 
37      Date: 01/23/2002
38 
39 ------------------------------------------------------------------------------
40  REVISION HISTORY
41 
42  Description: Modified code as per review comments regarding things such as
43               adding the tables in bitreorder_tab.c to the Global section of
44               the input/output section of the template and removing the #define
45               of 244 since it wasn't needed in this function.
46 
47  Description: Fixed the loop that packs the last octet of the WMF output.
48 
49  Description:  Replaced "int" and/or "char" with OSCL defined types.
50 
51  Description:
52 
53 ------------------------------------------------------------------------------
54 */
55 
56 /*----------------------------------------------------------------------------
57 ; INCLUDES
58 ----------------------------------------------------------------------------*/
59 #include "ets_to_wmf.h"
60 #include "typedef.h"
61 #include "bitreorder_tab.h"
62 
63 /*----------------------------------------------------------------------------
64 ; MACROS
65 ; Define module specific macros here
66 ----------------------------------------------------------------------------*/
67 
68 /*----------------------------------------------------------------------------
69 ; DEFINES
70 ; Include all pre-processor statements here. Include conditional
71 ; compile variables also.
72 ----------------------------------------------------------------------------*/
73 
74 
75 /*----------------------------------------------------------------------------
76 ; LOCAL FUNCTION DEFINITIONS
77 ; Function Prototype declaration
78 ----------------------------------------------------------------------------*/
79 
80 /*----------------------------------------------------------------------------
81 ; LOCAL VARIABLE DEFINITIONS
82 ; Variable declaration - defined here and used outside this module
83 ----------------------------------------------------------------------------*/
84 
85 
86 /*
87 ------------------------------------------------------------------------------
88  FUNCTION NAME: ets_to_wmf
89 ------------------------------------------------------------------------------
90  INPUT AND OUTPUT DEFINITIONS
91 
92  Inputs:
93     frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
94     ets_input_ptr   = pointer to input encoded speech bits in ETS format (Word16)
95     wmf_output_ptr  = pointer to output encoded speech bits in WMF format(UWord8)
96 
97  Outputs:
98     wmf_output_ptr  = pointer to encoded speech bits in the WMF format (UWord8)
99 
100  Returns:
101     None
102 
103  Global Variables Used:
104     numOfBits = table of values that describe the number of bits per frame for
105                 each 3GPP frame type mode. The table is type const Word16 and has
106                 NUM_MODES elements. This table is located in bitreorder_tab.c.
107     reorderBits = table of pointers that point to tables used to reorder the
108                   encoded speech bits when converting from ETS to WMF or IF2
109                   format. The table is of type const Word16 * and contains
110                   NUM_MODES-1 elements. This table is located in bitreorder_tab.c.
111 
112  Local Variables Needed:
113     None
114 
115 ------------------------------------------------------------------------------
116  FUNCTION DESCRIPTION
117 
118  This function performs a transformation on the data buffers. It converts the
119  data format from ETS (European Telecommunication Standard) to WMF (wireless
120  multimedia forum). ETS format has the encoded speech bits each separate with
121  only one bit stored in each word. WMF is the storage format where the frame
122  type is in the first four bits of the first byte. This first byte has the
123  upper four bits as padded zeroes. The following bytes contain the rest of the
124  encoded speech bits. The final byte has padded zeros to make the frame byte
125  aligned.
126 ------------------------------------------------------------------------------
127  REQUIREMENTS
128 
129  None
130 
131 ------------------------------------------------------------------------------
132  REFERENCES
133 
134  None
135 
136 ------------------------------------------------------------------------------
137  PSEUDO-CODE
138 
139 
140 
141 ------------------------------------------------------------------------------
142  RESOURCES USED [optional]
143 
144  When the code is written for a specific target processor the
145  the resources used should be documented below.
146 
147  HEAP MEMORY USED: x bytes
148 
149  STACK MEMORY USED: x bytes
150 
151  CLOCK CYCLES: (cycle count equation for this function) + (variable
152                 used to represent cycle count for each subroutine
153                 called)
154      where: (cycle count variable) = cycle count for [subroutine
155                                      name]
156 
157 ------------------------------------------------------------------------------
158  CAUTION [optional]
159  [State any special notes, constraints or cautions for users of this function]
160 
161 ------------------------------------------------------------------------------
162 */
163 
ets_to_wmf(enum Frame_Type_3GPP frame_type_3gpp,Word16 * ets_input_ptr,UWord8 * wmf_output_ptr)164 void ets_to_wmf(
165     enum Frame_Type_3GPP frame_type_3gpp,
166     Word16 *ets_input_ptr,
167     UWord8 *wmf_output_ptr)
168 {
169     Word16  i;
170     Word16  k = 0;
171     Word16  j = 0;
172     Word16 *ptr_temp;
173     Word16  bits_left;
174     UWord8  accum;
175 
176     if (frame_type_3gpp < AMR_SID)
177     {
178         wmf_output_ptr[j++] = (UWord8)(frame_type_3gpp) & 0x0f;
179 
180         for (i = 0; i < numOfBits[frame_type_3gpp] - 7;)
181         {
182             wmf_output_ptr[j]  =
183                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 7;
184             wmf_output_ptr[j] |=
185                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 6;
186             wmf_output_ptr[j] |=
187                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 5;
188             wmf_output_ptr[j] |=
189                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 4;
190             wmf_output_ptr[j] |=
191                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 3;
192             wmf_output_ptr[j] |=
193                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 2;
194             wmf_output_ptr[j] |=
195                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << 1;
196             wmf_output_ptr[j++] |=
197                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]];
198         }
199 
200         bits_left = numOfBits[frame_type_3gpp] -
201                     (numOfBits[frame_type_3gpp] & 0xFFF8);
202 
203         wmf_output_ptr[j] = 0;
204 
205         for (k = 0; k < bits_left; k++)
206         {
207             wmf_output_ptr[j] |=
208                 (UWord8) ets_input_ptr[reorderBits[frame_type_3gpp][i++]] << (7 - k);
209 
210         }
211     }
212     else
213     {
214         wmf_output_ptr[j++] = (UWord8)(frame_type_3gpp) & 0x0f;
215 
216         ptr_temp = &ets_input_ptr[0];
217 
218         for (i = numOfBits[frame_type_3gpp] - 7; i > 0; i -= 8)
219         {
220             accum  = (UWord8) * (ptr_temp++) << 7;
221             accum |= (UWord8) * (ptr_temp++) << 6;
222             accum |= (UWord8) * (ptr_temp++) << 5;
223             accum |= (UWord8) * (ptr_temp++) << 4;
224             accum |= (UWord8) * (ptr_temp++) << 3;
225             accum |= (UWord8) * (ptr_temp++) << 2;
226             accum |= (UWord8) * (ptr_temp++) << 1;
227             accum |= (UWord8) * (ptr_temp++);
228 
229             wmf_output_ptr[j++] = accum;
230         }
231 
232         bits_left = numOfBits[frame_type_3gpp] -
233                     (numOfBits[frame_type_3gpp] & 0xFFF8);
234 
235         wmf_output_ptr[j] = 0;
236 
237         for (i = 0; i < bits_left; i++)
238         {
239             wmf_output_ptr[j] |= *(ptr_temp++) << (7 - i);
240         }
241     }
242 
243     return;
244 }
245