audioread() returns wrong data for integer range

조회 수: 17 (최근 30일)
John Wygonski
John Wygonski 2015년 2월 19일
댓글: David Heise 2020년 12월 17일
In the following code, audioread() returns wrong data but wavread() returns correct data from a wav file if the range parameters [start, finish] are int32 type. If the range parameters are type double, both audioread() and wavread() return correct data.
Is this expected behavior or a bug or my misunderstanding?
%audioread() reads from start=1 for range that is integer; wavread() correctly returns data starting at 'start'
start = int32(42016);
finish = int32(44440);
%start = 42016;
%finish = 44440;
wavpath = '.\test.wav';
clear arResult Fsar wrResult Fswr;
[arResult, Fsar] = audioread(wavpath, [start, finish ], 'native');
[wrResult, Fswr] = wavread(wavpath, [start, finish ], 'native');
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 12월 17일
i did some digging into the code, but unfortunately going further would require testing with a large .wav and I do not happen to have one large enough sitting around.
David Heise
David Heise 2020년 12월 17일
In implementing my "workaround", I noticed a similar error (at the change to scientific notation) when using the calculated sample numbers as indices to access a portion of the entire signal. I was eventually able to get around that issue by explicitly converting the calculated indices to an int (I used uint64) and then *back to a double* since some of the Audio Toolbox functions - in this case, pitch() - expect doubles as input parameters.
It is odd to me that the Audio Toolbox functions - or, for that matter, audioread() - would expect doubles as the type to specify what must be an integer index, but maybe it's done that way since most of the time we rely on the default data type...
In any case, a bit later I'll see if a similar strategy can be used to avoid the aforementioned error with audioread(), and I'll post a code example for the benefit of others running into this particular issue.

댓글을 달려면 로그인하십시오.

답변 (1개)

Antara Ganesh Kolar
Antara Ganesh Kolar 2016년 11월 23일
Hey, Did you resolve this error? Even I am getting the same error. I am using R2016a on Windows.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by