/*
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.
*/
/***************************************************************************
*
* File Name: mathhalf.c
*
* Purpose: Contains functions which implement the primitive
* arithmetic operations.
*
* The functions in this file are listed below. Some of them are
* defined in terms of other basic operations. One of the
* routines, saturate() is static. This is not a basic
* operation, and is not reference outside the scope of this
* file.
*
*
* abs_s()
* add()
* divide_s()
* extract_h()
* extract_l()
* L_abs()
* L_add()
* L_deposit_h()
* L_deposit_l()
* L_mac()
* L_msu()
* L_mult()
* L_negate()
* L_shift_r()
* L_shl()
* L_shr()
* L_sub()
* mac_r()
* msu_r()
* mult()
* mult_r()
* negate()
* norm_l()
* norm_s()
* round()
* saturate()
* shift_r()
* shl()
* shr()
* sub()
*
**************************************************************************/
#include "typedefs.h"
#include "mathhalf.h"
#include "mathdp31.h"
/***************************************************************************
*
* FUNCTION NAME: saturate
*
* PURPOSE:
*
* Limit the 32 bit input to the range of a 16 bit word.
*
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Shortword) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
* KEYWORDS: saturation, limiting, limit, saturate, 16 bits
*
*************************************************************************/
static Shortword saturate(Longword L_var1)
{
Shortword swOut;
if (L_var1 > SW_MAX)
{
swOut = SW_MAX;
}
else if (L_var1 < SW_MIN)
{
swOut = SW_MIN;
}
else
{
swOut = (Shortword) L_var1;
}
return (swOut);
}
/***************************************************************************
*
* FUNCTION NAME: divide_s
*
* PURPOSE:
*
* Divide var1 by var2. Note that both must be positive, and
* var1 >= var2. The output is set to 0 if invalid input is
* provided.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
* var2
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Shortword) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* In the case where var1==var2 the function returns 0x7fff. The output
* is undefined for invalid inputs. This implementation returns zero
* and issues a warning via stdio if invalid input is presented.
*
* KEYWORDS: divide
*
*************************************************************************/
Shortword divide_s(Shortword var1, Shortword var2)
{
Longword L_div;
Shortword swOut;
if (var1 < 0 || var2 < 0 || var1 > var2) {
/* undefined output for invalid input into divide_s */
return ((Shortword)0);
}
if (var1 == var2)
return ((Shortword)0x7fff);
L_div = ((0x00008000L * (Longword) var1) / (Longword) var2);
swOut = saturate(L_div);
return (swOut);
}
/***************************************************************************
*
* FUNCTION NAME: L_deposit_l
*
* PURPOSE:
*
* Put the 16 bit input into the 16 LSB's of the output Longword with
* sign extension i.e. the top 16 bits are set to either 0 or 0xffff.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0xffff 8000 <= L_var1 <= 0x0000 7fff.
*
* KEYWORDS: deposit, assign
*
*************************************************************************/
Longword L_deposit_l(Shortword var1)
{
Longword L_Out;
L_Out = var1;
return (L_Out);
}
/***************************************************************************
*
* FUNCTION NAME: L_deposit_h
*
* PURPOSE:
*
* Put the 16 bit input into the 16 MSB's of the output Longword. The
* LS 16 bits are zeroed.
*
* INPUTS:
*
* var1
* 16 bit short signed integer (Shortword) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_Out
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff 0000.
*
*
* KEYWORDS: deposit, assign, fractional assign
*
*************************************************************************/
Longword L_deposit_h(Shortword var1)
{
Longword L_var2;
L_var2 = (Longword) var1 << 16;
return (L_var2);
}
/***************************************************************************
*
* FUNCTION NAME: extract_l
*
* PURPOSE:
*
* Extract the 16 LS bits of a 32 bit Longword. Return the 16 bit
* number as a Shortword. The upper portion of the input Longword
* has no impact whatsoever on the output.
*
* INPUTS:
*
* L_var1
* 32 bit long signed integer (Longword) whose value
* falls in the range
* 0x8000 0000 <= L_var1 <= 0x7fff ffff.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* swOut
* 16 bit short signed integer (Shortword) whose value
* falls in the range
* 0xffff 8000 <= swOut <= 0x0000 7fff.
*
*
* KEYWORDS: extract, as
朱moyimi
- 粉丝: 84
- 资源: 1万+
最新资源
- 基于位置跟踪观测器的脉振高频电压信号注入的无速度传感器控制系统
- 永磁同步发电机仿真,带四个牵引电机仿真 内燃机车仿真
- Induction-Motor-VF-Control:基于MATLAB Simulink的利用V F控制的感应电机调速仿真模型 仿真条件:MATLAB Simulink R2015b
- 欧姆龙cp1h与台达变频器modbus rtu通讯程序 程序有注释 控制正反转、状态显示、写入频率和读取频率、电压,plc型号为cp1h-xa40dt-d,触摸屏为威纶通mt8071ie,变频器为
- SVPWM-Inverter-Inductor-Motor:基于MATLAB Simulink的空间矢量脉宽调制SVPWM逆变器,交流测连接三相感应电机 仿真条件:MATLAB Simulink R
- Labview Modbus-Tcp和西门子全糸列pLC通讯所有数据类型均能读写,速度快,使用在多个项目上,运行稳定,可以扩展到其它品牌PLc,上位机程序一样,只是PLC程序稍微变动一下,上下位机源
- NPC-5level-Inverter:基于MATLAB Simulink的中性点钳位五电平逆变器仿真模型 仿真条件:MATLAB Simulink R2015b
- NPC-3level-Inverter:基于MATLAB Simulink的中性点钳位三电平逆变器仿真模型 仿真条件:MATLAB Simulink R2015b
- DC-Machine-Field-Control:基于MATLAB Simulink的直流电机弱磁控制仿真模型 仿真条件:MATLAB Simulink R2015b
- Twelve-Pulse-Diode-Rectifier:基于MATLAB Simulink的12脉冲二极管整流器仿真模型 仿真条件:MATLAB Simulink R2015b
- AC-DC-Machine:基于MATLAB Simulink的三相AC DC整流后的直流电机转速开环控制仿真模型 仿真条件:MATLAB Simulink R2015b
- 经典西门子200smart四轴定位控制:两台CPU ST60做通讯,台达伺服,步科触摸屏, 包含200smar-PLC程序+项目电气接线图+程序流程说明+触摸屏程序全套资料; 程序经典,结构清晰,梯形
- pscad仿真模型, upqc upfc d-v-r,拓扑为三电平四线制,变压器串联接入电网,电压跌落补偿,控制部分非模块搭建,全部用c语言编写,代码可以直接用在实际dsp中控制逆变器,当初就是为实
- 三菱,FX3U,plc程序模板和触摸屏程序模板,适用于运动轴控制,程序可以在自动的时候暂停进行手动控制,适用于一些中大型设备,可以防止某个气缸超时时,处于自动模式,能够轻松处理,处理完成后,恢复原来的
- EKF-SoC:基于MATLAB Similink的扩展卡尔曼滤波器EKF的锂电池SoC计算仿真模型 仿真条件:MATLAB Simulink R2015b
- 动态电压恢复器(DVR)模型 Matlab simulink 可用于治理电压暂降、暂升和不平衡短路带来的电能质量问题:仿真总时长0.7s,DVR始终接入, 0.1-0.2s治理电压暂降,0.3-0
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈