I have ran into a small problem trying to read a signal in MATLAB.
The audioread function converts a audio file into its individual samples.
The audioinfo function examines an audio file and returns information relating to the signal.
A code snippet is as follows.
clear all;
%Read in the song
mySong = audioread('IowaFightSong.mp3');
%Get some information about the song
info = audioinfo('IowaFightSong.mp3')
I would expect both functions to have the same number of samples, but they differ slightly.
audioread returns an array with length of 3,043,056audioinfo has the TotalSamples value of 3,043,582
These 2 values differ by 526 samples.
When I instead run the code with one of MATLAB's sample audio files
clear all
load handel.mat
audiowrite('handel.wav',y,Fs)
info = audioinfo('handel.wav')
y = audioread('handel.wav');
Both the audioread and audioinfo have the same total samples, 73,113.
I am wondering if anyone can explain the discrepancy in total samples between the 2 functions?
A simple workaround is
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