EN
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

G726

将G726格式音频数据流解码成PCM格式音频数据流。支持大小端比特流格式。

该函数调用流程如下:

  1. 调用HMPPA_G726_DecodeInit_8u16s初始化HmppaG726DecodePolicy_16s。
  2. 调用主函数HMPPA_G726_Decode_8u16s。
  3. 最后调用HMPPA_G726_DecodeRelease_8u16s释放HmppaG726DecodePolicy_16s所包含的内存。

函数接口声明如下:

  • 初始化函数:

    HmppResult HMPPA_G726_DecodeInit_8u16s(HmppSpchBitRate rate, int32_t littleEndian, HmppaG726DecodePolicy_16s **policy);

  • 解码函数:

    HmppResult HMPPA_G726_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaG726DecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);

  • 释放函数:

    HmppResult HMPPA_G726_DecodeRelease_8u16s(HmppaG726DecodePolicy_16s *policy);

参数

参数名

描述

取值范围

输入/输出

rate

G726语音码率。

HMPP_SPCHBR_16000、 HMPP_SPCHBR_24000、

HMPP_SPCHBR_32000、 HMPP_SPCHBR_40000之一。

输入

littleEndian

表征726码流大小端格式的参数。

  • 0:表示码流为大端格式。
  • 1:表示码流为小端格式。

输入

src

指向待解码的G726码流指针。

非空。

输入

len

待解码G726码流长度(以字节为单位)。

(0, INT_MAX]

输入

dst

指向目的向量的指针。

非空。

输出

policy

特殊结构体的指针。

非空。

输入/输出

bytesConsumed

指向实际解码消耗的长度(以字节为单位)。

  • 输入:空或者非空。
  • 输出:当输入为空,不输出;当输入为非空时,输出范围为[0, len]

输出

bytesDecoded

指向实际解码输出的长度(以字节为单位)。

  • 输入:空或者非空
  • 输出:当输入为空,不输出;当输入为非空时,输出范围为[0, 理论解码len后输出的字节数]

输出

返回值

  • 成功:返回HMPP_STS_NO_ERR
  • 失败:返回错误码。

错误码

错误码

描述

HMPP_STS_NULL_PTR_ERR

src、dst、policy中存在空指针。

HMPP_STS_SIZE_ERR

len小于或者等于0。

HMPP_STS_BAD_ARG_ERR

rate、policy结构体成员不合法。

HMPP_STS_MALLOC_FAILED

申请内存失败。

HMPP_STS_SIZE_WRN

len * 8不是每个采样点比特数的整数倍。

示例

#include <stdio.h>
#include <stdlib.h>
#include "hmpp.h"

#define AUDIO_INBUF_SIZE 20480
#defien BIG_ENDIAN_G726 0

int main(int argc, char **argv)
{
    if (argc <= 3) {
        fprintf(stderr, "Usage: %s <bitrates index> <input file> <output file>\n", argv[0]);
        exit(0);
    }
    const char *outFilename, *inFilename;
    int32_t bitrate = atoi(argv[1]);
    inFilename = argv[2];
    outFilename = argv[3];
    uint8_t *data;
    int32_t dataSize;
    int32_t bytesConsumered = 0;
    int64_t bytesDecoded = 0;
	
    FILE *inFile = fopen(inFilename, "rb");
    if(NULL == inFile){
        printf("%s:[%d] open %s file failed\n",__FUNCTION__,__LINE__,inFilename);
        return -1;
    }

    FILE *outFile = fopen(outFilename, "wb");
    if(NULL == outFile){
        printf("%s:[%d] open %s file failed\n",__FUNCTION__,__LINE__,outFilename);
        return -1;
    }

    HmppaG726DecodePolicy_16s *policy;
    HmppResult result = HMPPA_G726_DecodeInit_8u16s((HmppSpchBitRate)bitrate, BIG_ENDIAN_G726, &policy);
    if (result != HMPP_STS_NO_ERR) {
        printf("HMPPA_G729_DecodeInit_8u16s return : %d\n", result);
    }

    fseek(inFile, 0, SEEK_END);
    int srcLen = ftell(inFile);
    fseek(inFile, 0, SEEK_SET);

    uint8_t *inBuf = (uint8_t*)malloc(srcLen * sizeof(uint8_t));
    int16_t *outBuf = HMPPS_Malloc_16s(srcLen * 4);
    fread(inBuf, sizeof(uint8_t), srcLen, inFile);
    dataSize = srcLen;

    result = HMPPA_G726_Decode_8u16s(inBuf, dataSize, outBuf, policy, &bytesConsumered, &bytesDecoded);
    fwrite(outBuf, 1, bytesDecoded, outFile);
    printf("HmppResult: %d, bytesConsumed: %d, bytesDecoded: %d\n", result, bytesConsumered, bytesDecoded);

    HMPPA_G726_DecodeRelease_8u16s(policy);
    HMPP_Free(outBuf);
    fclose(inFile);
    fclose(outFile);
	
    return 0;
}

运行结果:

HmppResult: 0, bytesConsumed: 533504, bytesDecoded: 4268032