Rate This Document
Findability
Accuracy
Completeness
Readability

WAV

Encodes audio data streams in the PCM format into the Waveform Audio File Format (WAV).

The function calling process is as follows:

  1. Obtain the size of the memory to be applied for encoding (dstBufLen).
  2. Call the main function HMPPA_Wav_Encode_16s8u for encoding.

The function interface is declared as follows:

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

    HmppResult HMPPA_Wav_GetEncodeDstBufLen_16s8u(int32_t len, int32_t *dstLen);

  • Encoding:

    HmppResult HMPPA_Wav_Encode_16s8u(const int16_t *src, int32_t len, uint8_t *dst, int channels, int sampleRate);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the AMRWB stream to be encoded

Not null

Input

len

Length of the data stream to be encoded (in dual-bytes)

(0, 1073741789]

Input

dst

Pointer to the destination vector

Not null

Output

dstBufLen

Pointer to the required destination vector length (in bytes)

Not null

Output

channels

Number of audio channels

1 or 2

Input

sampleRate

Audio sampling rate

(0, INT_MAX]

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_BAD_ARG_ERR

The input of channels and sampleRate is invalid.

HMPP_STS_SIZE_ERR

The length is invalid.

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);
    int16_t *src = (int16_t*)malloc(srcLen * sizeof(int16_t));
    fread(src, sizeof(int16_t), srcLen, in);

    int32_t dstLen;
    int32_t re = HMPPA_Wav_GetEncodeDstBufLen_16s8u(srcLen, &dstLen);
    uint8_t *dst = (uint8_t*)malloc(dstLen * sizeof(uint8_t));

    re = HMPPA_Wav_Encode_16s8u(src, srcLen, dst, 1, 8000);
    printf("HmppResult:%d\n", re);
    fwrite(dst, sizeof(int16_t), dstLen, out);

    fclose(in);
    fclose(out);

    return 0;
}

Output:

HmppResult:0