---
title: EVS
description: "将PCM格式音频数据流编码成EVS（Enhanced Voice Service）格式音频数据流。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_hmpp_06_0293.html
sourcePath: /source/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_hmpp_06_0293.html
indexId: 80e47f8865456c54953cae6f8bc86919cb6cd5e35ff214be866d0b363e7a414277
---
# EVS

将PCM格式音频数据流编码成EVS（Enhanced Voice Service）格式音频数据流。

该函数调用流程如下：

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

函数接口声明如下：

- 获取编码需要申请的内存大小：
  HmppResult HMPPA_Evs_GetEncodeDstBufLen_16s8u(int32_t len, int32_t *dstBufLen, HmppEvsMode mode)

- 初始化函数：
  HmppResult HMPPA_Evs_EncodeInit_16s8u(HmppaEvsEncodePolicy_16s **policy, HmppEvsMode mode, int32_t allowDtx);

- 编码函数：
  HmppResult HMPPA_Evs_Encode_16s8u(const int16_t *src, int32_t len, uint8_t *dst, HmppaEvsEncodePolicy_16s *policy, int64_t *bytesConsumed, int32_t *bytesEncoded);

- 释放函数：
  HmppResult HMPPA_Evs_EncodeRelease_16s8u(HmppaEvsEncodePolicy_16s *policy);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向待编码的数据流指针。 | 非空 | 输入 |
| len | 待编码的数据流长度。 | >0 | 输入 |
| dst | 指向目的向量的指针。 | 非空 | 输出 |
| policy | 特殊结构体的指针。 | 非空 | 输入/输出 |
| bytesConsumed | 指向实际编码消耗的长度（以字节为单位）。 | >=0 | 输出 |
| bytesEncoded | 指向实际编码输出的长度（以字节为单位）。 | >=0 | 输出 |
| dstBufLen | 指向目的向量需要的长度（以字节为单位）。 | 非空 | 输出 |
| mode | 待编码的EVS码流的比特率。 | 由结构体定义 | 输入 |
| allowDtx | 是否开启DTX（非连续传输）功能的标志。 | 0：关闭DTX 1：开启DTX | 输入 |


#### 返回值

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


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、dst、policy中存在空指针。 |
| HMPP\_STS\_BAD\_ARG\_ERR | 输入参数范围错误。 |
| HMPP\_STS\_UNSUPPORT\_PARA | 不支持的编码格式。 |
| HMPP\_STS\_SIZE\_ERR | 输入的待编码数据长度为0。 |
| HMPP\_STS\_MALLOC\_FAILED | 申请内存失败。 |


#### 示例

```
#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) / 2;
fseek(in, 0, SEEK_SET);
int16_t *src = (int16_t*)malloc(srcLen * sizeof(int16_t));
fread(src, sizeof(int16_t), srcLen, in);
HmppaAmrnbEncodePolicy_16s *policy;
int32_t re = HMPPA_Evs_EncodeInit_16s8u(&policy, HMPP_EVS_6600, 0);
int dstLen;
re = HMPPA_Evs_GetEncodeDstBufLen_16s8u(srcLen, &dstLen, HMPP_EVS_6600);
uint8_t *dst = (uint8_t*)malloc(dstLen * sizeof(uint8_t));
int64_t bytesConsumed = 0;
int32_t bytesEncoded = 0;
re = HMPPA_Evs_Encode_16s8u(src, srcLen, dst, policy, &bytesConsumed, &bytesEncoded);
printf("HmppResult:%d, bytesConsumed:%d, bytesEncoded:%d\n", re, bytesConsumed, bytesEncoded);
re = HMPPA_Evs_EncodeRelease_16s8u(policy);
fwrite(dst, sizeof(uint8_t), bytesEncoded, out);
fclose(in);
fclose(out);
return 0;
}
```

运行结果：

```
HmppResult:0, bytesConsumed:50560, bytesDecoded:2054
```
