GSMEFR
Decodes GSM enhanced full rate (GSMEFR) audio streams to int16 PCM data streams.
The function calling process is as follows:
- Obtain the size of the memory to be applied for decoding (dstBufLen).
- Initialize the HmppaGsmefrDecodePolicy_16s structure by calling HMPPA_Gsmefr_DecodeInit_8u16s.
- Call the main function HMPPA_Gsmefr_Decode_8u16s for decoding.
- Call HMPPA_Gsmefr_DecodeRelease_8u16s to release the memory allocated to the HmppaGsmefrDecodePolicy_16s structure.
The function interface declaration is as follows:
- Obtaining the size of the memory to be applied for decoding:
HmppResult HMPPA_Gsmefr_GetDecodeDstBufLen_8u16s(int32_t len, int32_t *dstBufLen);
- Initialization:
HmppResult HMPPA_Gsmefr_DecodeInit_8u16s(HmppaGsmefrDecodePolicy_16s** policy);
- Decoding:
HmppResult HMPPA_Gsmefr_Decode_8u16s(const uint8_t* src, int32_t srcLen, int16_t* dst, HmppaGsmefrDecodePolicy_16s* policy, int32_t* bytesConsumed, int64_t* bytesDecoded);
- Release:
HmppResult HMPPA_Gsmefr_DecodeRelease_8u16s(HmppaGsmefrDecodePolicy_16s* policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
policy (in the Init function) |
Pointer to pointer to the GSMEFR Policy structure |
The value cannot be NULL. |
Output |
policy (in the main and release functions) |
Pointer to the GSMEFR structure |
The value cannot be NULL. |
Input |
src |
Pointer to the input data to be decoded |
The value cannot be NULL. |
Input |
srcLen |
Length of the input data |
Non-negative |
Input |
dst |
Pointer to the output decoded data |
The value cannot be NULL. |
Output |
bytesConsumed |
Pointer to the data stream length (in bytes) actually consumed for decoding |
The value cannot be NULL. |
Output |
bytesDecoded |
Pointer to the data stream length (in bytes) of the actual decoded output |
This parameter can be empty. |
Output |
dstBufLen |
Length (in duel-bytes) required to point to the destination vector |
The value cannot be 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 |
Any of the input pointers is NULL. |
HMPP_STS_SIZE_ERR |
The value of srcLen is not a positive number. |
HMPP_STS_SIZE_WRN |
The src is not completely decoded. |
Example
#include<stdlib.h>
#include<stdio.h>
#include"hmppa.h"
#define ONE_FRAME_GSM 31
#define ONE_FRAME_PCM 160
int main(int argc, char* argv[])
{
if (argc <3) {
printf("%s in.gsmefr 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_Gsmefr_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);
fseek(file, 0, SEEK_SET);
unsigned char src[srcLen];
short pcm[dstLen];
HmppaGsmefrDecodePolicy_16s *policy;
HMPPA_Gsmefr_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;
int64_t bytesDecoded;
int res = HMPPA_Gsmefr_Decode_8u16s(src, srcLen, pcm, policy, &bytesConsumed, &bytesDecoded);
HMPPA_Gsmefr_DecodeRelease_8u16s(policy);
printf("bytesConsumed = %d, bytesDecoded = %d, res = %d\n", bytesConsumed, bytesDecoded, res);
fwrite(pcm, sizeof(short), bytesDecoded / 2, out);
}
Output:
bytesConsumed = 4898, bytesDecoded = 50560, res = 0