xsh2005105326 发表于 2009-7-1 09:08:47

差分脉冲编解码源代码,用于语音编解码的,压缩比为1:2

编译环境为keilourdev_457307.rar(文件大小:33K) (原文件名:Wireless_Audio.rar)
以下为该压缩包中关于DPCM 编解码的例程。
/**************************************************************************
DPCM 编解码例程,文件名为DpcmCodec.c
***************************************************************************
* Description:                                                            *
*   DPCM 编解码                                                         *
***************************************************************************
* Input arguments:                                                      *
*   byte sample: Unsigned speech sample (0-255).                        *
*   bit returncode: Function returns an encoded difference (4 bit) if set,*
*       or a predicted sample (8 bit) if not set.                         *
* Return value:                                                         *
*   byte: An encoded 4-bit DPCM code or a predicted sample.               *
**************************************************************************/
byte DpcmEncoder (byte sample, bit returncode)
{
    // Compute the differense between the actual- and predicted sample
    diff = sample - encoderpredsample;

    // Quantize the difference
    if (diff >= 0)
      dpcmcodeout = 8;// Set the first bit
    else // (diff < 0)
    {
      dpcmcodeout = 0;
      diff = -diff;// Use the absolute value of the difference

    }// End else

    if (diff >= 8)
    {
      dpcmcodeout |= 4;// Set the second bit
      if (diff >= 32)
      {
            dpcmcodeout |= 2;// Set the third bit
            if (diff >= 64)
                dpcmcodeout |= 1;// Set the fourth bit (LSB)

      }// End if
      else// (diff < 32)
      {
            if (diff >= 16)
                dpcmcodeout |= 1;// Set the fourth bit (LSB)

      }// End else

    }// End if
    else// (diff < 8)
    {
      if (diff >= 2)
      {
            dpcmcodeout |= 2;// Set the third bit
            if (diff >= 4)
                dpcmcodeout |= 1;// Set the fourth bit(LSB)

      }// End if
      else // (diff < 2)
      {
            if (diff >= 1)
            dpcmcodeout |= 1;// Set the fourth bit(LSB)

      }// End else

    }// End else

    /* Compute new predicted sample by adding the
    old predicted sample to the quantzed difference*/
    encoderpredsample += StepSize;

    // Return the new DPCM code or the new predicted sample
    if (returncode)
      return (dpcmcodeout);
    else
      return (encoderpredsample);

}// End function


/**************************************************************************
* DpcmDecoder() - DPCM decoder routine                                    *
***************************************************************************
* Description:                                                            *
*   Performs DPCM speech decompression (1:2).                           *
***************************************************************************
* Input arguments:                                                      *
*   byte dpcmcodein: Contains one or two encoded differences.             *
*   bit msbits: The 4 msb of dpcmcodein are decoded if set, the 4 lsb are *
*       decoded if not set.                                             *
* Return value:                                                         *
*   byte: A decoded predicted sample (8 bit).                           *
**************************************************************************/
byte DpcmDecoder (byte dpcmcodein, bit msbits)
{
    // Decide if the four MSB or LSB should be decoded
    if (msbits)
      // Shift dpcmcodein four bits to the right
      dpcmcodein >>= 4;

    /* Compute new predicted sample by adding the
    old predicted sample to the quantzed difference*/
    decoderpredsample += StepSize;

    // Return the decoded sample
    return (decoderpredsample);

} // End function

wajlh 发表于 2009-7-1 09:19:19

顶一下

gavin_li 发表于 2010-8-18 15:49:48

mark

boy364100 发表于 2010-12-31 09:06:37

很给力哦!

joni 发表于 2011-8-20 16:41:19

mark

Gavin_GC 发表于 2012-2-22 18:58:16

mark

liber730 发表于 2012-4-16 14:54:56

下来看看

myhonour 发表于 2012-11-11 08:16:22

下来看看
页: [1]
查看完整版本: 差分脉冲编解码源代码,用于语音编解码的,压缩比为1:2