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

📄 gain.dsp

📁 作者:Analog Devices,Inc 平台:ADSP21xx 编程语言:ASM 说明:ADSP21xx用AD的16位定点DSP作音频压缩器性价比不错
💻 DSP
字号:
.module/boot=3/boot=4        gain_calculation; 

{ GAIN.DSP - Calculates the gain factor for a speech frame.

  INPUT:
     i0 -> speech frame
     l0 =  0
  
  OUTPUT:
     sr1 = gain

  FUNCTIONS CALLED:
     poly_approx - used to aproximate sqrt function
  
  DESCRIPTION:
     The gain of a frame is calculated as:

        gain = sqrt(sum_over_frame(x(n)^2))

     A simpel no-speech detection is implemented, if the gain is lower
     than NOISE_FLOOR the gain is set to zero.
     The result is scaled appropriatly by GAIN_SCALE.
}

{Include constant definitions}
#include "lpc.h"

.const NOISE_FLOOR = 0x0000;  {found as gain when no input is present}
.const GAIN_SCALE  = 0;       {appropriate scale value}

.entry    calc_gain;

.external sqrt;

calc_gain:
  
  {calulate energy of frame, R(0), as sum of input squared}
  mr=0;
  cntr = FRAME_LENGTH;
  do cor_data_loop until ce;
    si = dm(i0,m1);
    sr = ashift si by G_INP_SHIFT (hi);  {scale to avoid overflow}
    my0 = sr1;                  
  cor_data_loop: mr=mr+sr1*my0(ss);
  
  {set gain = 0 if energy is under noise level}
  ay0 = NOISE_FLOOR;
  ar = mr1 - ay0;
  if gt jump speech;
    sr1 = 0;
    jump from_noise;
  speech:
    {calc the gain as the squareroot of R(0)}
    sr = lshift mr0 by -12 (lo);   {shift to 16.16 format}
    sr = sr or ashift mr1 by -12 (hi);
    mr1 = sr1;                     {msw of gain^2}
    mr0 = sr0;                     {lsw of gain^2}
    call sqrt;                     {result is in unsigned 8.8 format} 
    sr  = lshift sr1 by 7 (hi);    {shift back to 1.15 format}
    sr  = lshift sr1 by GAIN_SCALE (hi);  
    
  from_noise:

rts;
     
.endmod;

⌨️ 快捷键说明

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