CM OPUS Encode

The cmOpusEncode is used to encode the audio/x-raw(PCM) data to audio/x-opus(OPUS) data by the OPUS library.


API Instructions

create/destroy

gpointer cm_opus_encode_create(); void cm_opus_encode_destroy(gpointer hd);

start/stop

void cm_opus_encode_start(gpointer hd); void cm_opus_encode_stop(gpointer hd);

parameters

/* @type Supports 2049(generic), 2048(voice), 2051(low delay), default is 2048 */ void cm_opus_encode_set_audio_type(gpointer hd, int type); /* @br:4000-65000, default 64000 */ void cm_opus_encode_set_bitrate(gpointer hd, int br); /* @type Supports 0(cbr), 1(vbr), 2(constrained br), default is 1 */ void cm_opus_encode_set_bitrate_type(gpointer hd, int type); /* @size Duration per frames in ms, supports 2(2.5), 5, 10, 20, 40, 60, default is 10 */ void cm_opus_encode_set_frame_size(gpointer hd, int size);

data

The encoder needs to know the actual format of the input before encoding, so must ensure the source is ready to be linked(the media info is ready).

others


Demo

Opus PV to PB Demo

Structure

Get raw data and encode to opus, then decode them and send to speaker to play.

image-20240520-071811.png

Main codes

For more details please refer to the demo file.

Test result

The speaker can hear the sound from the microphone.

image-20240520-071916.png

Â