⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mat_lib.c

📁 2400bps MELP语音编解码源程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
/*

2.4 kbps MELP Proposed Federal Standard speech coder

Fixed-point C code, version 1.0

Copyright (c) 1998, Texas Instruments, Inc.  

Texas Instruments has intellectual property rights on the MELP
algorithm.  The Texas Instruments contact for licensing issues for
commercial and non-government use is William Gordon, Director,
Government Contracts, Texas Instruments Incorporated, Semiconductor
Group (phone 972 480 7442).

The fixed-point version of the voice codec Mixed Excitation Linear
Prediction (MELP) is based on specifications on the C-language software
simulation contained in GSM 06.06 which is protected by copyright and
is the property of the European Telecommunications Standards Institute
(ETSI). This standard is available from the ETSI publication office
tel. +33 (0)4 92 94 42 58. ETSI has granted a license to United States
Department of Defense to use the C-language software simulation contained
in GSM 06.06 for the purposes of the development of a fixed-point
version of the voice codec Mixed Excitation Linear Prediction (MELP).
Requests for authorization to make other use of the GSM 06.06 or
otherwise distribute or modify them need to be addressed to the ETSI
Secretariat fax: +33 493 65 47 16.

*/
/*

  mat_lib.c: Matrix and vector manipulation library

*/

#include "spbstd.h"
#include "mathhalf.h"
#include "wmops.h"
#include "mat.h"

/***************************************************************************
 *
 *   FUNCTION NAME: v_add
 *
 *   PURPOSE:
 *
 *     Perform the addition of the two 16 bit input vector with
 *     saturation.
 *
 *   INPUTS:
 *
 *     vec1            16 bit short signed integer (Shortword) vector whose 
 *                     values fall in the range 
 *                     0xffff 8000 <= vec1 <= 0x0000 7fff.
 *
 *     vec2            16 bit short signed integer (Shortword) vector whose 
 *                     values falls in the range 
 *                     0xffff 8000 <= vec2 <= 0x0000 7fff.
 *
 *     n               size of input vectors.
 *
 *   OUTPUTS:
 *
 *     none
 *
 *   RETURN VALUE:
 *
 *     vec1            16 bit short signed integer (Shortword) vector whose 
 *                     values fall in the range
 *                     0xffff 8000 <= vec1[] <= 0x0000 7fff.
 *
 *   IMPLEMENTATION:
 *
 *     Perform the addition of the two 16 bit input vectors with
 *     saturation.
 *
 *     vec1 = vec1 + vec2
 *
 *     vec1[] is set to 0x7fff if the operation results in an
 *     overflow.  vec1[] is set to 0x8000 if the operation results
 *     in an underflow.
 *
 *   KEYWORDS: add, addition
 *
 *************************************************************************/

Shortword *v_add(Shortword *vec1,Shortword *vec2,Shortword n)
{
    Shortword i;

    for(i=0; i < n; i++) {
      vec1[i] = add(vec1[i],vec2[i]);    data_move();
    }
    return(vec1);
}

/***************************************************************************
 *
 *   FUNCTION NAME: L_v_add
 *
 *   PURPOSE:
 *
 *     Perform the addition of the two 32 bit input vector with
 *     saturation.
 *
 *   INPUTS:
 *
 *     L_vec1          32 bit long signed integer (Longword) vector whose 
 *                     values fall in the range 
 *                     0x8000 0000 <= L_vec1 <= 0x7fff ffff.
 *
 *     L_vec2          32 bit long signed integer (Longword) vector whose 
 *                     values falls in the range 
 *                     0x8000 0000 <= L_vec2 <= 0x7fff ffff.
 *
 *     n               size of input vectors.
 *
 *   OUTPUTS:
 *
 *     none
 *
 *   RETURN VALUE:
 *
 *     L_vec1          32 bit long signed integer (Longword) vector whose 
 *                     values fall in the range
 *                     0x8000 0000 <= L_vec1[] <= 0x7fff ffff.
 *
 *   IMPLEMENTATION:
 *
 *     Perform the addition of the two 32 bit input vectors with
 *     saturation.
 *
 *     L_vec1 = L_vec1 + L_vec2
 *
 *     L_vec1[] is set to 0x7fff ffff if the operation results in an
 *     overflow.  L_vec1[] is set to 0x8000 0000 if the operation results
 *     in an underflow.
 *
 *   KEYWORDS: add, addition
 *
 *************************************************************************/

Longword *L_v_add(Longword *L_vec1,Longword *L_vec2,Shortword n)
{
    Shortword i;

    for(i=0; i < n; i++) {
      L_vec1[i] = L_add(L_vec1[i],L_vec2[i]);    L_data_move();
    }
    return(L_vec1);
}

/***************************************************************************
 *
 *   FUNCTION NAME: v_equ
 *
 *   PURPOSE:
 *
 *     Copy the contents of one 16 bit input vector to another
 *
 *   INPUTS:
 *
 *     vec2            16 bit short signed integer (Shortword) vector whose 
 *                     values falls in the range 
 *                     0xffff 8000 <= vec2 <= 0x0000 7fff.
 *
 *     n               size of input vector
 *
 *   OUTPUTS:
 *
 *     vec1            16 bit short signed integer (Shortword) vector whose 
 *                     values fall in the range 
 *                     0xffff 8000 <= vec1 <= 0x0000 7fff.
 *
 *   RETURN VALUE:
 *
 *     vec1            16 bit short signed integer (Shortword) vector whose 
 *                     values fall in the range
 *                     0xffff 8000 <= vec1[] <= 0x0000 7fff.
 *
 *   IMPLEMENTATION:
 *
 *     Copy the contents of one 16 bit input vector to another
 *
 *     vec1 = vec2
 *
 *   KEYWORDS: equate, copy
 *
 *************************************************************************/

Shortword *v_equ(Shortword *vec1,Shortword *vec2,Shortword n)
{
    Shortword i;

    for(i=0; i < n; i++) {
      vec1[i] = vec2[i];    data_move();
    }
    return(vec1);
}

/***************************************************************************
 *
 *   FUNCTION NAME: v_equ_shr
 *
 *   PURPOSE:
 *
 *     Copy the contents of one 16 bit input vector to another with shift
 *
 *   INPUTS:
 *
 *     vec2            16 bit short signed integer (Shortword) vector whose 
 *                     values falls in the range 
 *                     0xffff 8000 <= vec2 <= 0x0000 7fff.
 *     scale           right shift factor
 *     n               size of input vector
 *
 *   OUTPUTS:
 *
 *     vec1            16 bit short signed integer (Shortword) vector whose 
 *                     values fall in the range 
 *                     0xffff 8000 <= vec1 <= 0x0000 7fff.
 *
 *   RETURN VALUE:
 *
 *     vec1            16 bit short signed integer (Shortword) vector whose 
 *                     values fall in the range
 *                     0xffff 8000 <= vec1[] <= 0x0000 7fff.
 *
 *   IMPLEMENTATION:
 *
 *     Copy the contents of one 16 bit input vector to another with shift
 *
 *     vec1 = vec2>>scale
 *
 *   KEYWORDS: equate, copy
 *
 *************************************************************************/

Shortword *v_equ_shr(Shortword *vec1,Shortword *vec2,Shortword scale,
		     Shortword n)
{
    Shortword i;

    for(i=0; i < n; i++) {
	vec1[i] = shr(vec2[i],scale);    data_move();
    }
    return(vec1);
}

/***************************************************************************
 *
 *   FUNCTION NAME: L_v_equ
 *
 *   PURPOSE:
 *
 *     Copy the contents of one 32 bit input vector to another
 *
 *   INPUTS:
 *
 *     L_vec2          32 bit long signed integer (Longword) vector whose 
 *                     values falls in the range 
 *                     0x8000 0000 <= L_vec2 <= 0x7fff ffff.
 *
 *     n               size of input vector
 *
 *   OUTPUTS:
 *
 *     L_vec1          32 bit long signed integer (Longword) vector whose 
 *                     values fall in the range 
 *                     0x8000 0000 <= L_vec1 <= 0x7fff ffff.
 *
 *   RETURN VALUE:
 *
 *     L_vec1          32 bit long signed integer (Longword) vector whose 
 *                     values fall in the range
 *                     0x8000 0000 <= L_vec1[] <= 0x7fff ffff.
 *
 *   IMPLEMENTATION:
 *
 *     Copy the contents of one 32 bit input vector to another
 *
 *     vec1 = vec2
 *
 *   KEYWORDS: equate, copy
 *
 *************************************************************************/

Longword *L_v_equ(Longword *L_vec1,Longword *L_vec2,Shortword n)
{
    Shortword i;

    for(i=0; i < n; i++) {
      L_vec1[i] = L_vec2[i];     L_data_move();
    }
    return(L_vec1);
}

/***************************************************************************
 *
 *   FUNCTION NAME: v_inner
 *
 *   PURPOSE:
 *
 *     Compute the inner product of two 16 bit input vectors
 *     with saturation and truncation.  Output is a 16 bit number.
 *
 *   INPUTS:
 *
 *     vec1            16 bit short signed integer (Shortword) whose value
 *                     falls in the range 0xffff 8000 <= vec1 <= 0x0000 7fff.
 *
 *     vec2            16 bit short signed integer (Shortword) whose value
 *                     falls in the range 0xffff 8000 <= vec2 <= 0x0000 7fff.
 *
 *     n               size of input vectors
 *
 *     qvec1           Q value of vec1
 *
 *     qvec2           Q value of vec2
 *
 *     qout            Q value of output
 *
 *   OUTPUTS:
 *
 *     none
 *
 *   RETURN VALUE:
 *
 *     innerprod       16 bit short signed integer (Shortword) whose value
 *                     falls in the range
 *                     0xffff 8000 <= innerprod <= 0x0000 7fff.
 *
 *   IMPLEMENTATION:
 *
 *     Compute the inner product of the two 16 bit input vectors.
 *     The output is a 16 bit number.
 *
 *   KEYWORDS: inner product
 *
 *************************************************************************/

Shortword v_inner(Shortword *vec1,Shortword *vec2,Shortword n,
		  Shortword qvec1,Shortword qvec2,Shortword qout)
{
    Shortword i;
    Shortword innerprod;
    Longword L_temp;

    L_temp = 0;   data_move();
    for(i = 0; i < n; i++)
        L_temp = L_mac(L_temp,vec1[i],vec2[i]);
    innerprod = extract_h(L_shl(L_temp,(Shortword)(qout-((qvec1+qvec2+1)-16))));
    return(innerprod);
}

/***************************************************************************
 *
 *   FUNCTION NAME: L_v_inner
 *
 *   PURPOSE:
 *
 *     Compute the inner product of two 16 bit input vectors
 *     with saturation and truncation.  Output is a 32 bit number.
 *
 *   INPUTS:
 *
 *     vec1            16 bit short signed integer (Shortword) whose value
 *                     falls in the range 0xffff 8000 <= vec1 <= 0x0000 7fff.
 *
 *     vec2            16 bit short signed integer (Shortword) whose value
 *                     falls in the range 0xffff 8000 <= vec2 <= 0x0000 7fff.
 *
 *     n               size of input vectors
 *
 *     qvec1           Q value of vec1
 *
 *     qvec2           Q value of vec2
 *
 *     qout            Q value of output
 *
 *   OUTPUTS:
 *
 *     none
 *
 *   RETURN VALUE:
 *
 *     L_innerprod     32 bit long signed integer (Longword) whose value

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -