📄 dsp_sub.c
字号:
/*
*2.4 kbps MELP Proposed Federal Standard speech coder
*
*TMS320C5x assembly 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 following code was hand optimized for the Texas Instuments
* TMS320C5x DSP by DSPCon, Inc. For information, please contact DSPCon
* at:
*
* DSPCon, Inc.
* 380 Foothill Road
* Bridgewater, New Jersey 08807
* (908) 722-5656
* info@dspcon.com
* www.dspcon.com
*
*************************************************************************/
/*
dsp_sub.c: general subroutines.
*/
/* compiler include files */
#include <stdlib.h>
#include <math.h>
#include "spbstd.h"
#include "mathhalf.h"
#include "mathdp31.h"
#include "mat.h"
#include "math_lib.h"
#include "dsp_sub.h"
/* */
/* Subroutine median: calculate median value */
/* */
#define MAXSORT 5
Shortword median(Shortword input[], Shortword npts)
{
Shortword i,j,loc;
Shortword insert_val;
Shortword sorted[MAXSORT];
/* sort data in temporary array */
v_equ(sorted,input,npts);
for (i = 1; i < npts; i++) {
/* for each data point */
for (j = 0; j < i; j++) {
/* find location in current sorted list */
if (sorted[i] < sorted[j])
break;
}
/* insert new value */
loc = j;
insert_val = sorted[i];
for (j = i; j > loc; j--) {
sorted[j] = sorted[j-1];
}
sorted[loc] = insert_val;
}
return(sorted[npts/2]);
}
#undef MAXSORT
#undef LIMIT_PEAKI
/* */
/* Subroutine QUANT_U: quantize positive input value with */
/* symmetrical uniform quantizer over given positive */
/* input range. */
/* */
void quant_u(Shortword *p_data, Shortword *p_index, Shortword qmin,
Shortword qmax, Shortword nlev, Shortword nlev_q,
Shortword double_flag, Shortword scale)
{
Shortword i;
Shortword step, half_step, qbnd, *p_in;
Longword L_step, L_half_step, L_qbnd, L_qmin, L_p_in;
Shortword temp;
Longword L_temp;
p_in = p_data;
/* Define symmetrical quantizer stepsize */
/* step = (qmax - qmin) / (nlev - 1); */
temp = sub(qmax,qmin);
step = divide_s(temp,nlev_q);
if (double_flag) {
/* double precision specified */
/* Search quantizer boundaries */
/*qbnd = qmin + (0.5 * step); */
L_step = L_deposit_l(step);
L_half_step = L_shr(L_step,1);
L_qmin = L_shl(L_deposit_l(qmin),scale);
L_qbnd = L_add(L_qmin,L_half_step);
L_p_in = L_shl(L_deposit_l(*p_in),scale);
for (i = 0; i < nlev; i++) {
if (L_p_in < L_qbnd)
break;
else
L_qbnd = L_add(L_qbnd,L_step);
}
/* Quantize input to correct level */
/* *p_in = qmin + (i * step); */
L_temp = L_sub(L_qbnd,L_half_step);
*p_in = extract_l(L_shr(L_temp,scale));
*p_index = i;
}
else {
/* Search quantizer boundaries */
/* qbnd = qmin + (0.5 * step); */
step = shr(step,scale);
half_step = shr(step,1);
qbnd = add(qmin,half_step);
for (i = 0; i < nlev; i ++ ) {
if (*p_in < qbnd)
break;
else
qbnd = add(qbnd,step);
}
/* Quantize input to correct level */
/* *p_in = qmin + (i * step); */
*p_in = sub(qbnd,half_step);
*p_index = i;
}
} /* quant_u */
/* */
/* Subroutine QUANT_U_DEC: decode uniformly quantized */
/* value. */
/* */
void quant_u_dec(Shortword index, Shortword *p_data, Shortword qmin,
Shortword qmax, Shortword nlev_q, Shortword scale)
{
Shortword step,temp;
Longword L_qmin, L_temp;
/* Define symmetrical quantizer stepsize */
/* step = (qmax - qmin) / (nlev - 1); */
temp = sub(qmax,qmin);
step = divide_s(temp,nlev_q);
/* Decode quantized level */
/* double precision specified */
L_temp = L_shr(L_mult(step,index),1);
L_qmin = L_shl(L_deposit_l(qmin),scale);
L_temp = L_add(L_qmin,L_temp);
*p_data = extract_l(L_shr(L_temp,scale));
}
/* */
/* Subroutine READBL: read block of input data */
/* */
#define MAXSIZE 1024
Shortword readbl() {}
#undef MAXSIZE
/* */
/* Subroutine WRITEBL: write block of output data */
/* */
#define MAXSIZE 1024
void writebl() {}
#undef MAXSIZE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -