14f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/* ------------------------------------------------------------------
24f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * Copyright (C) 1998-2009 PacketVideo
34f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber *
44f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
54f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * you may not use this file except in compliance with the License.
64f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * You may obtain a copy of the License at
74f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber *
84f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
94f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber *
104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * Unless required by applicable law or agreed to in writing, software
114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * express or implied.
144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * See the License for the specific language governing permissions
154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * and limitations under the License.
164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber * -------------------------------------------------------------------
174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber */
184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/****************************************************************************************
194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas HuberPortions of this file are derived from the following 3GPP standard:
204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    3GPP TS 26.073
224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Available from http://www.3gpp.org
244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas HuberPermission to distribute, modify and use this file under the standard license
274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberterms listed above has been obtained from the copyright holder.
284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber****************************************************************************************/
294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Pathname: ./audio/gsm-amr/c/src/vad1.c
314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Functions:
324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REVISION HISTORY
354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Description: Updated template used to PV coding template.
374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Changed to accept the pOverflow flag for EPOC compatibility.
384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Description: Made changes per review comments
404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber (1) Removed include of "count.h"
414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber (2) Replaced "basic_op.h" with individual include files
424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber (3) Removed some unnecessary instances of sub().
434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Description:  Replaced OSCL mem type functions and eliminated include
454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber               files that now are chosen by OSCL definitions
464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Description:  Replaced "int" and/or "char" with OSCL defined types.
484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Description: Changed round function name to pv_round to avoid conflict with
504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              round function in C standard library.
514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Who:                           Date:
534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Description:
544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber MODULE DESCRIPTION
574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*----------------------------------------------------------------------------
634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; INCLUDES
644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber----------------------------------------------------------------------------*/
654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include <stdlib.h>
674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include <string.h>
684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include "vad.h"
704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include "typedef.h"
714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include "shr.h"
724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include "basic_op.h"
734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber#include "cnst_vad.h"
744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*----------------------------------------------------------------------------
764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; MACROS
774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; Define module specific macros here
784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber----------------------------------------------------------------------------*/
794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*----------------------------------------------------------------------------
814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; DEFINES
824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; Include all pre-processor statements here. Include conditional
834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; compile variables also.
844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber----------------------------------------------------------------------------*/
854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*----------------------------------------------------------------------------
874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; LOCAL FUNCTION DEFINITIONS
884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; Function Prototype declaration
894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber----------------------------------------------------------------------------*/
904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*----------------------------------------------------------------------------
924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; LOCAL VARIABLE DEFINITIONS
934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber; Variable declaration - defined here and used outside this module
944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber----------------------------------------------------------------------------*/
954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: first_filter_stage
994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
1014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
1034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- filter memory
1044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in   -- array of type Word16 -- input signal
1054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
1074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- filter memory
1084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    out  -- array of type Word16 -- output values, every other
1094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                    output is low-pass part and
1104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                    other is high-pass part every
1114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
1134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
1154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
1164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
1184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
1194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
1214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
1224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
1254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : Scale input down by one bit. Calculate 5th order
1274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                half-band lowpass/highpass filter pair with
1284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                decimation.
1294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
1314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
1334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
1364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
1384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
1414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
1454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
1474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
1484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
1504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
1524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
1544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
1554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
1564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
1574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
1584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
1614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
1624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
1644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
1654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void first_filter_stage(
1674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 in[],      /* i   : input signal                  */
1684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 out[],     /* o   : output values, every other    */
1694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /*       output is low-pass part and   */
1704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /*       other is high-pass part every */
1714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 data[],    /* i/o : filter memory                 */
1724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow  /* o : Flag set when overflow occurs   */
1734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
1744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
1754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp0;
1764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp1;
1774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp2;
1784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp3;
1794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 i;
1804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 data0;
1814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 data1;
1824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data0 = data[0];
1844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data1 = data[1];
1854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < FRAME_LEN / 4; i++)
1874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
1884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp0 = mult(COEFF5_1, data0, pOverflow);
1894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp1 = shr(in[4*i+0], 2, pOverflow);
1904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp0 = sub(temp1, temp0, pOverflow);
1914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp1 = mult(COEFF5_1, temp0, pOverflow);
1934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp1 = add(data0, temp1, pOverflow);
1944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp3 = mult(COEFF5_2, data1, pOverflow);
1964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = shr(in[4*i+1], 2, pOverflow);
1974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
1984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp3 = sub(temp2, temp3, pOverflow);
1994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = mult(COEFF5_2, temp3, pOverflow);
2014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = add(data1, temp2, pOverflow);
2024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        out[4*i+0] = add(temp1, temp2, pOverflow);
2044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        out[4*i+1] = sub(temp1, temp2, pOverflow);
2054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp1 = mult(COEFF5_1, temp0, pOverflow);
2074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = shr(in[4*i+2], 2, pOverflow);
2084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        data0 = sub(temp2, temp1, pOverflow);
2094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp1 = mult(COEFF5_1, data0, pOverflow);
2114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp1 = add(temp0, temp1, pOverflow);
2124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        data1 = mult(COEFF5_2, temp3, pOverflow);
2144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = shr(in[4*i+3], 2, pOverflow);
2154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        data1 = sub(temp2, data1, pOverflow);
2164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = mult(COEFF5_2, data1, pOverflow);
2184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp2 = add(temp3, temp2, pOverflow);
2194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        out[4*i+2] = add(temp1, temp2, pOverflow);
2214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        out[4*i+3] = sub(temp1, temp2, pOverflow);
2224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
2234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data[0] = data0;
2254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data[1] = data1;
2264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
2274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
2304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: filter5
2324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
2344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
2364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in0 -- array of type Word16 -- input values; output low-pass part
2374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in1 -- array of type Word16 -- input values; output high-pass part
2384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- updated filter memory
2394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
2414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in0 -- array of type Word16 -- input values; output low-pass part
2424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in1 -- array of type Word16 -- input values; output high-pass part
2434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- updated filter memory
2444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
2454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
2474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
2484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
2504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
2514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
2534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
2544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
2574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : Fifth-order half-band lowpass/highpass filter pair with
2594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                decimation.
2604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
2624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
2644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
2674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
2694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
2724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
2764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
2784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
2794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
2814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
2834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
2854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
2864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
2874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
2884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
2894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
2924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
2934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
2954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
2964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
2974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void filter5(Word16 *in0,    /* i/o : input values; output low-pass part  */
2984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    Word16 *in1,    /* i/o : input values; output high-pass part */
2994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    Word16 data[],  /* i/o : updated filter memory               */
3004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    Flag  *pOverflow  /* o : Flag set when overflow occurs       */
3014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                   )
3024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
3034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp0;
3044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp1;
3054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp2;
3064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp0 = mult(COEFF5_1, data[0], pOverflow);
3084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp0 = sub(*in0, temp0, pOverflow);
3094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp1 = mult(COEFF5_1, temp0, pOverflow);
3114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp1 = add(data[0], temp1, pOverflow);
3124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data[0] = temp0;
3134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp0 = mult(COEFF5_2, data[1], pOverflow);
3154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp0 = sub(*in1, temp0, pOverflow);
3164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp2 = mult(COEFF5_2, temp0, pOverflow);
3184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp2 = add(data[1], temp2, pOverflow);
3194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data[1] = temp0;
3214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp0 = add(temp1, temp2, pOverflow);
3234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    *in0 = shr(temp0, 1, pOverflow);
3244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp0 = sub(temp1, temp2, pOverflow);
3264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    *in1 = shr(temp0, 1, pOverflow);
3274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
3284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
3334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: filter3
3354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
3374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
3404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in0 -- array of type Word16 -- input values; output low-pass part
3414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in1 -- array of type Word16 -- input values; output high-pass part
3424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- updated filter memory
3434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
3454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in0 -- array of type Word16 -- input values; output low-pass part
3464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in1 -- array of type Word16 -- input values; output high-pass part
3474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- updated filter memory
3484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
3494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
3514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
3524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
3544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
3554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
3574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
3584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
3614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : Third-order half-band lowpass/highpass filter pair with
3634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                decimation.
3644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
3664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
3684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
3714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
3734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
3764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
3804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
3824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
3834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
3854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
3874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
3894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
3904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
3914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
3924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
3934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
3964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
3974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
3984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
3994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
4004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void filter3(
4024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 *in0,      /* i/o : input values; output low-pass part  */
4034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 *in1,      /* i/o : input values; output high-pass part */
4044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 *data,     /* i/o : updated filter memory               */
4054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow  /* o : Flag set when overflow occurs         */
4064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
4074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
4084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp1;
4094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp2;
4104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp1 = mult(COEFF3, *data, pOverflow);
4124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp1 = sub(*in1, temp1, pOverflow);
4134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp2 = mult(COEFF3, temp1, pOverflow);
4154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp2 = add(*data, temp2, pOverflow);
4164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    *data = temp1;
4184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp1 = sub(*in0, temp2, pOverflow);
4204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    *in1 = shr(temp1, 1, pOverflow);
4224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    temp1 = add(*in0, temp2, pOverflow);
4244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    *in0 = shr(temp1, 1, pOverflow);
4264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
4274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
4324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: level_calculation
4344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
4364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
4384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    data -- array of type Word16 -- signal buffer
4394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    sub_level -- pointer to type Word16 -- level calculated at the end of
4404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                           the previous frame
4414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    count1 -- Word16 -- number of samples to be counted
4434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    count2 -- Word16 -- number of samples to be counted
4444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    ind_m  -- Word16 -- step size for the index of the data buffer
4454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    ind_a  -- Word16 -- starting index of the data buffer
4464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    scale  -- Word16 -- scaling for the level calculation
4474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
4494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    sub_level -- pointer to tyep Word16 -- level of signal calculated from the
4504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                           last (count2 - count1) samples.
4514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
4524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
4544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    signal level
4554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
4574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
4604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
4614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
4644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : Calculate signal level in a sub-band. Level is calculated
4664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                by summing absolute values of the input data.
4674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
4704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
4724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
4754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
4774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
4804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
4844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
4864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
4874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
4894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
4914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
4934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
4944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
4954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
4964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
4974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
4984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
4994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
5004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
5014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
5044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic Word16 level_calculation(
5064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 data[],     /* i   : signal buffer                                */
5074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 *sub_level, /* i   : level calculate at the end of                */
5084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /*       the previous frame                           */
5094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* o   : level of signal calculated from the last     */
5104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /*       (count2 - count1) samples                    */
5114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 count1,     /* i   : number of samples to be counted              */
5124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 count2,     /* i   : number of samples to be counted              */
5134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 ind_m,      /* i   : step size for the index of the data buffer   */
5144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 ind_a,      /* i   : starting index of the data buffer            */
5154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 scale,      /* i   : scaling for the level calculation            */
5164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow   /* o : Flag set when overflow occurs                  */
5174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
5184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
5194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word32 l_temp1;
5204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word32 l_temp2;
5214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 level;
5224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 i;
5234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    l_temp1 = 0L;
5254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = count1; i < count2; i++)
5274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
5284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        l_temp1 = L_mac(l_temp1, 1, abs_s(data[ind_m*i+ind_a]), pOverflow);
5294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
5304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    l_temp2 = L_add(l_temp1, L_shl(*sub_level, sub(16, scale, pOverflow), pOverflow), pOverflow);
5324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    *sub_level = extract_h(L_shl(l_temp1, scale, pOverflow));
5334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < count1; i++)
5354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
5364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        l_temp2 = L_mac(l_temp2, 1, abs_s(data[ind_m*i+ind_a]), pOverflow);
5374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
5384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level = extract_h(L_shl(l_temp2, scale, pOverflow));
5394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    return level;
5414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
5424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
5474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: filter_bank
5494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
5514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
5534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
5544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    in -- array of type Word16 -- input frame
5554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
5574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level -- array of type Word16 -- signal levels at each band
5584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
5594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
5604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
5624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
5634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
5654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
5664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
5684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
5694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
5724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : Divides input signal into 9-bands and calculas level of
5744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                the signal in each band
5754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
5784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
5804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
5834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
5854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
5884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
5914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
5924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
5944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
5954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
5974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
5984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
5994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
6014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
6024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
6034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
6044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
6054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
6074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
6084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
6094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
6114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
6124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void filter_bank(
6144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    vadState1 *st,    /* i/o : State struct                    */
6154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 in[],      /* i   : input frame                     */
6164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 level[],   /* 0   : signal levels at each band      */
6174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow  /* o   : Flag set when overflow occurs   */
6184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
6194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
6204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 i;
6214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 tmp_buf[FRAME_LEN];
6224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* calculate the filter bank */
6244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    first_filter_stage(in, tmp_buf, st->a_data5[0], pOverflow);
6264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < FRAME_LEN / 4; i++)
6284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
6294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter5(&tmp_buf[4*i], &tmp_buf[4*i+2], st->a_data5[1], pOverflow);
6304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter5(&tmp_buf[4*i+1], &tmp_buf[4*i+3], st->a_data5[2], pOverflow);
6314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
6324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < FRAME_LEN / 8; i++)
6334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
6344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter3(&tmp_buf[8*i+0], &tmp_buf[8*i+4], &st->a_data3[0], pOverflow);
6354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter3(&tmp_buf[8*i+2], &tmp_buf[8*i+6], &st->a_data3[1], pOverflow);
6364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter3(&tmp_buf[8*i+3], &tmp_buf[8*i+7], &st->a_data3[4], pOverflow);
6374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
6384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < FRAME_LEN / 16; i++)
6404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
6414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[2], pOverflow);
6424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[3], pOverflow);
6434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
6444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* calculate levels in each frequency band */
6464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 3000 - 4000 Hz*/
6484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN / 4 - 8,
6494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 4, 4, 1, 15, pOverflow);
6504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 2500 - 3000 Hz*/
6514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN / 8 - 4,
6524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 8, 8, 7, 16, pOverflow);
6534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 2000 - 2500 Hz*/
6544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN / 8 - 4,
6554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 8, 8, 3, 16, pOverflow);
6564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 1500 - 2000 Hz*/
6574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN / 8 - 4,
6584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 8, 8, 2, 16, pOverflow);
6594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 1000 - 1500 Hz*/
6604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN / 8 - 4,
6614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 8, 8, 6, 16, pOverflow);
6624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 750 - 1000 Hz*/
6634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN / 16 - 2,
6644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 16, 16, 4, 16, pOverflow);
6654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 500 - 750 Hz*/
6664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN / 16 - 2,
6674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 16, 16, 12, 16, pOverflow);
6684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 250 - 500 Hz*/
6694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN / 16 - 2,
6704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 16, 16, 8, 16, pOverflow);
6714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* 0 - 250 Hz*/
6724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN / 16 - 2,
6734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                 FRAME_LEN / 16, 16, 0, 16, pOverflow);
6744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
6754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
6794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
6804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: update_cntrl
6814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
6824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
6834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
6854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
6864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level -- array of type Word16 -- sub-band levels of the input frame
6874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
6894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
6904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
6914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
6934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
6944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
6964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
6974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
6984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
6994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
7004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
7034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose    : Control update of the background noise estimate.
7054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs     : pitch:      flags for pitch detection
7064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              stat_count: stationary counter
7074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              tone:       flags indicating presence of a tone
7084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              complex:      flags for complex  detection
7094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              vadreg:     intermediate VAD flags
7104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Output     : stat_count: stationary counter
7114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
7154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
7174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
7204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
7224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
7254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
7294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
7314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
7324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
7344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
7364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
7384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
7394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
7404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
7414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
7424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
7454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
7464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
7484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
7494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void update_cntrl(
7514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    vadState1 *st,   /* i/o : State struct                       */
7524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 level[],  /* i   : sub-band levels of the input frame */
7534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow /* o   : Flag set when overflow occurs      */
7544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
7554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
7564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 i;
7574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 temp;
7584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 stat_rat;
7594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 exp;
7604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 num;
7614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 denom;
7624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 alpha;
7634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* handle highband complex signal input  separately       */
7654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* if ther has been highband correlation for some time    */
7664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* make sure that the VAD update speed is low for a while */
7674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->complex_warning != 0)
7684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
7694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->stat_count < CAD_MIN_STAT_COUNT)
7704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
7714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->stat_count = CAD_MIN_STAT_COUNT;
7724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
7734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
7744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* NB stat_count is allowed to be decreased by one below again  */
7754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* deadlock in speech is not possible unless the signal is very */
7764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* complex and need a high rate                                 */
7774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
7784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* if fullband pitch or tone have been detected for a while, initialize stat_count */
7794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (((Word16)(st->pitch & 0x6000) == 0x6000) ||
7804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            ((Word16)(st->tone & 0x7c00) == 0x7c00))
7814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
7824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->stat_count = STAT_COUNT;
7834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
7844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else
7854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
7864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        /* if 8 last vad-decisions have been "0", reinitialize stat_count */
7874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if ((st->vadreg & 0x7f80) == 0)
7884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
7894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->stat_count = STAT_COUNT;
7904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
7914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        else
7924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
7934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            stat_rat = 0;
7944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            for (i = 0; i < COMPLEN; i++)
7954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            {
7964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                if (level[i] > st->ave_level[i])
7974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                {
7984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    num = level[i];
7994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    denom = st->ave_level[i];
8004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                }
8014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                else
8024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                {
8034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    num = st->ave_level[i];
8044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    denom = level[i];
8054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                }
8064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                /* Limit nimimum value of num and denom to STAT_THR_LEVEL */
8074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                if (num < STAT_THR_LEVEL)
8084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                {
8094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    num = STAT_THR_LEVEL;
8104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                }
8114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                if (denom < STAT_THR_LEVEL)
8124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                {
8134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    denom = STAT_THR_LEVEL;
8144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                }
8154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                exp = norm_s(denom);
8174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                denom = shl(denom, exp, pOverflow);
8194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                /* stat_rat = num/denom * 64 */
8214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                temp = shr(num, 1, pOverflow);
8224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                temp = div_s(temp, denom);
8234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                stat_rat = add(stat_rat, shr(temp, sub(8, exp, pOverflow), pOverflow), pOverflow);
8254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            }
8264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            /* compare stat_rat with a threshold and update stat_count */
8284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            if (stat_rat > STAT_THR)
8294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            {
8304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                st->stat_count = STAT_COUNT;
8314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            }
8324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            else
8334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            {
8344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                if ((st->vadreg & 0x4000) != 0)
8354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                {
8364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    if (st->stat_count != 0)
8374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    {
8384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                        st->stat_count = sub(st->stat_count, 1, pOverflow);
8394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                    }
8404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                }
8414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            }
8424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
8434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
8444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* Update average amplitude estimate for stationarity estimation */
8464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    alpha = ALPHA4;
8474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->stat_count == STAT_COUNT)
8484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
8494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        alpha = 32767;
8504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
8514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else if ((st->vadreg & 0x4000) == 0)
8524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
8534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        alpha = ALPHA5;
8544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
8554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < COMPLEN; i++)
8574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
8584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp = sub(level[i], st->ave_level[i], pOverflow);
8594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp = mult_r(alpha, temp, pOverflow);
8604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->ave_level[i] =
8624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            add(
8634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                st->ave_level[i],
8644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                temp,
8654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                pOverflow);
8664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
8674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
8684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
8724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
8734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: hangover_addition
8744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
8754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
8764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
8784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    noise_level -- Word16 -- average level of the noise estimates
8794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    low_power   -- Word16 -- flag power of the input frame
8804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
8824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
8834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicato
8844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
8864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    VAD_flag indicating final VAD decision (Word16)
8874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
8894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
8904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
8924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
8934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
8954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
8964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
8974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Function     : hangover_addition
8984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : Add hangover for complex signal or after speech bursts
8994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs       : burst_count:  counter for the length of speech bursts
9004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                hang_count:   hangover counter
9014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                vadreg:       intermediate VAD decision
9024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs      : burst_count:  counter for the length of speech bursts
9034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                hang_count:   hangover counter
9044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Return value : VAD_flag indicating final VAD decision
9054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
9084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
9094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
9114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
9134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
9144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
9164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
9184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
9194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
9224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
9234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
9254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
9264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
9284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
9304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
9324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
9334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
9344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
9354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
9364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
9384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
9394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
9404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
9424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
9434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic Word16 hangover_addition(
9454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    vadState1 *st,      /* i/o : State struct                     */
9464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 noise_level, /* i   : average level of the noise       */
9474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /*       estimates                        */
9484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 low_power,   /* i   : flag power of the input frame    */
9494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow    /* o   : Flag set when overflow occurs    */
9504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
9514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
9524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 hang_len;
9534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 burst_len;
9544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /*
9564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber       Calculate burst_len and hang_len
9574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber       burst_len: number of consecutive intermediate vad flags with "1"-decision
9584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                  required for hangover addition
9594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber       hang_len:  length of the hangover
9604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber       */
9614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (noise_level > HANG_NOISE_THR)
9634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
9644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        burst_len = BURST_LEN_HIGH_NOISE;
9654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        hang_len = HANG_LEN_HIGH_NOISE;
9664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
9674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else
9684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
9694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        burst_len = BURST_LEN_LOW_NOISE;
9704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        hang_len = HANG_LEN_LOW_NOISE;
9714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
9724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* if the input power (pow_sum) is lower than a threshold, clear
9744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber       counters and set VAD_flag to "0"  "fast exit"                 */
9754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (low_power != 0)
9764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
9774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->burst_count = 0;
9784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->hang_count = 0;
9794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->complex_hang_count = 0;
9804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->complex_hang_timer = 0;
9814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        return 0;
9824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
9834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->complex_hang_timer > CVAD_HANG_LIMIT)
9854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
9864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->complex_hang_count < CVAD_HANG_LENGTH)
9874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
9884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->complex_hang_count = CVAD_HANG_LENGTH;
9894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
9904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
9914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
9924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* long time very complex signal override VAD output function */
9934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->complex_hang_count != 0)
9944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
9954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->burst_count = BURST_LEN_HIGH_NOISE;
9964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->complex_hang_count = sub(st->complex_hang_count, 1, pOverflow);
9974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        return 1;
9984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
9994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else
10004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
10014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        /* let hp_corr work in from a noise_period indicated by the VAD */
10024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (((st->vadreg & 0x3ff0) == 0) &&
10034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                (st->corr_hp_fast > CVAD_THRESH_IN_NOISE))
10044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
10054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            return 1;
10064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
10074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
10084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* update the counters (hang_count, burst_count) */
10104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if ((st->vadreg & 0x4000) != 0)
10114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
10124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->burst_count = add(st->burst_count, 1, pOverflow);
10134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->burst_count >= burst_len)
10154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
10164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->hang_count = hang_len;
10174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
10184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        return 1;
10194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
10204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else
10214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
10224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->burst_count = 0;
10234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->hang_count > 0)
10244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
10254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->hang_count = sub(st->hang_count, 1, pOverflow);
10264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            return 1;
10274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
10284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
10294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    return 0;
10304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
10314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
10354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: noise_estimate_update
10374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
10394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
10414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
10424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    level -- array of type Word16 -- sub-band levels of the input frame
10434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
10454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
10464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
10474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
10494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
10504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
10524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
10534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
10554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
10564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
10594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose    : Update of background noise estimate
10614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs     : bckr_est:   background noise estimate
10624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              pitch:      flags for pitch detection
10634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber              stat_count: stationary counter
10644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs    : bckr_est:   background noise estimate
10654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
10684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
10704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
10734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
10754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
10784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
10824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
10844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
10854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
10874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
10894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
10914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
10924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
10934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
10944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
10954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
10964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
10974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
10984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
10994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
11014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
11024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void noise_estimate_update(
11044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    vadState1 *st,    /* i/o : State struct                       */
11054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 level[],   /* i   : sub-band levels of the input frame */
11064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow  /* o : Flag set when overflow occurs        */
11074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
11084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
11094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 i;
11104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 alpha_up;
11114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 alpha_down;
11124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 bckr_add;
11134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* Control update of bckr_est[] */
11154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    update_cntrl(st, level, pOverflow);
11164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* Choose update speed */
11184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    bckr_add = 2;
11194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (((0x7800 & st->vadreg) == 0) &&
11214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            ((st->pitch & 0x7800) == 0)
11224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            && (st->complex_hang_count == 0))
11234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
11244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        alpha_up = ALPHA_UP1;
11254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        alpha_down = ALPHA_DOWN1;
11264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
11274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else
11284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
11294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if ((st->stat_count == 0)
11304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                && (st->complex_hang_count == 0))
11314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
11324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha_up = ALPHA_UP2;
11334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha_down = ALPHA_DOWN2;
11344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
11354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        else
11364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
11374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha_up = 0;
11384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha_down = ALPHA3;
11394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            bckr_add = 0;
11404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
11414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
11424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* Update noise estimate (bckr_est) */
11444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < COMPLEN; i++)
11454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
11464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        Word16 temp;
11474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        temp = sub(st->old_level[i], st->bckr_est[i], pOverflow);
11494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (temp < 0)
11514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        { /* update downwards*/
11524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            temp = mult_r(alpha_down, temp, pOverflow);
11534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            temp = add(st->bckr_est[i], temp, pOverflow);
11544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->bckr_est[i] = add(-2, temp, pOverflow);
11564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            /* limit minimum value of the noise estimate to NOISE_MIN */
11584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            if (st->bckr_est[i] < NOISE_MIN)
11594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            {
11604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                st->bckr_est[i] = NOISE_MIN;
11614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            }
11624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
11634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        else
11644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        { /* update upwards */
11654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            temp = mult_r(alpha_up, temp, pOverflow);
11664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            temp = add(st->bckr_est[i], temp, pOverflow);
11674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->bckr_est[i] = add(bckr_add, temp, pOverflow);
11684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            /* limit maximum value of the noise estimate to NOISE_MAX */
11704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            if (st->bckr_est[i] > NOISE_MAX)
11714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            {
11724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                st->bckr_est[i] = NOISE_MAX;
11734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            }
11744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
11754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
11764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* Update signal levels of the previous frame (old_level) */
11784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    for (i = 0; i < COMPLEN; i++)
11794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
11804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->old_level[i] = level[i];
11814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
11824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
11834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
11864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
11874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: complex_estimate_adapt
11884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
11894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
11904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
11924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
11934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    low_power -- Word16 -- very low level flag of the input frame
11944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
11964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
11974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
11984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
11994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
12004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
12014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
12034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
12044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
12064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
12074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
12104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Function   : complex_estimate_adapt
12124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose    : Update/adapt of complex signal estimate
12134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs     : low_power:   low signal power flag
12144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs    : st->corr_hp_fast:   long term complex signal estimate
12154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
12184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
12204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
12234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
12254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
12284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
12324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
12344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
12354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
12374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
12394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
12414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
12424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
12434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
12444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
12454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
12484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
12494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
12514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
12524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic void complex_estimate_adapt(
12544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    vadState1 *st,      /* i/o : VAD state struct                       */
12554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 low_power,   /* i   : very low level flag of the input frame */
12564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow    /* o : Flag set when overflow occurs            */
12574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
12584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
12594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 alpha;            /* Q15 */
12604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word32 L_tmp;            /* Q31 */
12614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    /* adapt speed on own state */
12644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->best_corr_hp < st->corr_hp_fast) /* decrease */
12654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
12664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH)
12674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {  /* low state  */
12684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha = CVAD_ADAPT_FAST;
12694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
12704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        else
12714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {  /* high state */
12724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha = CVAD_ADAPT_REALLY_FAST;
12734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
12744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
12754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else  /* increase */
12764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
12774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH)
12784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
12794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha = CVAD_ADAPT_FAST;
12804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
12814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        else
12824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
12834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            alpha = CVAD_ADAPT_SLOW;
12844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
12854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
12864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    L_tmp = L_deposit_h(st->corr_hp_fast);
12884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    L_tmp = L_msu(L_tmp, alpha, st->corr_hp_fast, pOverflow);
12894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    L_tmp = L_mac(L_tmp, alpha, st->best_corr_hp, pOverflow);
12904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st->corr_hp_fast = pv_round(L_tmp, pOverflow);           /* Q15 */
12914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->corr_hp_fast < CVAD_MIN_CORR)
12934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
12944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->corr_hp_fast = CVAD_MIN_CORR;
12954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
12964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
12974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (low_power != 0)
12984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
12994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->corr_hp_fast = CVAD_MIN_CORR;
13004f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
13014f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber}
13024f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13034f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13044f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber/*
13054f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13064f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION NAME: complex_vad
13074f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13084f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber INPUT AND OUTPUT DEFINITIONS
13094f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13104f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Inputs:
13114f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
13124f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    low_power -- Word16 -- flag power of the input frame
13134f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13144f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Outputs:
13154f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st -- pointer to type vadState1 --  State struct
13164f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    pOverflow -- pointer to type Flag -- overflow indicator
13174f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13184f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13194f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Returns:
13204f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    the complex background decision
13214f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13224f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Global Variables Used:
13234f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
13244f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13254f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Local Variables Needed:
13264f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    None
13274f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13284f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13294f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber FUNCTION DESCRIPTION
13304f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13314f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Purpose      : complex background decision
13324f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber Return value : the complex background decision
13334f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13344f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13354f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REQUIREMENTS
13364f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13374f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber None
13384f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13394f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13404f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber REFERENCES
13414f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13424f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
13434f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13444f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13454f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber PSEUDO-CODE
13464f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13474f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13484f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13494f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber RESOURCES USED [optional]
13504f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13514f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber When the code is written for a specific target processor the
13524f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber the resources used should be documented below.
13534f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13544f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber HEAP MEMORY USED: x bytes
13554f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13564f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber STACK MEMORY USED: x bytes
13574f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13584f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
13594f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                used to represent cycle count for each subroutine
13604f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                called)
13614f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
13624f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber                                     name]
13634f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13644f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13654f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber CAUTION [optional]
13664f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber [State any special notes, constraints or cautions for users of this function]
13674f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13684f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber------------------------------------------------------------------------------
13694f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber*/
13704f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13714f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huberstatic Word16 complex_vad(
13724f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    vadState1 *st,    /* i/o : VAD state struct              */
13734f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Word16 low_power, /* i   : flag power of the input frame */
13744f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    Flag  *pOverflow  /* o : Flag set when overflow occurs   */
13754f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber)
13764f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber{
13774f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st->complex_high = shr(st->complex_high, 1, pOverflow);
13784f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    st->complex_low = shr(st->complex_low, 1, pOverflow);
13794f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13804f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (low_power == 0)
13814f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
13824f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->corr_hp_fast > CVAD_THRESH_ADAPT_HIGH)
13834f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
13844f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->complex_high |= 0x4000;
13854f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
13864f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13874f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        if (st->corr_hp_fast > CVAD_THRESH_ADAPT_LOW)
13884f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        {
13894f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber            st->complex_low |= 0x4000;
13904f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        }
13914f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
13924f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber
13934f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    if (st->corr_hp_fast > CVAD_THRESH_HANG)
13944f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
13954f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->complex_hang_timer = add(st->complex_hang_timer, 1, pOverflow);
13964f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    }
13974f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    else
13984f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber    {
13994f1efc098cb5791c3e9f483f2af84aef70d2d0a0Andreas Huber        st->complex_hang_timer =  0;
1400