117299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong/*
217299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** Copyright 2003-2010, VisualOn, Inc.
317299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong **
417299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** Licensed under the Apache License, Version 2.0 (the "License");
517299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** you may not use this file except in compliance with the License.
617299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** You may obtain a copy of the License at
717299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong **
817299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong **     http://www.apache.org/licenses/LICENSE-2.0
917299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong **
1017299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** Unless required by applicable law or agreed to in writing, software
1117299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** distributed under the License is distributed on an "AS IS" BASIS,
1217299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1317299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** See the License for the specific language governing permissions and
1417299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong ** limitations under the License.
1517299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong */
1617299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong
1717299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong/***********************************************************************
1817299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong*       File: scale.c                                                  *
1917299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong*                                                                      *
2017299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong*       Description: Scale signal to get maximum of dynamic            *
2117299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong*                                                                      *
2217299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong************************************************************************/
2317299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong
2417299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong#include "typedef.h"
2517299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong#include "basic_op.h"
2617299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong
2717299ab50ceb70d904e610e3b2d7fb2361a11e03James Dongvoid Scale_sig(
2817299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		Word16 x[],                           /* (i/o) : signal to scale               */
2917299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		Word16 lg,                            /* (i)   : size of x[]                   */
3017299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		Word16 exp                            /* (i)   : exponent: x = round(x << exp) */
3117299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	      )
3217299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong{
3317299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	Word32 i;
3417299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	Word32 L_tmp;
3517299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	if(exp > 0)
3617299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	{
3717299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		for (i = lg - 1 ; i >= 0; i--)
3817299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		{
3917299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong			L_tmp = L_shl2(x[i], 16 + exp);
4017299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong			x[i] = extract_h(L_add(L_tmp, 0x8000));
4117299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		}
4217299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	}
4317299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	else
4417299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	{
4517299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		exp = -exp;
4617299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		for (i = lg - 1; i >= 0; i--)
4717299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		{
4817299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong			L_tmp = x[i] << 16;
4917299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong			L_tmp >>= exp;
5017299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong			x[i] = (L_tmp + 0x8000)>>16;
5117299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong		}
5217299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	}
5317299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong	return;
5417299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong}
5517299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong
5617299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong
5717299ab50ceb70d904e610e3b2d7fb2361a11e03James Dong
58