wavread fails to append .wav to incomplete fileneme in some cases
Reported by Federico Miyara
BUG DESCRIPTION:
----------------
When using an incomplete filename (i.e., one without explicit extension .wav), the documentation says the extension is automatically appended. However, if it contains a dot other than the one separating name and wav extension, wavread fails to locate and open it because it does not append .wav
ERROR LOG:
----------
at line 37 of function wavread ( C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci line 52 )
wavread: Cannot open file c:\test_v.1.1.
HOW TO REPRODUCE THE BUG:
-------------------------
1) Create any wave file and save it as c:\test_v1.1.wav
2) Evaluate waveread('c:\test_v.1.1')
Result: See error log above
OTHER INFORMATION:
------------------
Cause:
The function code has a poor completion criterion:
// Append .wav extension if necessary
if ( strindex(wavfile, ".") == [] ) then
wavfile = wavfile + ".wav";
end
The only check for the presence or not of .wav extension is the detection of a dot. An example such as the one indicated above fools the criterion since it has a dot not belonging to the extension, so the algorithm fails to append the missing extension.
Solution:
Replace the detection criterion with
// Append .wav extension if necessary
if ( ~(max(strindex(wavfile,'.wav')) == length(wavfile)-3) ) then
wavfile = wavfile + '.wav';
end
or (suggested by Samuel Gougeon)
if fileparts(wavfile,"extension")<>"wav",
wavfile = wavfile + ".wav"
end
In both cases what is checked is whether the extension is '.wav' or not