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/wmf_to_ets.c
35 Funtions: wmf_to_ets
36
37 Date: 01/21/2002
38
39 ------------------------------------------------------------------------------
40 REVISION HISTORY
41
42 Description: Changing mode to frame_type_3gpp for DTX support. Modifying for
43 loops for optimized code. Updating as per review comments.
44
45 Description: Changed MRDTX to AMR_SID in the code and added bitreorder_tab.h
46 in the Include section.
47
48 Description:
49
50 ------------------------------------------------------------------------------
51 */
52
53 /*----------------------------------------------------------------------------
54 ; INCLUDES
55 ----------------------------------------------------------------------------*/
56 #include "frame_type_3gpp.h"
57 #include "wmf_to_ets.h"
58 #include "typedef.h"
59 #include "bitreorder_tab.h"
60 /*----------------------------------------------------------------------------
61 ; MACROS
62 ; Define module specific macros here
63 ----------------------------------------------------------------------------*/
64
65 /*----------------------------------------------------------------------------
66 ; DEFINES
67 ; Include all pre-processor statements here. Include conditional
68 ; compile variables also.
69 ----------------------------------------------------------------------------*/
70
71
72 /*----------------------------------------------------------------------------
73 ; LOCAL FUNCTION DEFINITIONS
74 ; Function Prototype declaration
75 ----------------------------------------------------------------------------*/
76
77 /*----------------------------------------------------------------------------
78 ; LOCAL VARIABLE DEFINITIONS
79 ; Variable declaration - defined here and used outside this module
80 ----------------------------------------------------------------------------*/
81
82
83
84 /*
85 ------------------------------------------------------------------------------
86 FUNCTION NAME: wmf_to_ets
87 ------------------------------------------------------------------------------
88 INPUT AND OUTPUT DEFINITIONS
89
90 Inputs:
91 frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
92 wmf_input_ptr = pointer to input encoded speech bits in WMF (non-IF2) format
93 (Word8)
94 ets_output_ptr = pointer to output encoded speech bits in ETS format (Word16)
95
96 Outputs:
97 ets_output_ptr = pointer to encoded speech bits in the ETS format (Word16)
98
99 Returns:
100 None
101
102 Global Variables Used:
103 None
104
105 Local Variables Needed:
106 None
107
108 ------------------------------------------------------------------------------
109 FUNCTION DESCRIPTION
110
111 This function performs a transformation on the data buffers. It converts the
112 data format from WMF (non-IF2) (Wireless Multi-media Forum) to ETS (European
113 Telecommunication Standard). WMF format has the encoded speech bits byte
114 aligned with MSB to LSB going left to right. ETS format has the encoded speech
115 bits each separate with only one bit stored in each word.
116
117 ------------------------------------------------------------------------------
118 REQUIREMENTS
119
120 None
121
122 ------------------------------------------------------------------------------
123 REFERENCES
124
125 AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
126
127 ------------------------------------------------------------------------------
128 PSEUDO-CODE
129
130
131
132 ------------------------------------------------------------------------------
133 RESOURCES USED [optional]
134
135 When the code is written for a specific target processor the
136 the resources used should be documented below.
137
138 HEAP MEMORY USED: x bytes
139
140 STACK MEMORY USED: x bytes
141
142 CLOCK CYCLES: (cycle count equation for this function) + (variable
143 used to represent cycle count for each subroutine
144 called)
145 where: (cycle count variable) = cycle count for [subroutine
146 name]
147
148 ------------------------------------------------------------------------------
149 CAUTION [optional]
150 [State any special notes, constraints or cautions for users of this function]
151
152 ------------------------------------------------------------------------------
153 */
154
wmf_to_ets(enum Frame_Type_3GPP frame_type_3gpp,UWord8 * wmf_input_ptr,Word16 * ets_output_ptr)155 void wmf_to_ets(
156 enum Frame_Type_3GPP frame_type_3gpp,
157 UWord8 *wmf_input_ptr,
158 Word16 *ets_output_ptr)
159 {
160
161 Word16 i;
162
163 /*
164 * The following section of code accesses bits in the WMF method of
165 * bit ordering. Each bit is given its own location in the buffer pointed
166 * to by ets_output_ptr. If the frame_type_3gpp is less than MRDTX then
167 * the elements are reordered within the buffer pointed to by ets_output_ptr.
168 */
169
170 if (frame_type_3gpp < AMR_SID)
171 {
172 /* The table numOfBits[] can be found in bitreorder.c. */
173 for (i = numOfBits[frame_type_3gpp] - 1; i >= 0; i--)
174 {
175 /* The table reorderBits[][] can be found in bitreorder.c. */
176 ets_output_ptr[reorderBits[frame_type_3gpp][i]] =
177 (wmf_input_ptr[i>>3] >> ((~i) & 0x7)) & 0x01;
178 }
179 }
180 else
181 {
182 /* The table numOfBits[] can be found in bitreorder.c. */
183 for (i = numOfBits[frame_type_3gpp] - 1; i >= 0; i--)
184 {
185 ets_output_ptr[i] = (wmf_input_ptr[i>>3] >> ((~i) & 0x7)) & 0x01;
186 }
187 }
188
189 return;
190 }
191