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.173
     22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2007, 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  Filename: median5.cpp
     35 
     36      Date: 05/08/2007
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41 
     42  Description:
     43 
     44 ------------------------------------------------------------------------------
     45  INPUT AND OUTPUT DEFINITIONS
     46 
     47    INPUT
     48        X[-2:2]   16-bit integers.
     49 
     50    RETURN VALUE
     51        The median of {X[-2], X[-1],..., X[2]}.
     52 
     53 ------------------------------------------------------------------------------
     54  FUNCTION DESCRIPTION
     55 
     56       Returns the median of the set {X[-2], X[-1],..., X[2]},
     57       whose elements are 16-bit integers.
     58 
     59 ------------------------------------------------------------------------------
     60  REQUIREMENTS
     61 
     62 
     63 ------------------------------------------------------------------------------
     64  REFERENCES
     65 
     66 ------------------------------------------------------------------------------
     67  PSEUDO-CODE
     68 
     69 ------------------------------------------------------------------------------
     70 */
     71 
     72 
     73 /*----------------------------------------------------------------------------
     74 ; INCLUDES
     75 ----------------------------------------------------------------------------*/
     76 
     77 #include "pv_amr_wb_type_defs.h"
     78 #include "pvamrwbdecoder_basic_op.h"
     79 #include "pvamrwbdecoder_acelp.h"
     80 #include "pvamrwb_math_op.h"
     81 
     82 /*----------------------------------------------------------------------------
     83 ; MACROS
     84 ; Define module specific macros here
     85 ----------------------------------------------------------------------------*/
     86 
     87 
     88 /*----------------------------------------------------------------------------
     89 ; DEFINES
     90 ; Include all pre-processor statements here. Include conditional
     91 ; compile variables also.
     92 ----------------------------------------------------------------------------*/
     93 
     94 /*----------------------------------------------------------------------------
     95 ; LOCAL FUNCTION DEFINITIONS
     96 ; Function Prototype declaration
     97 ----------------------------------------------------------------------------*/
     98 
     99 /*----------------------------------------------------------------------------
    100 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    101 ; Variable declaration - defined here and used outside this module
    102 ----------------------------------------------------------------------------*/
    103 
    104 /*----------------------------------------------------------------------------
    105 ; EXTERNAL FUNCTION REFERENCES
    106 ; Declare functions defined elsewhere and referenced in this module
    107 ----------------------------------------------------------------------------*/
    108 
    109 /*----------------------------------------------------------------------------
    110 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    111 ; Declare variables used in this module but defined elsewhere
    112 ----------------------------------------------------------------------------*/
    113 
    114 /*----------------------------------------------------------------------------
    115 ; FUNCTION CODE
    116 ----------------------------------------------------------------------------*/
    117 
    118 int16 median5(int16 x[])
    119 {
    120     int16 x1, x2, x3, x4, x5;
    121     int16 tmp;
    122 
    123     x1 = x[-2];
    124     x2 = x[-1];
    125     x3 = x[0];
    126     x4 = x[1];
    127     x5 = x[2];
    128 
    129 
    130 
    131     if (x2 < x1)
    132     {
    133         tmp = x1;
    134         x1 = x2;
    135         x2 = tmp;
    136     }
    137     if (x3 < x1)
    138     {
    139         tmp = x1;
    140         x1 = x3;
    141         x3 = tmp;
    142     }
    143     if (x4 < x1)
    144     {
    145         tmp = x1;
    146         x1 = x4;
    147         x4 = tmp;
    148     }
    149     if (x5 < x1)
    150     {
    151         x5 = x1;
    152     }
    153     if (x3 < x2)
    154     {
    155         tmp = x2;
    156         x2 = x3;
    157         x3 = tmp;
    158     }
    159     if (x4 < x2)
    160     {
    161         tmp = x2;
    162         x2 = x4;
    163         x4 = tmp;
    164     }
    165     if (x5 < x2)
    166     {
    167         x5 = x2;
    168     }
    169     if (x4 < x3)
    170     {
    171         x3 = x4;
    172     }
    173     if (x5 < x3)
    174     {
    175         x3 = x5;
    176     }
    177     return (x3);
    178 }
    179 
    180 
    181