---
title: GSMHR
description: "将112位的GSMHR（GSM Half Rate）格式音频数据流解码成PCM格式音频数据流。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_hmpp_06_0209.html
sourcePath: /source/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_hmpp_06_0209.html
indexId: 8e4c64f1cfad9718fc33b5b161391666a77aac645f461dbfc3499fbbf785f97c77
---
# GSMHR

将112位的GSMHR（GSM Half Rate）格式音频数据流解码成PCM格式音频数据流。

该函数调用流程如下：

1. 获取解码需要申请的内存大小dstBufLen。
2. 调用HMPPA_Gsmhr_DecodeInit_8u16s初始化HmppaGsmhrDecodePolicy_16s结构体。
3. 调用主函数HMPPA_Gsmhr_Decode_8u16s解码。
4. 最后调用HMPPA_Gsmhr_DecodeRelease_8u16s释放HmppaGsmhrDecodePolicy_16s结构体所包含的内存。

函数接口声明如下：

- 获取解码需要申请的内存大小：
  HmppResult HMPPA_Gsmhr_GetDecodeDstBufLen_8u16s(const uint8_t *src, int32_t len, int32_t *dstBufLen);

- 初始化函数：
  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 | 指向实际解码消耗的长度（以字节为单位）。 | [0, len] | 输出 |
| bytesDecoded | 指向实际解码输出的长度（以字节为单位）。 | [0, 理论解码len后输出的字节数] | 输出 |
| dstBufLen | 指向目的向量需要的长度（以双字节为单位）。 | 非空 | 输出 |


#### 返回值

- 成功：返回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.gsmhr 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);
int32_t srcLen =ftell(file);
int32_t dstLen;
HMPPA_Gsmhr_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);
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
```
