主要内容

vorbis解码器

此示例显示如何实现Vorbis解码器,该解码器是MP3标准的免费软件,开源替代品。此音频解码格式支持编码数据的分段为网络传输的小数据包。金宝app

Vorbis基础知识

vorbis编码格式[1]是一个类似于MPEG-1音频层3的开源有损音频压缩算法,更常见称为MP3。Vorbis具有许多与MP3相同的功能,同时添加灵活性和功能。Vorbis规范仅定义比特流和解码算法的格式。这允许开发人员随时间改进编码算法,并且与现有解码器保持兼容。

通过将原始信号分成重叠帧来开始编码。Vorbis允许不同长度的帧,以便它可以有效地处理静止和瞬态信号。每个帧乘以窗口并使用修改的离散余弦变换进行转换(MDCT.). The frames are then split into a rough approximation called thefloor和剩下的叫做residue

The flexibility of the Vorbis format is illustrated by its use of different methods to represent and encode the floor and residue portions of the signal. The algorithm introduces模式as a mechanism to specify these different methods and thereby code various frames differently.

Vorbis uses Huffman coding to compress the data contained in the floor and residue portions. Vorbis uses a dynamic probability model rather than the static probability model of MP3. Specifically, Vorbis builds custom codebooks for audio signals, which can differ for 'floor' and 'residue' and from frame to frame.

在霍夫曼编码完成后,帧数据位于逻辑数据包中。在Vorbis中,一系列这样的数据包始终是标题。标题包含正确解码所需的所有信息。该信息包括一组完整的码本,描述了代表楼层和渣数的方法的描述,以及多通道支持的模式和映射。金宝app标题还可以包括比特率,采样率,歌曲和艺术家名称等一般信息。

Vorbis provides its own format, known as 'Ogg', to encapsulate logical packets into transport streams. The Ogg format provides mechanisms such as framing, synchronization, positioning, and error correction, which are necessary for data transfer over networks.

Problem Overview and Design Details

此示例中的Vorbis解码器实现了Vorbis I格式的规格,它是vorbis的子集。示例模型对包含单声道或立体声音频信号的任何原始二进制OGG文件进行解码。示例模型具有可实时解码和播放各种Vorbis音频文件的功能。

You can test this example with any Vorbis audio file, or with the included亨德尔file. To load the file into the model, replace the file name in the annotated code at the top level of the model with the name of the file you want to test. When this step is complete, click the annotated code to load the new audio file. The model is configured to notify you if the output sampling rate has been changed due to a change in the input data. In this case, the simulation needs to be restarted with the new sample rate.

为了在Simulink®中实现Vorbis解码器,您必须解决变量大小的数据包。金宝app此示例通过使用“OGGS”同步模式捕获OGG比特流的整个页面来解决变量大小的数据包。出于实际目的,假设页面不超过5500字节。在页面开头获取分段表后,模型从页面的其余部分提取逻辑数据包。通过SoundowFlow Chart'解码所有数据页面来实现对解码序列的异步控制。

最初,图表尝试检测“OGGS”同步模式,然后遵循上述解码步骤。解码页面使用Simulink函数“DecodePage”完成,然后模型金宝app立即返回到检测下一个'Oggs'序列。状态'resetPageCounter'并行地与上述状态流算法并行添加,以支持压缩输入文件的循环以获取无限数量的迭代。金宝app

数据页包含不同类型的信息:header, codebooks, and audio signal data. The 'Read Setup Info', 'Read the Header', and 'Decode Audio' subsystems inside the 'decodePage' Simulink function are responsible for handling each of these different kinds of information.

使用MATLAB功能块实现解码过程。该示例中的大多数位解压缩例程是用MATLAB代码实现的。

重组的floorandresidue并且随后的逆MDCT(IMDCT)也是用Matlab函数块来实现,该函数块使用快速imdctfunction of Audio Toolbox. The variable frame lengths are taken into account using a fixed-size maximum-length frame at the input and output of the Function block, and by using a window length parameter in both the Function block code and a Selector block immediately following the Function block.

The IMDCT transforms the frames back to the time domain, ready to be multiplied by the synthesis window and then combined with an overlap-add operation.

The output block in the top level of the model feeds the output of the decoding block to the audio playback device on your system. The valid portion of the decoded signal is input to theAudio Device Writer堵塞。

References

[1] Complete specification of the Vorbis decoder standardhttps://xiph.org/vorbis/doc/vorbis_i_spec.html.