---
title: GSMFR
description: "将GSMFR（GSM Full Rate）格式音频数据流解码成PCM格式音频数据流。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_hmpp_06_0208.html
sourcePath: /source/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_hmpp_06_0208.html
indexId: d8d9e6a6302b0ae1f1f37410c6d50f9c616b2255dba29c39b29839e86aa1f82377
---
# GSMFR

将GSMFR（GSM Full Rate）格式音频数据流解码成PCM格式音频数据流。

该函数调用流程如下：

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

函数接口声明如下：

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

- 初始化函数：
  HmppResult HMPPA_Gsmfr_DecodeInit_8u16s(HmppaGsmfrDecodePolicy_16s **policy);

- 解码函数：
  HmppResult HMPPA_Gsmfr_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaGsmfrDecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);

- 释放函数：
  HmppResult HMPPA_Gsmfr_DecodeRelease_8u16s(HmppaGsmfrDecodePolicy_16s *policy);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向待解码的GSMFR码流指针。 | 非空 | 输入 |
| len | 待解码GSMFR码流长度（以字节为单位）。 | (0, INT\_MAX] | 输入 |
| dst | 指向目的向量的指针。 | 非空 | 输出 |
| policy | 指向GSMFR结构体的指针。 | 非空 | 输入/输出 |
| 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 <stdint.h>
#include "hmppa.h"
#define ONE_FRAME_GSM 33
#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 *in = fopen(argv[1], "rb");
FILE *out = fopen(argv[2], "wb");
if (!in || !out) {
printf("Open file failed!\n");
return 1;
}
fseek(in, 0, SEEK_END);
int32_t srcLen =ftell(in);
int32_t dstLen;
HMPPA_Gsmfr_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);
fseek(in, 0, SEEK_SET);
uint8_t *src = (uint8_t*)malloc(srcLen * sizeof(uint8_t));
int16_t *dst= (int16_t*)malloc(dstLen * sizeof(int16_t));
fread(src, sizeof(uint8_t), srcLen, in);
int32_t bytesConsumed;
int64_t bytesDecoded;
HmppaGsmfrDecodePolicy_16s *policy;
HMPPA_Gsmfr_DecodeInit_8u16s(&policy);
HmppResult res = HMPPA_Gsmfr_Decode_8u16s(src, srcLen, dst, policy, &bytesConsumed, &bytesDecoded);
HMPPA_Gsmfr_DecodeRelease_8u16s(policy);
printf("bytesConsumed = %d, bytesDecoded = %d, res = %d\n", bytesConsumed, bytesDecoded, res);
fwrite(dst, sizeof(short), bytesDecoded / 2, out);
free(src);
free(dst);
fclose(in);
fclose(out);
}
```

运行结果：

```
bytesConsumed = 5214, bytesDecoded = 50560, res = 0
```
