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

AMRNB

将AMRNB格式音频数据流解码成PCM格式音频数据流,目前仅支持单通道解码。

该函数调用流程如下:

  1. 调用Init初始化结构体。
  2. 调用主函数HMPPA_Amrnb_Decode_8u16s解码。
  3. 最后调用Release释放结构体所申请的内存。

函数接口声明如下:

  • 初始化函数:

    HmppResult HMPPA_Amrnb_DecodeInit_8u16s(HmppaAmrnbDecodePolicy_16s **policy);

  • 解码函数:

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

  • 释放函数:

    HmppResult HMPPA_Amrnb_DecodeRelease(HmppaAmrnbDecodePolicy_16s *policy);

参数

参数名

描述

取值范围

输入/输出

src

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

非空

输入

len

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

(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_MALLOC_FAILED

申请内存失败。

HMPP_STS_SIZE_WRN

输入的数据流未能完全解码。

示例

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <hmpp.h>

int main(int argc, char *argv[]) 
{
    if (argc < 3) {
        fprintf(stderr, "%s in.amr out.wav\n", argv[0]);
        return 1;
    }

    FILE *in = fopen(argv[1], "r");
    FILE *out = fopen(argv[2], "w+");
    if (!in || !out) {
        printf("Open file failed!\n");
        return 1;
    }

    fseek(in, 0, SEEK_END);
    int32_t srcLen = ftell(in);
    fseek(in, 0, SEEK_SET);

    HmppaAmrnbDecodePolicy_16s *policy;
    int32_t re = HMPPA_Amrnb_DecodeInit_8u16s(&policy);
    uint8_t *src = (uint8_t*)malloc(srcLen * sizeof(uint8_t));

    int dstLen = 25280; //158frame * 160 = 25280
    int16_t *dst = (int16_t*)malloc(dstLen * sizeof(int16_t));
 fread(src, sizeof(uint8_t), srcLen, in);

    int32_t bytesConsumed = 0;
    int64_t bytesDecoded = 0;
    re = HMPPA_Amrnb_Decode_8u16s(src, srcLen, dst, policy, &bytesConsumed, &bytesDecoded);
    printf("HmppResult:%d, bytesConsumed:%d, bytesDecoded:%d\n", re, bytesConsumed, bytesDecoded);

    re = HMPPA_Amrnb_DecodeRelease(policy);
    fwrite(dst, sizeof(int16_t), dstLen, out);

    fclose(in);
    fclose(out);

    return 0;
}

运行结果:

HmppResult:0, bytesConsumed:5062, bytesDecoded:50560