EVS
Decodes Enhanced Voice Service (EVS) audio data streams into pulse code modulation (PCM) streams. It supports 8 kHz sampling rate and 5.9, 7.2, 8.0, 9.6, 13.2, 16.4, and 24.4 kbit/s bit rates.
The function is called as follows:
- Obtain the size of the memory to be applied for decoding (DstBufLen).
- Initialize the structure by calling Init.
- Call the main function HMPPA_Evs_Decode_8u16s for decoding.
- Call Release to release the memory allocated to the structure.
The function interface is declared as follows:
- Obtaining the size of the memory to be applied for decoding:
HmppResult HMPPA_Evs_GetDecodeDstBufLen_8u16s(const uint8_t *src, int32_t len, int32_t *dstBufLen);
- Initialization:
HmppResult HMPPA_Evs_DecodeInit_8u16s(HmppaEvsDecodePolicy_16s** policy);
- Decoding:
HmppResult HMPPA_Evs_Decode_8u16s(uint8_t *src, int32_t len, int16_t *dst, HmppaEvsDecodePolicy_16s*policy, int32_t *bytesConsumed, int64_t *byteDecoded);
- Release:
HmppResult HMPPA_Evs_DecodeRelease_8u16s(HmppaEvsDecodePolicy_16s* policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the EVS stream to be decoded |
Not null |
Input |
len |
Length of the data stream to be decoded, in bytes |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
Not null |
Output |
policy |
Pointer to the special structure |
Not null |
Input/Output |
bytesConsumed |
Pointer to the data stream length (in bytes) actually consumed for decoding |
[0, len] |
Output |
bytesDecoded |
Pointer to the data stream length (in bytes) of the actual decoded output |
[0, Theoretical output data stream length after decoding] |
Output |
dstBufLen |
Pointer to the required destination vector length (in duel-bytes) |
Not null |
Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src, dst, or policy is NULL. |
HMPP_STS_MALLOC_FAILED |
Memory allocation failed. |
HMPP_STS_SIZE_WRN |
The input data stream is not completely decoded. |
HMPP_STS_BAD_ARG_ERR |
The format of the input data stream is incorrect. The protocol or bit rate is not supported. |
Example
#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;
}
Output:
SUCCESS: srcLen:25296, HmppResult:0, bytesConsumed:50592, bytesDecoded:130560