我要评分
获取效率
正确性
完整性
易理解

G726

Decodes G726 audio data streams into the PCM format. Big-endian and little-endian bit stream formats are supported.

The function calling process is as follows:

  1. Obtain the size of the memory to be applied for decoding (dstBufLen).
  2. Initialize the HmppaG726DecodePolicy_16s by calling HMPPA_G726_DecodeInit_8u16s.
  3. Call the main function HMPPA_G726_Decode_8u16s.
  4. Call HMPPA_G726_DecodeRelease_8u16s to release the memory allocated to the HmppaG726DecodePolicy_16s structure.

The function interface declaration is as follows:

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

    HmppResult HMPPA_G726_GetDecodeDstBufLen_8u16s(int32_t len, int32_t *dstBufLen, HmppSpchBitRate rate);

  • Initialization:

    HmppResult HMPPA_G726_DecodeInit_8u16s(HmppSpchBitRate rate, int32_t littleEndian, HmppaG726DecodePolicy_16s **policy);

  • Decoding:

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

  • Release:

    HmppResult HMPPA_G726_DecodeRelease_8u16s(HmppaG726DecodePolicy_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

rate

Bit rate of the G726 audio stream

HMPP_SPCHBR_16000, HMPP_SPCHBR_24000, HMPP_SPCHBR_32000, or HMPP_SPCHBR_40000

Input

littleEndian

Endian mode of the G726 stream

  • 0: big endian
  • 1: little endian

Input

src

Pointer to the G726 stream to be decoded

The value cannot be NULL.

Input

len

Length of the G726 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 special 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

The value of src, dst, or policy is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0.

HMPP_STS_BAD_ARG_ERR

A member of the rate or policy structure is invalid.

HMPP_STS_MALLOC_FAILED

Memory allocation failed.

HMPP_STS_SIZE_WRN

The product of len x 8 is not an integral multiple of the number of bits at each sampling point.

Example

#include <stdio.h>
#include <stdlib.h>
#include "hmpp.h"
#define AUDIO_INBUF_SIZE 20480
#define BIG_ENDIAN_G726 0
int main(int argc, char **argv)
{
    if (argc <= 3) {
        fprintf(stderr, "Usage: %s <bitrates index> <input file> <output file>\n", argv[0]);
        exit(0);
    }
    const char *outFilename, *inFilename;
    int32_t bitrate = atoi(argv[1]);
    inFilename = argv[2];
    outFilename = argv[3];
    uint8_t *data;
    int32_t dataSize;
    int32_t bytesConsumered = 0;
    int64_t bytesDecoded = 0;
    FILE *inFile = fopen(inFilename, "rb");
    if (NULL == inFile) {
        printf("%s:[%d] open %s file failed\n", __FUNCTION__, __LINE__, inFilename);
        return -1;
    }
    FILE *outFile = fopen(outFilename, "wb");
    if (NULL == outFile) {
        printf("%s:[%d] open %s file failed\n", __FUNCTION__, __LINE__, outFilename);
        return -1;
    }
    HmppaG726DecodePolicy_16s *policy;
    HmppResult result = HMPPA_G726_DecodeInit_8u16s((HmppSpchBitRate)bitrate, BIG_ENDIAN_G726, &policy);
    if (result != HMPP_STS_NO_ERR) {
        printf("HMPPA_G729_DecodeInit_8u16s return : %d\n", result);
    }
    fseek(inFile, 0, SEEK_END);
    int32_t srcLen = ftell(inFile);
    fseek(inFile, 0, SEEK_SET);
    int32_t dstLen;
    HMPPA_G726_GetDecodeDstBufLen_8u16s(srcLen, &dstLen, (HmppSpchBitRate)bitrate);
    uint8_t *inBuf = HMPP_Malloc(srcLen);
    int16_t *outBuf = HMPPS_Malloc_16s(dstLen);
    fread(inBuf, sizeof(uint8_t), srcLen, inFile);
    dataSize = srcLen;
    result = HMPPA_G726_Decode_8u16s(inBuf, dataSize, outBuf, policy, &bytesConsumered, &bytesDecoded);
    fwrite(outBuf, 1, bytesDecoded, outFile);
    printf("HmppResult: %d, bytesConsumed: %d, bytesDecoded: %d\n", result, bytesConsumered, bytesDecoded);
    HMPPA_G726_DecodeRelease_8u16s(policy);
    HMPP_Free(inBuf);
    HMPP_Free(outBuf);
    fclose(inFile);
    fclose(outFile);
    return 0;
}

Output:

HmppResult: 0, bytesConsumed: 533504, bytesDecoded: 4268032