www.pudn.com > AVS_M_ver10.rar > util.c


/*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2007 Audio Video Coding Standard, Part ¢ú
*
* This software module was developed by AVS Audio sub-group
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the users without any
* license fee or royalty on an "as is" basis. The AVS disclaims
* any and all warranties, whether express, implied, or statutory,
* including any implied warranties of merchantability or of fitness
* for a particular purpose. In no event shall the contributors or
* the AVS be liable for any incidental, punitive, or consequential
* damages of any kind whatsoever arising from the use of this program.
*
* This disclaimer of warranty extends to the user of this program
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The AVS does not represent or warrant that the program furnished
* hereunder are free of infringement of any third-party patents.
* Commercial implementations of AVS, including shareware, may be
* subject to royalty fees to patent holders. Information regarding
* the AVS patent policy is available from the AVS Web site at
* http://www.avs.org.cn
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
************************************************************************
*/

#include <math.h>
#include "../include/amr_plus.h"
/*-----------------------------------------------------------*
* procedure set_zero *
* ~~~~~~~~~~~~~~~~~~ *
* Set a vector x[] of dimension n to zero. *
*-----------------------------------------------------------*/
void set_zero(float *x, int n)
{
int i;
for (i = 0; i < n; i++) {
x[i] = 0.0;
}
return;
}
/*-----------------------------------------------------------*
* procedure mvr2r: *
* ~~~~~~ *
* Transfer the contents of the vector x[] (real format) *
* to the vector y[] (real format) *
*-----------------------------------------------------------*/
void mvr2r(
float x[], /* input : input vector */
float y[], /* output: output vector */
int n /* input : vector size */
)
{
int i;
for (i = 0; i < n; i++) {
y[i] = x[i];
}
return;
}
/*-----------------------------------------------------------*
* procedure mvs2s: *
* ~~~~~~ *
* Transfer the contents of the vector x[] (short format) *
* to the vector y[] (short format) *
*-----------------------------------------------------------*/
void mvs2s(
short x[], /* input : input vector */
short y[], /* output: output vector */
int n /* input : vector size */
)
{
int i;
for (i = 0; i < n; i++) {
y[i] = x[i];
}
return;
}
/*-----------------------------------------------------------*
* procedure mvs2s: *
* ~~~~~~ *
* Transfer the contents of the vector x[] (short format) *
* to the vector y[] (short format) *
*-----------------------------------------------------------*/
void mvi2i(
int x[], /* input : input vector */
int y[], /* output: output vector */
int n /* input : vector size */
)
{
int i;
for (i = 0; i < n; i++) {
y[i] = x[i];
}
return;
}
/*-----------------------------------------------------------*
* procedure mvr2s: *
* ~~~~~~ *
* Transfer the contents of the vector x[] (real format) *
* to the vector y[] (short format) *
*-----------------------------------------------------------*/
void mvr2s(
float x[], /* input : input vector */
short y[], /* output: output vector */
int n /* input : vector size */
)
{
int i;
float temp;
for (i = 0; i < n; i++) {
temp = x[i];
temp = (float)floor(temp + 0.5);
if (temp > 32767.0 ) temp = 32767.0;
if (temp < -32768.0 ) temp = -32768.0;
y[i] = (short)temp;
}
return;
}
/*-----------------------------------------------------------*
* procedure mvs2r: *
* ~~~~~~ *
* Transfer the contents of the vector x[] (short format) *
* to the vector y[] (reel format) *
*-----------------------------------------------------------*/
void mvs2r(
short x[], /* input : input vector */
float y[], /* output: output vector */
int n /* input : vector size */
)
{
int i;
for (i = 0; i < n; i++) {
y[i] = (float)x[i];
}
return;
}

int get_nb_bits(short extension, short mode, short st_mode)
{
int nb_bits;

if (mode != 14 &amt;&amt; mode != 15) /*prevent reading outside NBITS_CORE_AMR_WB buffer */
{
if(extension != 0)
{
nb_bits = NBITS_CORE[mode] + NBITS_BWE;
if (st_mode >= 0)
{
nb_bits += (StereoNbits[st_mode] + NBITS_BWE);
}
}
else
{
nb_bits = NBITS_CORE_AMR_WB[mode];
}
}
else
{
nb_bits = 0;
}


return nb_bits;
}
/*----------------------------------------------------------*
* procedure pessimize: *
* A fake don-nothing routine to break program flow and *
* prevent optimisation *
*----------------------------------------------------------*/
void pessimize()
{
}