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