Opus 低延迟音频编解码器API手册中文翻译

更新时间:2024-06-02 23:21:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Opus:IETF低延迟音频编解码器:API和操作手册

Opus简介

Opus编解码器是专门设计用于互联网的交互式语音和音频传输。它是由IETF的编解码器工作组设计的,合并了Skype的SILK和Xiph. Org的CELT技术。

Opus编解码器的设计目的是处理广泛的交互式音频应用程序,包括IP语音,视频,游戏内聊天,甚至远程现场音乐表演。它可以适用于从低码率窄带语音到非常高质量的立体声音乐。它的主要特点是:

? ? ? ? ? ? ? ? ? ?

采样率从8至48 kHz

比特率从6kb/s到510kb/s

对固定码率(CBR)和可变码率(VBR)都能支持 从窄带到宽带的音频带宽 支持语音和音乐 支持单声道和立体声

支持多通道(最多255通道) 帧规格从2.5毫秒到60毫秒

良好的损失鲁棒性和包丢失隐藏性(PLC)(注:应是指丢包也不容易被发现)

浮点和定点执行

文档包括:

? ? ? ? ? ?

Opus Encoder Opus Decoder Repacketizer

Opus Multistream API

Opus library information functions Opus Custom

1

Opus Encoder

本节描述了Opus编码器OpusEncoder的过程和函数

类型定义

typedef struct OpusEncoder

OpusEncoderOpus encoder 状态.

函数

int

OpusEncoder

*

int

opus_encoder_get_size (int channels) 获得 OpusEncoder结构的大小

opus_encoder_create (opus_int32 Fs, int channels, int application, int *error)

分配和初始化 encoder状态.

opus_encoder_init (OpusEncoder *st, opus_int32 Fs, int channels, int application)

初始化一个以前分配的编码器状态。所指向的内存圣必须至少是opus_encoder_get_size()返回的大小.

opus_int32

opus_int32

void

int

opus_encode (OpusEncoder *st, const opus_int16 *pcm, int frame_size, unsigned char *data, opus_int32 max_data_bytes) 对一个 Opus帧进行编码.

opus_encode_float (OpusEncoder *st, const float *pcm, int frame_size, unsigned char *data, opus_int32 max_data_bytes) 根据浮点输入对一个 Opus帧进行编码. opus_encoder_destroy (OpusEncoder *st)

释放一个根据opus_encoder_create()已分配的OpusEncoder 对象。 opus_encoder_ctl (OpusEncoder *st, int request,...) 向一个Opus编码器执行一个 CTL 函数.

2

详细描述

本节描述了用于编码Opus的过程和函数。

既然Opus是一个有状态的编解码器,编码过程始于创建一个编码器状态,用以下方法做到:

int error;

OpusEncoder *enc;

enc = opus_encoder_create(Fs, channels, application, &error);

从这一点上, enc可以用于编码音频流。一个编码器状态在同一时间不得用于多于一个音频流。同样,编码器状态不能对于每帧重新初始化。

当opus_encoder_create()为状态分配内存时,它也可以初始化预分配的内存: int size; int error;

OpusEncoder *enc;

size = opus_encoder_get_size(channels); enc = malloc(size);

error = opus_encoder_init(enc, Fs, channels, application);

opus_encoder_get_size()返回编码器状态要求的大小。注意,这段代码的未来版本

可能改变大小,所以没有assuptions应该对它做出。

编码器状态在内存中总是连续,复制它只要一个浅拷贝就足够了。

使用opus_encoder_ctl()接口可以改变一些编码器的参数设置。所有这些参数都已有缺省值,所以只在必要的情况下改变它们。最常见的参数设置修改是: opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate));

opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type));

在这里:

? bitrate(比特率)的单位是比特/秒(b / s)

? complexity(复杂性)是一个值从1到10,1最低,10最高,值越大越复杂

? signal_type(信号的类型)包括OPUS_AUTO (缺省), OPUS_SIGNAL_VOICE, or

OPUS_SIGNAL_MUSIC。

看Encoder related CTLs 和 Generic CTLs可以获得可设置和查询的参数详细清单。在一

个音频流处理过程中,大多数参数可以设置或修改。

为了对一个帧进行编码,必须正确地用音频数据的帧(2.5, 5, 10, 20, 40 或60 毫

3

秒)来调用opus_encode() 或opus_encode_float()函数。

len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);

在这里:

? audio_frame(音频帧)是opus_int16(或用于opus_encode_float()的浮点)格

式的音频数据

? frame_size(帧大小)是样本中帧的最大数(每个通道) ? packet(包)是写成压缩数据的字节数组,

? max_packet是可以写入包的字节数的最大值推荐(4000字节)。不要使用

max_packet控制VBR的目标比特率,而应该用OPUS_SET_BITRATE CTL。

opus_encode() 和opus_encode_float()返回实际写入包的字节数。返回值可以是

负数,这表明一个错误已经发生。如果返回值是1个字节,那么包不需要传播(DTX)。

一旦一个编码器状态已不再需要,可以用以下方式解构:

opus_encoder_destroy(enc);

如果编码器是用opus_encoder_init() 创建的,而不是使用opus_encoder_create()函数,那么不需要采取行动,要求从潜在的释放为它手动分配的内存(上述例子是调用 free(enc))中分离。

类型定义文档

typedef struct OpusEncoder OpusEncoder

Opus编码器状态。

这包含了一个Opus编码器的完整状态。它是位置独立的,并且可以自由复制。

函数文档

opus_int32 opus_encode ( OpusEncoder * const opus_int16 * pcm, int frame_size, unsigned char * data, opus_int32 max_data_bytes ) 对一个Opus帧进行编码。

4

st,

参数:

[in] st OpusEncoder*:编码器状态

[in] pcmopus_int16*: 输入信号(如果是2 通道有交叉). 长度是 frame_size*channels*sizeof(opus_int16)

[in] frame_size int:输入信号的每通道样本数. 这必须是编码器采样率的Opus帧大小。比如,48 kHz 下允许值有120, 240, 480, 960, 1920, 和 2880。少于10毫秒的采样(48 kHz 有480个样本),将阻止编码器使用LPC或混合模式。

[out] 容量。

[in] max_data_bytes opus_int32: 为输出负载所分配的内存大小。可以用于限制固定比特率的最大上限,但不能用作唯一的比特率限制,可以用

OPUS_SET_BITRATE来控制比特率。

data unsigned char*: 输出负载。必须包含至少max_data_bytes 的

返回值:成功,是被编码包的长度(字节数),失败,一个负的错误代码

opus_int32 opus_encode_float ( OpusEncoder *

const float * pcm, int

frame_size,

data,

st,

unsigned char * opus_int32

max_data_bytes

)

根据浮点输入对一个 Opus帧进行编码. 参数:

[in] st OpusEncoder*:编码器状态

[in] pcmfloat*:浮点格式的输入(如果是2 通道有交叉),正常范围在+/-1.0之间. 超过该范围的采样也是支持的,但它将被解码器用整型API截取,并且只能在知道远端支持扩展的动态范围的情况下使用。长度是 frame_size*channels*sizeof(float)

[in]

frame_size int: 输入信号的每通道样本数. 这必须是编码器采样率

的Opus帧大小。比如,48 kHz 下允许值有120, 240, 480, 960, 1920, 和 2880。

5

向一个Opus解码器执行一个 CTL 函数.

一般其请求和后续的参数是由一个提供便利的宏来产生的。 参数:

? st OpusDecoder*: 解码器状态.

? request :这个及所有其他剩余参数应被1个在Generic CTLs 或

Encoder related CTLs所提供便利的宏来替代

参见:

Generic CTLs Decoder related CTLs

void opus_decoder_destroy ( OpusDecoder *

st )

释放一个根据opus_decoder_create()已分配的OpusDecoder 对象. 参数:

[in] st OpusDecoder*:用于释放的解码器状态。

int opus_decoder_get_nb_samples ( const OpusDecoder * dec,

const unsigned char opus_int32

len

packet[],

)

获得一个Opus包的样本数 参数:

[in] dec OpusDecoder*: 解码器状态 [in] packet char*: Opus包 [in] len opus_int32: 包的长度 返回:

样本的数量 返回值:

OPUS_INVALID_PACKET:通过的被压缩数据已损坏或其格式不被支持。

16

int opus_decoder_get_size ( int 获得 OpusDecoder结构的大小。 参数:

[in] channels 返回:

字节数的大小.

channels )

int: 通道数,必须是1或2.

int opus_decoder_init ( OpusDecoder *

opus_int32 int

Fs,

st,

channels

)

初始化一个以前分配过的解码器状态.

状态必须至少是opus_decoder_get_size()返回的大小.

在这里,应用程序不要用系统自动分配内存,而要准备用自己的分配器。 参见:

opus_decoder_create,opus_decoder_get_size,为重设一个以前初始化的状态,使用OPUS_RESET_STATE CTL.

参数:

[in] st OpusDecoder*: 解码器状态.

[in] Fs opus_int32: 准备解码的采样率 (Hz). 必须是8000、12000、16000、24000、或48000.

[in] channels 返回值:

成功,OPUS_OK ,失败,错误代码。

int opus_packet_get_bandwidth ( const unsigned char * data

获得一个Opus包的带宽。 参数:

17

int: 解码的通道数 (1 or 2)

)

[in] data 返回值:

char*: Opus 包

? OPUS_BANDWIDTH_NARROWBAND 窄带 (4kHz bandpass) ? OPUS_BANDWIDTH_MEDIUMBAND 中等带宽 (6kHz bandpass) ? OPUS_BANDWIDTH_WIDEBAND 宽带 (8kHz bandpass) ? OPUS_BANDWIDTH_SUPERWIDEBAND

bandpass)

? OPUS_BANDWIDTH_FULLBAND 全宽带 (20kHz bandpass) ? OPUS_INVALID_PACKET 通过的被压缩数据已损坏或其格式不被

支持

int opus_packet_get_nb_channels

)

获得Opus 包的通道数。 参数: [in] data 返回: 通道数量 返回值:

OPUS_INVALID_PACKET 通过的被压缩数据已损坏或其格式不被支持

int opus_packet_get_nb_frames ( const unsigned char

opus_int32

len

packet[],

char*: Opus 包

( const unsigned char * data

高宽带

(12kHz

)

获得Opus 包所有帧的数量. 参数:

[in] packet char*: Opus 包

18

[in] len opus_int32:包的长度 返回: 帧的数量 返回值:

OPUS_INVALID_PACKET 通过的被压缩数据已损坏或其格式不被支持

int opus_packet_get_nb_samples

packet[],

opus_int32 opus_int32

len, Fs

( const

unsigned

char

)

获得Opus 包的样本数。 参数:

[in] packet char*: Opus 包 [in] len opus_int32: 包的长度

[in] Fs opus_int32: 采样率(Hz). 必须是400的倍数,否则结果不准确。

返回:

样本的数量 返回值:

OPUS_INVALID_PACKET 通过的被压缩数据已损坏或其格式不被支持

int opus_packet_get_samples_per_frame ( const

data,

opus_int32

Fs

unsigned

char

*

)

获得Opus 包每帧的样本数。

19

参数: [in] data

char*: Opus 包. 必须包含至少一个字节的数据。

[in] Fs opus_int32: 采样率(Hz).必须是400的倍数,否则结果不准确。

返回:

每帧样本的数量.

int opus_packet_parse ( const unsigned char * data,

opus_int32

len,

out_toc,

unsigned char *

const unsigned char * frames[48], short size[48], int * payload_offset

)

将一个 opus 包解析成1个或多个帧.

Opus_decode在内部执行这个操作,所以大多数应用程序不需要用到这个函数。这个函数不复制各帧,返回的指针是输入包内部的指针。

参数: [in] data

char*:要进行解析的 Opus包

[in] len opus_int32: 数据的大小 [out] [out] [out] [out] 返回: 帧的数量

out_toc char*: TOC 指针 frames char*[48] 封装过的帧 size short[48] 封装过的帧的大小

payload_offset int*: 返回在包内负载的位置(按字节)

20

previously submitted packet. The total duration of audio in the repacketizer state also must not exceed 120 ms, the maximum duration of a single packet, after adding this packet.

用opus_repacketizer_out() 或 opus_repacketizer_out_range(),当前repacketizer状态的内容可以被提取到新的包。

The contents of the current repacketizer state can be extracted into new packets using opus_repacketizer_out() or opus_repacketizer_out_range().

如果想添加不同配置的包,或加更多的超过120毫秒的音频数据,就必须调用opus_repacketizer_init()来清除repacketizer状态。如果一个包太大不能整体添加到当前repacketizer状态,它的任何一部分也不能添加,即使这个包包含多个帧,其中部分也许适合添加。如果你想添加这样的包的部分内容,你应当首先使用另一个repacketizer来将这些包分离成适合添加的小片,再一个个地将这些小片加入目标repacketizer状态。

In order to add a packet with a different configuration or to add more audio beyond 120 ms, you must clear the repacketizer state by calling opus_repacketizer_init(). If a packet is too large to add to the current repacketizer state, no part of it is added, even if it contains multiple frames, some of which might fit. If you wish to be able to add parts of such packets, you should first use another repacketizer to split the packet into pieces and add them individually.

参见:

opus_repacketizer_out_range opus_repacketizer_out opus_repacketizer_init 参数:

rp OpusRepacketizer*:将要添加包的repacketizer状态。 The

repacketizer state to which to add the packet.

[in] data

const unsigned char*: 包数据。应用程序必须确保这个指

针合法有效直到对opus_repacketizer_init() 或 opus_repacketizer_destroy()的

26

下一次调用。The packet data. The application must ensure this pointer remains valid

until

the

next

call

to

opus_repacketizer_init()

or

opus_repacketizer_destroy().

packet data.

返回:

表示操作成功与否的错误代码。

An error code indicating whether or not the operation succeeded. 返回值:

OPUS_OK 包的内容已被添加到repacketizer状态。The packet's contents have been added to the repacketizer状态.

OPUS_INVALID_PACKET 包的TOC系列无效,该系列不能与以前提交的包相匹配(编码模式、音频带宽、帧大小或通道数不吻合),或添加这个包将导致存储在repacketizer状态的声音时长超过120毫秒。The packet did not have a valid TOC sequence, the packet's TOC sequence was not compatible with previously submitted packets (because the coding mode, audio bandwidth, frame size, or channel count did not match), or adding this packet would increase the total amount of audio stored in the repacketizer状态 to more than 120 ms.

OpusRepacketizer* opus_repacketizer_create ( void

)

len opus_int32: 包数据中的字节数。The number of bytes in the

为用opus_repacketizer_init()产生的新repacketizer 分配内存和初始化。 Allocates

memory

and

initializes

the

new

repacketizer

with

opus_repacketizer_init().

void opus_repacketizer_destroy ( OpusRepacketizer *

rp )

释放通过opus_repacketizer_create()分配过的OpusRepacketizer。 Frees an OpusRepacketizer allocated by opus_repacketizer_create(). 参数:

27

[in] rp OpusRepacketizer*:将被释放的repacketizer状态。 State to be freed.

int opus_repacketizer_get_nb_frames

)

返回最后一次调用opus_repacketizer_init() 或 opus_repacketizer_create()后,到当前为止通过opus_repacketizer_cat()提交的包数据所包含的帧的总数。

Return the total number of frames contained in packet data submitted to the repacketizer状态 so far via opus_repacketizer_cat() since the last call to opus_repacketizer_init() or opus_repacketizer_create().

opus_repacketizer_out_range()

( OpusRepacketizer *

rp

opus_repacketizer_out()提取的有效包的范围。

This defines the valid range of packets that can be extracted with opus_repacketizer_out_range() or opus_repacketizer_out().

参数:

rp OpusRepacketizer*: 包含各帧的repacketizer状态。The repacketizer状态 containing the frames.

返回:

提交给repacketizer状态的包所包含的帧的总数。

The total number of frames contained in the packet data submitted to the repacketizer状态.

int opus_repacketizer_get_size ( void 获得 OpusRepacketizer结构的大小

Gets the size of an OpusRepacketizer structure. 返回:

结构体字节的大小 The size in bytes.

28

)

OpusRepacketizer* opus_repacketizer_init

rp )

( OpusRepacketizer *

(重新)初始化以前分配过的repacketizer 状态 (Re)initializes a previously allocated repacketizer状态.

Repacketizer状态必须至少有opus_repacketizer_get_size()返回的大小。这适用于不使用malloc(),而是用自己的分配器的应用程序。它也要被调用来重设正在等待重构的那些包的队列,如果最大包时长达到120ms或你希望用不同的Opus配置(编码模式、音频带宽、帧大小或通道数)来提交包的时候,这么做就有必要了。这么做如果失败了,系统将阻止用opus_repacketizer_cat()添加新的包。

The state must be at least the size returned by opus_repacketizer_get_size(). This can be used for applications which use their own allocator instead of malloc(). It must also be called to reset the queue of packets waiting to be repacketized, which is necessary if the maximum packet duration of 120 ms is reached or if you wish to submit packets with a different Opus configuration (coding mode, audio bandwidth, frame size, or channel count). Failure to do so will prevent a new packet from being added with opus_repacketizer_cat().

参见:

opus_repacketizer_create opus_repacketizer_get_size opus_repacketizer_cat 参数:

rp OpusRepacketizer*:需要 (重新)初始化的repacketizer状态 返回:

输入的同一个repacketizer状态的指针。

A pointer to the same repacketizer状态 that was passed in.

opus_int32 opus_repacketizer_out ( OpusRepacketizer *

rp,

unsigned char * opus_int32

data,

29

maxlen

)

通过opus_repacketizer_cat()从以前提交给repacketizer状态的数据构建一个新的包。

Construct a new packet from data previously submitted to the repacketizer状态 via opus_repacketizer_cat().

返回迄今提交进单一个包的所有数据可以提供便利,这么做等同于调用opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp),data, maxlen)

This is a convenience routine that returns all the data submitted so far in a single packet. It is equivalent to calling

opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp), data, maxlen) 参数:

rp OpusRepacketizer*: 准备构建新包的repacketizer状态。The

repacketizer状态 from which to construct the new packet.

[out]

data

const unsigned char*: 将要存储输出包的缓冲区。

The buffer in which to store the output packet.

maxlen opus_int32: 将要存入输出缓冲区的字节最大数。为保证

成功,这个值应该至少为1277*opus_repacketizer_get_nb_frames(rp)。然而,1*opus_repacketizer_get_nb_frames(rp)

opus_repacketizer_init() 或opus_repacketizer_create()以来所有提交包数据的大小,也是足够的,也可能小得多(此话似有矛盾)。 The maximum number of bytes to store in the output buffer. In order to guarantee success, this should be

at

least

1277*opus_repacketizer_get_nb_frames(rp).

However,

1*opus_repacketizer_get_nb_frames(rp) plus the size of all packet data submitted to the repacketizer since the last call to opus_repacketizer_init() or opus_repacketizer_create() is also sufficient, and possibly much smaller.

返回:

成功,输出包总的大小,失败,错误代码。

The total size of the output packet on success, or an error code on

30

j的索引。如果i< 2*coupled_streams,那么i若为偶数,I/O 通道 j被按照数据流的左声道进行编码;若i为奇数,I/O 通道 j被按照数据流的右声道进行编码。其他情况下,I/O 通道 j被按照数据流的单声道编码(i - coupled_streams),除非它有特殊的值255,在这种情况下它将被从编码中彻底删掉(解码器将其作为静音重建)。i的每个值不是特殊值255就是小于streams + coupled_streams。

A mapping table defines which decoded channel i should be used for each input/output (I/O) channel j. This table is typically provided as an unsigned char array. Let i = mapping[j] be the index for I/O channel j. If i < 2*coupled_streams, then I/O channel j is encoded as the left channel of stream (i/2) if i is even, or as the right channel of stream (i/2) if i is odd. Otherwise, I/O channel j is encoded as mono in stream (i - coupled_streams), unless it has the special value 255, in which case it is omitted from the encoding entirely (the decoder will reproduce it as silence). Each value i must either be the special value 255 or be less than streams + coupled_streams.

必须说明,编码器的输出通道应使用Vorbis(免费音乐格式)的通道规则。解码器可能希望应用一个附加的排列以映射用于实现不同输出通道规则的编码器(例如用于WAV规则的输出)。

The output channels specified by the encoder should use the Vorbis channel ordering. A decoder may wish to apply an additional permutation to the mapping the encoder used to achieve a different output channel order (e.g. for outputing in WAV order).

多流包包含对应每个流的各Opus包,在单一多流包内的所有Opus包必须有相同的时长。因此,一个多流包的时长可以从位于包开始位置的第一个流的TOC序列提取,就象一个基本的Opus流:

Each multistream packet contains an Opus psacket for each stream, and all of the Opus packets in a single multistream packet must have the same duration. Therefore the duration of a multistream packet can be extracted from the TOC sequence of the first stream, which is located at the beginning of the packet, just like an elementary Opus stream:

36

int nb_samples; int nb_frames;

nb_frames = opus_packet_get_nb_frames(data, len); if (nb_frames < 1)

return nb_frames;

nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames;

一般的编码和解码过程执行完全相同的标准Opus Encoder 和 Opus Decoder API。如何使用相应的多流函数可以查阅它们的说明文档。

The general encoding and decoding process proceeds exactly the same as in the normal Opus Encoder and Opus Decoder APIs. See their documentation for an overview of how to use the corresponding multistream functions.

类型定义文档

typedef struct OpusMSDecoder OpusMSDecoder Opus多流解码器状态。 Opus multistream decoder state.

这包含了一个Opus多流解码器的完整状态。它是位置独立的,并且可以自由复制。

This contains the complete state of a multistream Opus decoder. It is position independent and can be freely copied.

参见:

opus_multistream_decoder_create opus_multistream_decoder_init

typedef struct OpusMSEncoder OpusMSEncoder Opus多流编码器状态。 Opus multistream encoder state.

这包含了一个Opus多流编码器的完整状态。它是位置独立的,并且可以自由复制。

This contains the complete state of a multistream Opus encoder. It is position independent and can be freely copied.

37

参见:

opus_multistream_encoder_create opus_multistream_encoder_init

函数文档

int opus_multistream_decode

( OpusMSDecoder * st,

const unsigned char * data, opus_int32

len,

opus_int16 * pcm, int int

frame_size, decode_fec

)

解码一个多流Opus包。

Decode a multistream Opus packet. 参数:

st OpusMSDecoder*: Opus多流解码器状态。Multistream

decoder state.

[in] data

const unsigned char*:输入负载.对包丢失使用一个空指针

来表示。 Input payload. Use a NULL pointer to indicate packet loss.

payload.

[out]

pcmopus_int16*:使用交叉样本的输出信号。必须有容纳len opus_int32: 在输入负载中的字节数。Number of bytes in

frame_size*channels样本数的空间。Output signal, with interleaved samples. This must contain room for frame_size*channels samples.

frame_size int: 在PCM可用空间中每通道的样本数。如果小于

最大包的时长(120毫秒,4848kHz5760个),这个函数将不能解码一些包。如果是PLC (data==NULL) 或 FEC (decode_fec=1)的情况,那么frame_size必须正好是丢失音频的时长,否则解码器无法在解码下一个包时进入优化状态。

38

对于PLC 和 FEC 的情况,frame_size必须是2.5毫秒的倍数。The number of samples per channel of available space in pcm. If this is less than the maximum packet duration (120 ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.

decode_fec int: 对于请求任何带内前向错误纠正数据进行解码

的状态标志 (0 or 1) 。如果没有这样的数据可用,帧在解码时被认为已经丢失。 Flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available, the frame is decoded as if it were lost.

返回:

成功,解码样本的数量,失败,负的错误代码。Number of samples decoded on success or a negative error code (see Error codes) on failure.

int opus_multistream_decode_float ( OpusMSDecoder * st,

const unsigned char * data, opus_int32 float * int int

len,

pcm,

frame_size, decode_fec

)

用浮点输出格式解码一个多流Opus包。

Decode a multistream Opus packet with floating point output. 参数:

st OpusMSDecoder*: Opus多流解码器状态。Multistream

decoder state.

[in] data

const unsigned char*::输入负载.对包丢失使用一个空指

39

针来表示。 Input payload. Use a NULL pointer to indicate packet loss.

payload.

[out]

pcmopus_int16*:使用交叉样本的输出信号。必须有容纳len opus_int32: 在输入负载中的字节数。 Number of bytes in

frame_size*channels样本数的空间。Output signal, with interleaved samples. This must contain room for frame_size*channels samples.

frame_size int: 在PCM可用空间中每通道的样本数。如果小于

最大包的时长(120毫秒,4848kHz5760个),这个函数将不能解码一些包。如果是PLC (data==NULL) 或 FEC (decode_fec=1)的情况,那么frame_size必须正好是丢失音频的时长,否则解码器无法在解码下一个包时进入优化状态。对于PLC 和 FEC 的情况,frame_size必须是2.5毫秒的倍数。The number of samples per channel of available space in pcm. If this is less than the maximum packet duration (120 ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.

decode_fec int: 对于请求任何带内前向错误纠正数据进行解码

的状态标志 (0 or 1) 。如果没有这样的数据可用,帧在解码时被认为已经丢失。 Flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available, the frame is decoded as if it were lost.

返回:

成功,解码样本的数量,失败,负的错误代码。Number of samples decoded on success or a negative error code (see Error codes) on failure.

OpusMSDecoder* opus_multistream_decoder_create ( opus_int32

Fs,

int int

channels, streams,

40

本文来源:https://www.bwwdw.com/article/79e6.html

Top