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 ------------------------------------------------------------------------------
32 Filename: if2_to_ets.cpp
37 /*----------------------------------------------------------------------------
39 ----------------------------------------------------------------------------*/
40 #include "frame_type_3gpp.h"
41 #include "if2_to_ets.h"
43 /*----------------------------------------------------------------------------
45 ; Define module specific macros here
46 ----------------------------------------------------------------------------*/
48 /*----------------------------------------------------------------------------
50 ; Include all pre-processor statements here. Include conditional
51 ; compile variables also.
52 ----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------
56 ; LOCAL FUNCTION DEFINITIONS
57 ; Function Prototype declaration
58 ----------------------------------------------------------------------------*/
60 /*----------------------------------------------------------------------------
61 ; LOCAL VARIABLE DEFINITIONS
62 ; Variable declaration - defined here and used outside this module
63 ----------------------------------------------------------------------------*/
68 ------------------------------------------------------------------------------
69 FUNCTION NAME: if2_to_ets
70 ------------------------------------------------------------------------------
71 INPUT AND OUTPUT DEFINITIONS
74 frame_type_3gpp = decoder speech bit rate (enum Frame_Type_3GPP)
75 if2_input_ptr = pointer to input encoded speech bits in IF2 format (Word8)
76 ets_output_ptr = pointer to output encoded speech bits in ETS format (Word16)
79 ets_output_ptr = pointer to encoded speech bits in the ETS format (Word16)
84 Global Variables Used:
87 Local Variables Needed:
90 ------------------------------------------------------------------------------
93 This function performs a transformation on the data buffers. It converts the
94 data format from IF2 to ETS. IF2 is the storage format where the frame type
95 is in the first four bits of the first byte. The upper four bits of that byte
96 contain the first four encoded speech bits for the frame. The following bytes
97 contain the rest of the encoded speech bits. The final byte has padded zeros
98 to make the frame byte aligned. ETS format has the encoded speech
99 bits each separate with only one bit stored in each word.
101 ------------------------------------------------------------------------------
106 ------------------------------------------------------------------------------
109 AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
111 ------------------------------------------------------------------------------
116 ------------------------------------------------------------------------------
118 [State any special notes, constraints or cautions for users of this function]
120 ------------------------------------------------------------------------------
124 enum Frame_Type_3GPP frame_type_3gpp,
125 UWord8 *if2_input_ptr,
126 Word16 *ets_output_ptr,
127 CommonAmrTbls* common_amr_tbls)
133 const Word16* numCompressedBytes_ptr = common_amr_tbls->numCompressedBytes_ptr;
134 const Word16* numOfBits_ptr = common_amr_tbls->numOfBits_ptr;
135 const Word16* const* reorderBits_ptr = common_amr_tbls->reorderBits_ptr;
138 * The following section of code accesses bits in the IF2 method of
139 * bit ordering. Each bit is given its own location in the buffer pointed
140 * to by ets_output_ptr. The bits (for modes less than AMR_SID) are
141 * reordered using the tables in bitreorder.c before the data is stored
142 * into the buffer pointed to by ets_output_ptr.
145 if (frame_type_3gpp < AMR_SID)
147 for (j = 4; j < 8; j++)
149 ets_output_ptr[reorderBits_ptr[frame_type_3gpp][x++]] =
150 (if2_input_ptr[0] >> j) & 0x01;
152 for (i = 1; i < numCompressedBytes_ptr[frame_type_3gpp]; i++)
154 for (j = 0; j < 8; j++)
156 if (x >= numOfBits_ptr[frame_type_3gpp])
160 ets_output_ptr[reorderBits_ptr[frame_type_3gpp][x++]] =
161 (if2_input_ptr[i] >> j) & 0x01;
167 for (j = 4; j < 8; j++)
169 ets_output_ptr[x++] =
170 (if2_input_ptr[0] >> j) & 0x01;
172 for (i = 1; i < numCompressedBytes_ptr[frame_type_3gpp]; i++)
174 for (j = 0; j < 8; j++)
176 ets_output_ptr[x++] =
177 (if2_input_ptr[i] >> j) & 0x01;