---
title: EVS
description: "将EVS（Enhanced Voice Service）格式音频数据流解码成PCM（Pulse Code Modulation）格式音频数据流，目前仅支持8k采样率，5.9/7.2/8.0/9.6/13.2/16.4/24.4kbit/s码率场景的解码。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_hmpp_06_0290.html
sourcePath: /source/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_hmpp_06_0290.html
indexId: 327cdd7db576785b9f6da7af74f84412f9bf2630ec298aa5e06999789a5c793377
---
# EVS

将EVS（Enhanced Voice Service）格式音频数据流解码成PCM（Pulse Code Modulation）格式音频数据流，目前仅支持8k采样率，5.9/7.2/8.0/9.6/13.2/16.4/24.4kbit/s码率场景的解码。

该函数调用流程如下：

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

函数接口声明如下：

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

- 初始化函数：
  HmppResult HMPPA_Evs_DecodeInit_8u16s(HmppaEvsDecodePolicy_16s** policy);

- 解码函数：
  HmppResult HMPPA_Evs_Decode_8u16s(uint8_t *src, int32_t len, int16_t *dst, HmppaEvsDecodePolicy_16s*policy, int32_t *bytesConsumed, int64_t *byteDecoded);

- 释放函数：
  HmppResult HMPPA_Evs_DecodeRelease_8u16s(HmppaEvsDecodePolicy_16s* policy);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向待解码的EVS码流指针。 | 非空 | 输入 |
| len | 待解码数据流长度（以字节为单位）。 | (0, INT\_MAX] | 输入 |
| dst | 指向目的向量的指针。 | 非空 | 输出 |
| policy | 特殊结构体的指针。 | 非空 | 输入/输出 |
| bytesConsumed | 指向实际解码消耗的长度（以字节为单位）。 | [0, len] | 输出 |
| bytesDecoded | 指向实际解码输出的长度（以字节为单位）。 | [0, 理论解码len后输出的字节数] | 输出 |
| dstBufLen | 指向目的向量需要的长度（以双字节为单位）。 | 非空 | 输出 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、dst、policy中存在空指针。 |
| HMPP\_STS\_MALLOC\_FAILED | 申请内存失败。 |
| HMPP\_STS\_SIZE\_ERR | 输入的数据流长度为0或大于支持的解码长度。 |


#### 示例

```
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <hmppa.h>
int main(int argc, char *argv[]) {
FILE* in;
FILE* out;
int32_t re;
int32_t bytesConsumed = 0;
int64_t bytesDecoded = 0;
if (argc < 3) {
fprintf(stderr, "%s in.evs out.pcm\n", argv[0]);
return 1;
}
in = fopen(argv[1], "rb");
out = fopen(argv[2], "w+");
if (!in) {
perror(argv[1]);
return 1;
}
fseek(in, 0, SEEK_END);
int32_t srcLen = ftell(in);
fseek(in, 0, SEEK_SET);
uint8_t* src = (uint8_t*)malloc(srcLen * sizeof(uint8_t));
int32_t n = fread(src, sizeof(uint8_t), srcLen, in);
if (n != srcLen) {
return -1;
}
HmppaEvsDecodePolicy_16s *policy;
re = HMPPA_Evs_DecodeInit_8u16s(&policy);
int32_t dstLen;
re = HMPPA_Evs_GetDecodeDstBufLen_8u16s(src, srcLen, &dstLen);
int16_t* dst = (int16_t*)malloc(dstLen * sizeof(int16_t));
if (re != HMPP_STS_NO_ERR) {
return 0;
}
re = HMPPA_Evs_Decode_8u16s(src, srcLen, dst, policy, &bytesConsumed, &bytesDecoded);
if (re == HMPP_STS_NO_ERR) {
fwrite(dst, sizeof(int16_t), dstLen, out);
printf("SUCCESS: srcLen:%d, HmppResult:%d, bytesConsumed:%d, bytesDecoded:%d\n", srcLen, re, bytesConsumed, bytesDecoded);
} else {
printf("WRONG: srcLen:%d, HmppResult:%d, bytesConsumed:%d, bytesDecoded:%d\n", srcLen, re, bytesConsumed, bytesDecoded);
}
re = HMPPA_Evs_DecodeRelease_8u16s(policy);
fclose(in);
fclose(out);:q
return 0;
}
```

运行结果：

```
SUCCESS: srcLen:25296, HmppResult:0, bytesConsumed:50592, bytesDecoded:130560
```
