Audioread 和 Audioinfo 返回不同数量的样本总数?

Audioread & Audioinfo returning differing number of total samples?

我在尝试读取 MATLAB 中的信号时遇到了一个小问题 运行。

audioread 函数将音频文件转换成单独的样本。
audioinfo 函数检查音频文件和与信号相关的 returns 信息。

代码片段如下

clear all;

%Read in the song
mySong = audioread('IowaFightSong.mp3');
%Get some information about the song
info = audioinfo('IowaFightSong.mp3')

我希望这两个函数具有相同数量的样本,但它们略有不同。

audioread returns长度为3,043,056的数组
audioinfo 的 TotalSamples 值为 3,043,582

这 2 个值相差 526 个样本。

当我 运行 使用 MATLAB 示例音频文件之一的代码时

clear all

load handel.mat
audiowrite('handel.wav',y,Fs)

info = audioinfo('handel.wav')

y = audioread('handel.wav');

audioreadaudioinfo 的样本总数相同,均为 73,113。

我想知道是否有人可以解释这两个函数之间样本总数的差异?

一个简单的解决方法是

clear all;

%Read in the song
mySong = audioread('IowaFightSong.mp3');
%Get some information about the song
info = audioinfo('IowaFightSong.mp3')

info.TotalSamples = length(mySong)
info.Duration = info.TotalSamples/info.SampleRate

audioinfolimitations section 是这样说的:

For MP3 and MPEG-4 AAC audio files on Windows 7 or later and Linux platforms, audioinfo might report fewer samples than expected. On Linux platforms, this is due to a limitation in the underlying GStreamer framework.

audioreadlimitations section 表示:

For MP3, MPEG-4 AAC, and AVI audio files on Windows 7 or later and Linux platforms, audioread might read fewer samples than expected. On Windows 7 platforms, this is due to a limitation in the underlying Media Foundation framework. On Linux platforms, this is due to a limitation in the underlying GStreamer framework. If you require sample-accurate reading, work with WAV or FLAC files.

基本上,两者 都存在 MP3 文件样本报告不准确的问题,但 WAV 文件则不然,这就是 MATLAB 样本音频文件没有问题的原因。正如建议的那样,如果准确的样本计数很重要,您可能应该使用不同的格式。

WAV(wave riff)文件存储给定数量的音频样本,1 到 1。

mp3 文件不包含音频样本,而是保存有损压缩格式,其中样本不是单独转换为压缩格式,而是以一定数量的块或块形式转换。因此 mp3 文件通常会截断或填充填充每个压缩块或块所需的样本数。播放 mp3 时得到的是解压后这些块中的数字,因此是向上或向下舍入的数字。 (并包含压缩工件)。