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

AMRWB

Decodes audio data streams in the adaptive multi-rate wideband (AMRWB) format 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_Amrwb_Decode_8u16s for decoding.
  4. Call Release to release the memory allocated to the structure.

The function interface is declared as follows:

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

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

  • Initialization:

    HmppResult HMPPA_Amrwb_DecodeInit_8u16s(HmppaAmrwbDecodePolicy_16s** policy);

  • Decoding:

    HmppResult HMPPA_Amrwb_Decode_8u16s(uint8_t *src, int32_t len, int16_t *dst, HmppaAmrwbDecodePolicy_16s*policy, int32_t *bytesConsumed, int64_t *byteDecoded);

  • Release:

    HmppResult HMPPA_Amrwb_DecodeRelease_8u16s(HmppaAmrwbDecodePolicy_16s* policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the AMRWB stream to be decoded

Not null

Input

len

Length of the data stream to be decoded, in bytes

(0, INT_MAX]

Input

dst

Pointer to the destination vector

Not null

Output

policy

Pointer to the special structure

Not 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

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

HMPP_STS_HEAD_ERR

Incorrect header information of the input data stream. That is, the input data stream is not in the AMRWB audio format.

Example

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hmppa.h>

#define FRAMES 158

int main(int argc, char *argv[]) {
    FILE* in;
    FILE* out;
    int32_t re;
    int32_t bytesConsumed = 0;
    int64_t bytesDecoded = 0;
    if (argc < 3) {
        fprintf(stderr, "%s in.amr out.pcm\n", argv[0]);
        return 1;
    }

    in = fopen(argv[1], "rb");
    out = fopen(argv[2], "w+");
    if (!in) {
        perror(argv[1]);
        return 1;
    }

    fseek(in, 0, SEEK_END);
    int32_t srcLen = ftell(in);
    fseek(in, 0, SEEK_SET);
    uint8_t* src = (uint8_t*)malloc(srcLen * sizeof(uint8_t));
    int32_t n = fread(src, 1, srcLen, in);
    if (n != srcLen) {
        return -1;
    }

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

    HmppaAmrwbDecodePolicy_16s *amrwb = NULL;
    re = HMPPA_Amrwb_DecodeInit_8u16s(&amrwb);
    if (re != HMPP_STS_NO_ERR) {
        return 0;;
    }
    re = HMPPA_Amrwb_Decode_8u16s(src, srcLen, dst, amrwb, &bytesConsumed, &bytesDecoded);
    if (re == HMPP_STS_NO_ERR) {
        fwrite(dst, 2, dstLen, out);
        printf("SUCCESS: result = %d, bytesConsumed = %d, bytesDecoded = %lld\n", re, bytesConsumed, bytesDecoded);
    } else if (re == HMPP_STS_SIZE_WRN) {
        fwrite(dst, 2, dstLen, out);
        printf("WARNING: result = %d, bytesConsumed = %d, bytesDecoded = %lld\n", re, bytesConsumed, bytesDecoded);
    } else {
        printf("WRONG: result = %d, bytesConsumed = %d, bytesDecoded = %lld\n", re, bytesConsumed, bytesDecoded);
    }

    re = HMPPA_Amrwb_DecodeRelease_8u16s(amrwb);
    fclose(in);
    fclose(out);

    return 0;
}

Output:

SUCCESS: result = 0, bytesConsumed = 9647, bytesDecoded = 50560