zoukankan      html  css  js  c++  java
  • g.711 音频编码

         关于a law  and u law 定义如下:A律编码是ITU-T(国际电信标准局)定义的关于脉冲编码的一种压缩/解压缩算法。世界上大部分国家采用A律压缩算法(包括中国)。美国采用u 律算法进行脉冲编码。其英文定义大致如下:

    A-law and u-law are companding schemes used in telephone network to
    get more dynamics to the 8 bit samples that is available with linear
    coding. Typically 12..14 bit samples (linear scale) sampled at 8 kHz
    sample are companded to 8 bit (logarithmic scale) for transmission
    over 64 kbit/s data channel. In the receiving end the data is then
    converter back to linear scale (12..14 bit) and played back.
    converted back
    u-law definition
    u-LAW (pronounced mu-LAW) is
    sgn(m) ( |m |) |m |
    y= ------- ln( 1+ u|--|) |--| =< 1
    ln(1+u) ( |mp|) |mp|
    Another definition for mu-law I have seen
    ln(1+255 |x|)
    output = sgn(x) ---------------------
    ln(1+255)

    x = normalized input ( between -1 and 1)
    255 = compression parameter
    sgn(x) = sign (+/-) of x

    a-law definition
    A-LAW is
    | A (m ) |m | 1
    | ------- (--) |--| =< -
    | 1+ln A (mp) |mp| A
    y=|
    | sgn(m) ( |m |) 1 |m |
    | ------ ( 1+ ln A|--|) - =< |--| =< 1
    | 1+ln A ( |mp|) A |mp|
    Values of u=100 and 255, A=87.6, mp is the Peak message value, m is
    the current quantised message value. (The formulae get simpler if you
    substitute x for m/mp and sgn(x) for sgn(m); then -1 <= x <= 1.)
    Converting from u-LAW to A-LAW is in a sense "lossy" since there are
    quantizing errors introduced in the conversion.
    "..the u-LAW used in North America and Japan, and the A-LAW used in
    Europe and the rest of the world and international routes.."
    References:
    ? Modern Digital and Analog Communication Systems, B.P.Lathi.,
    2nd ed. ISBN 0-03-027933-X
    ? Transmission Systems for Communications, Fifth Edition, by
    Members of the Technical Staff at Bell Telephone Laboratories,
    Bell Telephone Laboratories, Incorporated, Copyright 1959, 1964,
    1970, 1982

     下面介绍下g.711的c代码的核心 

    #ifndef __G711_H_
    #define __G711_H_


    #ifdef __cplusplus
    extern "C" {
    #endif    /* __cplusplus */


    unsigned 
    char    linear2ulaw(short pcm_val);
    short            ulaw2linear(unsigned char u_val);

    unsigned 
    char    linear2alaw(short pcm_val);
    short            alaw2linear(unsigned char a_val);

    unsigned 
    char    alaw2ulaw(unsigned char a_val);
    unsigned 
    char    ulaw2alaw(unsigned char u_val);


    #ifdef __cplusplus
    }

    #endif    /* __cplusplus */


    #endif    /* __G711_H_ */

    一般工程中A律用的比较多,所以调用

    unsigned char    linear2alaw(short pcm_val);
    short            alaw2linear(unsigned char a_val);

    注意在音频处理中用的数据类型为 unsigned char 和 short ,其中ITU-T的官方代码是没有问题的,openh323中G.711的编解码器的数据类型都使用的int 和 unsigned 所以造成数据溢出,不能正常的工作,本人在第一次做的时候遇到了这个问题,替换一下就可解决即把相应的int 改为 short 和 unsigned char

  • 相关阅读:
    scrapy爬虫框架
    MongoDB分组查询,聚合查询,以及复杂查询
    mac重启iterm后不会自动加载.bash_profile
    Linux 之 2>&1
    linux下利用nohup后台运行jar文件包程序
    【intellij idea】汇总
    JAVA虚拟机体系结构
    JDK > JRE > JVM
    依赖注入(IOC) 详解
    mysql 忘记密码 登陆+修改密码
  • 原文地址:https://www.cnblogs.com/rainbowzc/p/2422314.html
Copyright © 2011-2022 走看看