搜索
bottom↓
回复: 7

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

[复制链接]

出0入0汤圆

发表于 2009-7-1 09:08:47 | 显示全部楼层 |阅读模式
编译环境为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[dpcmcodeout];

    // 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[dpcmcodein & 0x0f];

    // Return the decoded sample
    return (decoderpredsample);

} // End function

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入4汤圆

发表于 2009-7-1 09:19:19 | 显示全部楼层
顶一下

出0入0汤圆

发表于 2010-8-18 15:49:48 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-12-31 09:06:37 | 显示全部楼层
很给力哦!

出0入0汤圆

发表于 2011-8-20 16:41:19 | 显示全部楼层
mark

出0入0汤圆

发表于 2012-2-22 18:58:16 | 显示全部楼层
mark

出0入0汤圆

发表于 2012-4-16 14:54:56 | 显示全部楼层
下来看看

出0入0汤圆

发表于 2012-11-11 08:16:22 | 显示全部楼层
下来看看
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 07:20

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表