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

📄 g711_decoder.c

📁 Audio compression on embedded board
💻 C
字号:
/*
=============================================================================

                          U    U   GGG    SSS  TTTTT
                          U    U  G      S       T
                          U    U  G  GG   SSS    T
                          U    U  G   G      S   T
                           UUUU    GGG    SSS    T

                   ========================================
                    ITU-T - USER'S GROUP ON SOFTWARE TOOLS
                   ========================================


       =============================================================
       COPYRIGHT NOTE: This source code, and all of its derivations,
       is subject to the "ITU-T General Public License". Please have
       it  read  in    the  distribution  disk,   or  in  the  ITU-T
       Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND  AUDIO 
       CODING STANDARDS".
       =============================================================
*/

/******************************************************************************
**
**  Filename:     g711_decoder.c
**
**  System:       RISC
**
**  Platform:     dsPIC33F
**
**  Description:  This file contains g711 Alaw and ulaw expand functions.
**
******************************************************************************/

#include "g711.h"

/******************************************************************************
**
**  FunctionName: alaw_expand ( )
**
**  Description:  expands 1 vector of A-law samples to linear PCM;
**                use 8 Least Sig. Bits (LSBs) from input and
**                13 Most Sig.Bits (MSBs) on output.
******************************************************************************/
void __attribute__((section("libG711"))) alaw_expand(lseg, logbuf, linbuf)
long            lseg;
short           *linbuf;
short           *logbuf;
{
  short         ix, mant, iexp;
  long          n;

  for (n = 0; n < lseg; n++)
  {
    ix = logbuf[n] ^ (0x0055);      //re-toggle toggled bits
    ix &= (0x007F);		            //remove sign bit
    iexp = ix >> 4;		            //extract exponent
    mant = ix & (0x000F);	        //now get mantissa

    if (iexp > 0)
	{
      mant = mant + 16;		        //add leading '1', if exponent > 0
	}

    mant = (mant << 4) + (0x0008);  //now mantissa left justified and

	/* 1/2 quantization step added */
    if (iexp > 1)		            //now left shift according exponent
    {
	  mant = mant << (iexp - 1);
	}

    linbuf[n] = logbuf[n] > 127	    //invert, if negative sample
    ? mant
    : -mant;
  }
}
/* ................... End of alaw_expand() ..................... */

/* ................... Begin of ulaw_expand() ..................... */
/******************************************************************************
**
**  FunctionName: ulaw_expand ( )
**
**  Description:  expands 1 vector of u-law samples to linear PCM
**                use 8 Least Sig. Bits (LSBs) from input and
**                14 Most Sig.Bits (MSBs) on output.
******************************************************************************/
void  __attribute__((section("libG711"))) ulaw_expand(lseg, logbuf, linbuf)
long            lseg;
short          *logbuf;
short          *linbuf;
{
  long          n;		    //aux.var.
  short         segment;	//segment (Table 2/G711, column 1)
  short         mantissa;	//low  nibble of log companded sample
  short         exponent;	//high nibble of log companded sample
  short         sign;		//sign of output sample
  short         step;

  for (n = 0; n < lseg; n++)
  {
    sign = logbuf[n] < (0x0080)	 // sign-bit = 1 for positiv values
    ? -1
    : 1;
    mantissa = ~logbuf[n];	     // 1's complement of input value
    exponent = (mantissa >> 4) & (0x0007);	// extract exponent
    segment = exponent + 1;	     // compute segment number
    mantissa = mantissa & (0x000F);         // extract mantissa

	/* Compute Quantized Sample (14 bit left justified!) */
    step = (4) << segment;	     //position of the LSB

    /* = 1 quantization step) */
    linbuf[n] = sign *		     //sign
    (((0x0080) << exponent)	     //'1', preceding the mantissa
     + step * mantissa	         //left shift of mantissa
     + step / 2		             //1/2 quantization step
     - 4 * 33
    );
  }
 }
/* ................... End of ulaw_expand() ..................... */

/*-----------------------------------------------------------------------------
                      END OF FILE:  g711_decoder.c
-----------------------------------------------------------------------------*/


⌨️ 快捷键说明

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