PCM转PCMA(pcm_alaw,G711.A率)转换表 && PCM转PCMU(pcm_ulaw,G711.U率)转换表

PCM转PCMA(pcm_alaw,G711.A率)转换表 && PCM转PCMU(pcm_ulaw,G711.U率)转换表

文章目录

ffmpeg源码生成转码表

最近要做一个功能,int16_t的PCM数据转为uint8的PCMA数据,

网上的不太可信,找ffmpeg库,发现ffmpeg库使用的是查表发实现的,

而且还有现成的生成表数据的源代码,可信度非常高

c 复制代码
/*
 * Generate a header file for hardcoded PCM tables
 *
 * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdlib.h>
#define CONFIG_HARDCODED_TABLES 0
#include "pcm_tablegen.h"
#include "tableprint.h"

int main(void)
{
    pcm_alaw_tableinit();
    pcm_ulaw_tableinit();
    pcm_vidc_tableinit();

    write_fileheader();

    WRITE_ARRAY("static const", uint8_t, linear_to_alaw);
    WRITE_ARRAY("static const", uint8_t, linear_to_ulaw);
    WRITE_ARRAY("static const", uint8_t, linear_to_vidc);

    return 0;
}

编译上有些小问题,没太关注,直接使用了注释大法,

没有用的统统干掉,编译通过,执行生成转换映射表。

不用再去研究转换公式,直接对照着表查询结果即可。

拿走不谢

使用方式

可参照ffmpeg源代码pcm.c使用

c 复制代码
    case AV_CODEC_ID_PCM_ALAW:
        for (; n > 0; n--) {
            v      = *samples++;
            *dst++ = linear_to_alaw[(v + 32768) >> 2];
        }
        break;
    case AV_CODEC_ID_PCM_MULAW:
        for (; n > 0; n--) {
            v      = *samples++;
            *dst++ = linear_to_ulaw[(v + 32768) >> 2];
        }
        break;

PCM有符号,加上32768变成正数除以4查表即可。

生成源码

表数据太大,CSDN不让保存,放到我个人服务器上了(大神手下留情不要攻击)。
http://118.126.97.61:8084/src_libs/ffmpeg_pcm_table/

相关推荐
女神下凡11 天前
带NPU的电脑 和不带NPU的电脑 在使用上有什么不样
arm开发·单片机·pcm
STQY燊桐启元(深圳)电子科技24 天前
太阳能追踪设备散热优化,相变陶瓷片解决全日照高温积温故障
经验分享·笔记·pcm
STQY燊桐启元(深圳)电子科技1 个月前
耐高温工况专项适配:相变陶瓷片如何突破高温工业设备散热瓶颈
经验分享·笔记·pcm
STQY燊桐启元(深圳)电子科技1 个月前
工业物联网网关散热升级,相变陶瓷片解决微型设备积温过热难题
经验分享·笔记·pcm
STQY燊桐启元(深圳)电子科技1 个月前
大功率储能PCS散热升级,ST-PCM180氮化铝相变陶瓷适配高密度热管理
经验分享·笔记·pcm
STQY燊桐启元(深圳)电子科技1 个月前
免涂硅脂新时代,ST‑PCMTC96 与 ST‑PCM180 相变陶瓷片重构功率器件热管理
经验分享·笔记·重构·pcm
折枝吖1 个月前
音视频开发-PCM 原理与 AI 模块实战
音视频·pcm
程序员老陆2 个月前
FFmpeg6 在 Windows 打开麦克风并录成 PCM:不走 Qt Multimedia,也不碰 WASAPI
windows·ffmpeg·音视频·pcm
PGCCC2 个月前
PostgreSQL 数据库认证体系技术解析:PCA / PCP / PCM 三级能力模型与考纲拆解
数据库·postgresql·pcm
砚凝霜2 个月前
软考网络工程师|第 2 章 信道延迟、传输介质、数据编码、数字调制、PCM 完整备考笔记
网络·笔记·pcm