Rate This Document
Findability
Accuracy
Completeness
Readability

AMRWB

Encodes audio data streams in the PCM format into the AMRWB format.

The function calling process is as follows:

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

The function interface declaration is as follows:

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

    HmppResult HMPPA_Amrwb_GetEncodeDstBufLen_16s8u(int32_t len, int32_t *dstBufLen, HmppAmrwbMode mode);

  • Initialization:

    HmppResult HMPPA_Amrwb_EncodeInit_16s8u(HmppaAmrnbEncodePolicy_16s **policy, HmppAmrwbMode mode, int32_t dtx);

  • Encoding:

    HmppResult HMPPA_Amrwb_Encode_16s8u(const int16_t *src, int32_t len, uint8_t *dst, HmppaAmrwbEncodePolicy_16s *policy, int64_t *bytesConsumed, int32_t *bytesEncoded);

  • Release:

    HmppResult HMPPA_Amrwb_EncodeRelease_16s8u(HmppaAmrnbEncodePolicy_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the AMRWB stream to be encoded

The value cannot be NULL.

Input

len

Length of the data stream to be encoded (in dual-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 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 bytes) required to point to the destination vector

The value cannot be NULL.

Output

mode

Bit rate of the AMRWB streams to be encoded

The value is an element of HmppAmrwbMode:

HMPP_AMRWB_6600,

HMPP_AMRWB_8850,

HMPP_AMRWB_12650,

HMPP_AMRWB_14250,

HMPP_AMRWB_15850,

HMPP_AMRWB_18250,

HMPP_AMRWB_19850,

HMPP_AMRWB_23050,

HMPP_AMRWB_23850

Input

dtx

Whether to enable the discontinuous transmission (DTX) function

  • 0: disable
  • 1: enable

Input

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

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) / 2;
    fseek(in, 0, SEEK_SET);

    HmppaAmrwbEncodePolicy_16s *policy;
    int32_t re = HMPPA_Amrwb_EncodeInit_16s8u(&policy, HMPP_AMRWB_6600, 0);
    int16_t *src = (int16_t*)malloc(srcLen * sizeof(int16_t));

    int dstLen;
    re = HMPPA_Amrwb_GetEncodeDstBufLen_16s8u(srcLen, &dstLen, HMPP_AMRWB_6600);
    uint8_t *dst = (uint8_t*)malloc(dstLen * sizeof(uint8_t));
    fread(src, sizeof(int16_t), srcLen, in);

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

    re = HMPPA_Amrwb_EncodeRelease_16s8u(policy);
    fwrite(dst, sizeof(uint8_t), dstLen, out);

    fclose(in);
    fclose(out);

    return 0;
}

Output:

HmppResult:0, bytesConsumed:50560, bytesDecoded:2844