GSMHR
将112位的GSMHR格式音频数据流解码成PCM格式音频数据流。
该函数调用流程如下:
- 调用HMPPA_Gsmhr_DecodeInit_8u16s初始化HmppaGsmhrDecodePolicy_16s结构体。
- 调用主函数HMPPA_Gsmhr_Decode_8u16s解码。
- 最后调用HMPPA_Gsmhr_DecodeRelease_8u16s释放HmppaGsmhrDecodePolicy_16s结构体所包含的内存。
函数接口声明如下:
- 初始化函数:
HmppResult HMPPA_Gsmhr_DecodeInit_8u16s(HmppaGsmhrDecodePolicy_16s **policy);
- 解码函数:
HmppResult HMPPA_Gsmhr_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaGsmhrDecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);
- 释放函数:
HmppResult HMPPA_Gsmhr_DecodeRelease_8u16s(HmppaGsmhrDecodePolicy_16s *policy);
参数
参数名 |
描述 |
取值范围 |
输入/输出 |
|---|---|---|---|
src |
指向待解码的GSMHR码流指针。 |
非空 |
输入 |
len |
待解码GSMHR码流长度(以字节为单位)。 |
(0, INT_MAX] |
输入 |
dst |
指向目的向量的指针。 |
非空 |
输出 |
policy |
指向GSMHR结构体的指针。 |
非空 |
输入/输出 |
bytesConsumed |
指向实际解码消耗的长度(以字节为单位)。 |
|
输出 |
bytesDecoded |
指向实际解码输出的长度(以字节为单位)。 |
|
输出 |
返回值
- 成功:返回HMPP_STS_NO_ERR。
- 失败:返回错误码。
错误码
错误码 |
描述 |
|---|---|
HMPP_STS_NULL_PTR_ERR |
指针参数中包含空指针。 |
HMPP_STS_SIZE_ERR |
len不为正数。 |
HMPP_STS_SIZE_WRN |
src未全部解码。 |
示例
#include<stdlib.h>
#include<stdio.h>
#include"hmppa.h"
#define ONE_FRAME_GSM 14
#define ONE_FRAME_PCM 160
int main(int argc, char* argv[])
{
if (argc <3) {
printf("%s in.gsmfr out.pcm\n", argv[0]);
return 0;
}
FILE *file =fopen(argv[1], "rb");
if (file ==NULL) {
printf("Open File %s Failed\n", argv[1]);
return 0;
}
fseek(file, 0, SEEK_END);
int srcLen =ftell(file);
int dstLen = srcLen / ONE_FRAME_GSM * ONE_FRAME_PCM;
fseek(file, 0, SEEK_SET);
unsigned char src[srcLen];
short pcm[dstLen];
HmppaGsmhrDecodePolicy_16s *policy;
HMPPA_Gsmhr_DecodeInit_8u16s(&policy);
FILE *out = fopen(argv[2], "wb");
if (out == NULL) {
printf("Open File %s Failed\n", argv[2]);
return 0;
}
fread(src, sizeof(unsignedchar), srcLen, file);
int bytesConsumed, bytesDecoded;
int res = HMPPA_Gsmhr_Decode_8u16s(src, srcLen, pcm, policy, &bytesConsumed, &bytesDecoded);
HMPPA_Gsmhr_DecodeRelease_8u16s(policy);
printf("bytesConsumed = %d, bytesDecoded = %d, res = %d\n", bytesConsumed, bytesDecoded, res);
fwrite(pcm, sizeof(short), bytesDecoded / 2, out);
}
运行结果:
bytesConsumed = 2212, bytesDecoded = 50560, res = 0
父主题: 音频库接口函数