GSMHR
Encodes audio data streams in the PCM format into the GSMHR format.
The function calling process is as follows:
- Obtain the size of the memory to be applied for encoding (dstBufLen).
- Initialize the HmppaGsmhrEncodePolicy_16s structure by calling HMPPA_Gsmhr_EncodeInit_16s8u.
- Call the main function HMPPA_Gsmhr_Encode_16s8u for decoding.
- Call HMPPA_Gsmhr_EncodeRelease_16s8u to release the memory allocated to the HmppaGsmhrEncodePolicy_16s structure.
The function interface declaration is as follows:
- Obtaining the size of the memory to be applied for encoding:
HmppResult HMPPA_Gsmhr_GetEncodeDstBufLen_16s8u(int32_t len, int32_t *dstBufLen);
- Initialization:
HmppResult HMPPA_Gsmhr_EncodeInit_16s8u(HmppaGsmhrEncodePolicy_16s **policy);
- Encoding:
HmppResult HMPPA_Gsmhr_Encode_16s8u(const int16_t *src, int32_t len, int32_t dtx, uint8_t *dst, HmppaGsmhrEncodePolicy_16s *policy, int64_t *bytesConsumed, int32_t *bytesEncoded);
- Release:
HmppResult HMPPA_Gsmhr_EncodeRelease_16s8u(HmppaGsmhrEncodePolicy_16s *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the PCM stream to be encoded |
The value cannot be NULL. |
Input |
len |
Length of the PCM stream to be encoded, in bytes |
(0, INT_MAX] |
Input |
dtx |
Whether to enable the discontinuous transmission (DTX) function |
|
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
policy |
Pointer to the GSMHR structure |
The value cannot be NULL. |
Input/Output |
bytesConsumed |
Pointer to the data stream length (in bytes) actually consumed for encoding |
[0, len] |
Output |
bytesEncoded |
Pointer to the data stream length (in bytes) of the actual encoded output |
[0, Theoretical output data stream length after encoding] |
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 len is not a positive number. |
HMPP_STS_SIZE_WRN |
The src is not completely encoded. |
Example
#include<stdlib.h>
#include<stdio.h>
#include"hmppa.h"
#define ONE_FRAME_GSM 14
#define ONE_FRAME_PCM 160
int main(int argc, char* argv[])
{
if (argc <3) {
printf("%s in.pcm out.gsmhr\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) / 2;
int32_t dstLen;
HMPPA_Gsmhr_GetEncodeDstBufLen_16s8u(srcLen, &dstLen);
fseek(file, 0, SEEK_SET);
short src[srcLen];
unsigned char rb[dstLen];
HmppaGsmhrEncodePolicy_16s *policy;
HMPPA_Gsmhr_EncodeInit_16s8u(&policy);
FILE *out = fopen(argv[2], "wb");
fread(src, sizeof(short), srcLen, file);
long int bytesConsumed;
int bytesEncoded;
int dtx = 1;
int res = HMPPA_Gsmhr_Encode_16s8u(src, srcLen, dtx, rb, policy, &bytesConsumed, &bytesEncoded);
HMPPA_Gsmhr_EncodeRelease_16s8u(policy);
printf("bytesConsumed = %d, bytesDecoded = %d, res = %d\n", bytesConsumed, bytesEncoded, res);
fwrite(rb, sizeof(unsigned char), bytesEncoded, out);
}
Output:
bytesConsumed = 50560, bytesDecoded = 2212, res = 0