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

AMRNB

Decodes AMRNB audio data streams into the PCM format. Currently, only single-channel decoding is supported.

The function calling process is as follows:

  1. Obtain the size of the memory to be applied for decoding (dstBufLen).
  2. Initialize the structure by calling Init.
  3. Call the main function HMPPA_Amrnb_Decode_8u16s for decoding.
  4. Call Release to release the memory allocated in the structure.

The function interface declaration is as follows:

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

    HmppResult HMPPA_Amrnb_GetDecodeDstBufLen_8u16s(const uint8_t *src, int32_t len, int32_t *dstBufLen);

  • Initialization:

    HmppResult HMPPA_Amrnb_DecodeInit_8u16s(HmppaAmrnbDecodePolicy_16s **policy);

  • Decoding:

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

  • Release:

    HmppResult HMPPA_Amrnb_DecodeRelease(HmppaAmrnbDecodePolicy_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the AMRNB stream to be decoded

The value cannot be NULL.

Input

len

Length of the data 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_MALLOC_FAILED

Memory allocation failed.

HMPP_STS_SIZE_WRN

The input data stream is not completely decoded.

Example

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <hmpp.h>

int main(int argc, char *argv[]) 
{
    if (argc < 3) {
        fprintf(stderr, "%s in.amr out.wav\n", argv[0]);
        return 1;
    }

    FILE *in = fopen(argv[1], "r");
    FILE *out = fopen(argv[2], "w+");
    if (!in || !out) {
        printf("Open file failed!\n");
        return 1;
    }

    fseek(in, 0, SEEK_END);
    int32_t srcLen = ftell(in);
    fseek(in, 0, SEEK_SET);

    HmppaAmrnbDecodePolicy_16s *policy;
    int32_t re = HMPPA_Amrnb_DecodeInit_8u16s(&policy);
    uint8_t *src = (uint8_t*)malloc(srcLen * sizeof(uint8_t));

    int32_t dstLen;
    re = HMPPA_Amrnb_GetDecodeDstBufLen_8u16s(src, srcLen, &dstLen);
    int16_t *dst = (int16_t*)malloc(dstLen * sizeof(int16_t));
    fread(src, sizeof(uint8_t), srcLen, in);

    int32_t bytesConsumed = 0;
    int64_t bytesDecoded = 0;
    re = HMPPA_Amrnb_Decode_8u16s(src, srcLen, dst, policy, &bytesConsumed, &bytesDecoded);
    printf("HmppResult:%d, bytesConsumed:%d, bytesDecoded:%d\n", re, bytesConsumed, bytesDecoded);

    re = HMPPA_Amrnb_DecodeRelease(policy);
    fwrite(dst, sizeof(int16_t), dstLen, out);

    fclose(in);
    fclose(out);

    return 0;
}

Output:

HmppResult:0, bytesConsumed:5062, bytesDecoded:50560