Rate This Document
Findability
Accuracy
Completeness
Readability

GSMFR

Decodes audio data streams in the GSM Full Rate (GSMFR) format into the PCM format.

The function calling process is as follows:

  1. Obtain the size of the memory to be applied for decoding (dstBufLen).
  2. Initialize the HmppaGsmfrDecodePolicy_16s structure by calling HMPPA_Gsmfr_DecodeInit_8u16s.
  3. Call the main function HMPPA_Gsmfr_Decode_8u16s for decoding.
  4. Call HMPPA_Gsmfr_DecodeRelease_8u16s to release the memory allocated to the HmppaGsmfrDecodePolicy_16s structure.

The function interface declaration is as follows:

  • Obtaining the size of the memory to be applied for decoding:

    HmppResult HMPPA_Gsmfr_GetDecodeDstBufLen_8u16s(int32_t len, int32_t *dstBufLen);

  • Initialization:

    HmppResult HMPPA_Gsmfr_DecodeInit_8u16s(HmppaGsmfrDecodePolicy_16s **policy);

  • Decoding:

    HmppResult HMPPA_Gsmfr_Decode_8u16s(const uint8_t *src, int32_t len, int16_t *dst, HmppaGsmfrDecodePolicy_16s *policy, int32_t *bytesConsumed, int64_t *bytesDecoded);

  • Release:

    HmppResult HMPPA_Gsmfr_DecodeRelease_8u16s(HmppaGsmfrDecodePolicy_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the GSMFR stream to be decoded

The value cannot be NULL.

Input

len

Length of the GSMFR stream to be decoded, in bytes

(0, INT_MAX]

Input

dst

Pointer to the destination vector

The value cannot be NULL.

Output

policy

Pointer to the GSMFR structure

The value cannot be 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

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 decoded.

Example

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "hmppa.h"

#define ONE_FRAME_GSM 33
#define ONE_FRAME_PCM 160

int main(int argc, char* argv[])
{
    if (argc <3) {
        printf("%s in.gsmfr out.pcm\n", argv[0]);
        return 0;
    }
    FILE *in = fopen(argv[1], "rb");
    FILE *out = fopen(argv[2], "wb");
    if (!in || !out) {
        printf("Open file failed!\n");
        return 1;
    }

    fseek(in, 0, SEEK_END);
    int32_t srcLen =ftell(in);
    int32_t dstLen;
    HMPPA_Gsmfr_GetDecodeDstBufLen_8u16s(srcLen, &dstLen);
    fseek(in, 0, SEEK_SET);
    uint8_t *src = (uint8_t*)malloc(srcLen * sizeof(uint8_t));
    int16_t *dst= (int16_t*)malloc(dstLen * sizeof(int16_t));
    fread(src, sizeof(uint8_t), srcLen, in);
    int32_t bytesConsumed;
    int64_t bytesDecoded;

    HmppaGsmfrDecodePolicy_16s *policy;
    HMPPA_Gsmfr_DecodeInit_8u16s(&policy);
    HmppResult res = HMPPA_Gsmfr_Decode_8u16s(src, srcLen, dst, policy, &bytesConsumed, &bytesDecoded);
    HMPPA_Gsmfr_DecodeRelease_8u16s(policy);
    
    printf("bytesConsumed = %d, bytesDecoded = %d, res = %d\n", bytesConsumed, bytesDecoded, res);
    fwrite(dst, sizeof(short), bytesDecoded / 2, out);
    free(src);
    free(dst);
    fclose(in);
    fclose(out);
}

Output:

bytesConsumed = 5214, bytesDecoded = 50560, res = 0