codec - Multimedia-Codec#

Adapted Air780E/Air700E Air780EP Air601 Air101/Air103 Air105

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view the demo example of codec

Constant#

constant

type

explanation

codec.MP3

number

MP3 Format

codec.WAV

number

WAV Format

codec.AMR

number

AMR-NB format, in a general sense AMR

codec.AMR_WB

number

AMR-WB Format

codec.create(type, isDecoder, quality)#

Create a codec codec

Parameters

Incoming Value Type

Explanation

int

multimedia type, currently supported codec.MP3 codec.AMR

boolean

Is it a decoder, true decoder, false encoder, default true, is a decoder

int

encoding level. some bsps have internal encoders. you may need to enter the encoding level in advance, such as the internal amr encoder of a air780ep.

Return Value

return value type

explanation

userdata

Returns a data structure on success, otherwise nil

Examples

-- Create Decoder
local decoder = codec.create(codec.MP3)--Create an mp3 decoder
-- Create Encoder
local encoder = codec.create(codec.AMR, false)--Create an AMR encoder
-- Create Encoder
local encoder = codec.create(codec.AMR_WB, false, 8)--Create a amr-wb encoder with the default encoding level 8

codec.info(decoder, file_path)#

decoder Parsing audio information from a file

Parameters

Incoming Value Type

Explanation

userdata

for decoding decoder

string

File Path

Return Value

return value type

explanation

boolean

Whether the resolution was successful

int

Audio Format

int

Number of sound channels

int

Sampling frequency

int

Number of sampling bits

boolean

Is there a symbol

Examples

local result, audio_format, num_channels, sample_rate, bits_per_sample, is_signed= codec.info(coder, "xxx")

codec.data(decoder, out_buff)#

decoder Parse the original audio data from the file, for example, parse the PCM data from the MP3 file. The file path here has already been passed in to codec.info and does not need to be passed in again.

Parameters

Incoming Value Type

Explanation

userdata

for decoding decoder

zbuff

Zbuff for storing output data, space must be no less 16KB

int

How many bytes of audio data are decoded at least, by default 16384

Return Value

return value type

explanation

boolean

Whether the resolution was successful

Examples

-- Large Memory Device
local buff = zbuff.create(16*1024)
local result = codec.data(coder, buff)
-- Small Memory Device
local buff = zbuff.create(8*1024)
local result = codec.data(coder, buff, 4096)

codec.encode(coder, in_buffer, out_buffer, mode)#

for encoding audio data, flash and ram space are generally limited, except that some bsps have internal amr encoding function, currently only amr-nb encoding is supported.

Parameters

Incoming Value Type

Explanation

userdata

codec.create Used for the created codec coder

zbuff

input data, zbuff form, from 0 used

zbuff

The output data, in the form of zbuff, is automatically added to the tail of the buff. If the space is insufficient, it will automatically expand, but it will consume extra time and even fail, so try to give enough space at the beginning.

int

amr_nb The larger the encoding level of 0 to 7 (that is, MR475 to MR122), the more space consumed and the higher the sound quality. The default encoding level of 0 amr_wb is 0 to 8. The larger the value, the more space consumed and the higher the sound quality. The default 0

Return Value

return value type

explanation

boolean

Returns true on success and true on failure false

Examples

codec.encode(amr_coder, inbuf, outbuf, codec.AMR_)

codec.release(coder)#

For release codec coder

Parameters

Incoming Value Type

Explanation

coder

codec.create Used for the created codec coder

Return Value

None

Examples

codec.release(coder)