[Scilab-users] Possible bug in wavread

classic Classic list List threaded Threaded
4 messages Options
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Possible bug in wavread


Dear all,

When opening a wav file with wavread, even with the option 'info', seemingly it does not recognize the file as a valid wav file if it is encoded with a
category different from PCM.

For instance, I've created a simple wave file, opened it with Audacity (a free open-source audio editor) and exported it with mu-law encoding, getting the attached file. 

Wavread with the option 'info' behaves like this:

--> H = wavread('c:\test mu-law.wav', 'info')
at line    16 of function read_wavefmt ( C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci line 186 )
at line   113 of function wavread      ( C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci line 128 )

find_cktype: An error occurred: Invalid wav format.

I think this behavior is not correct, since my file is indeed a valid wav file (I successfully opened it with other audio editor).

From this and other similar experiments I conclude that the only encoding category Scilab supports is PCM (no compression). This may be OK to keep the function simple (there are literally dozens of formats that can be contained in a wav file), but the documentation should warn about that and the error message should be more accurate, informing that it is an unsupported format, instead of providing a misleading report telling that the format is invalid.

Regards,

Federico Miyara


Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

test mu-law.wav (11K) Download Attachment
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in wavread


Dear all,

I'm reviewing the wavread function code which I could find (on Windows 7) at the following path:

C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci

There is a code segment at the beginninig intended to detect if the wavfile has or not the .wav extension:


// Append .wav extension if necessary

if
( strindex(wavfile, ".") == [] ) then
    wavfile = wavfile + ".wav";
end

This contains a bug, since the wavfile name might contain a dot different from the one between the name and the extension. The normal case would be

sound.wav

and in this case the code works fine if the trailing .wav is absent. But in a case such as

sound_v1.1.wav

the code will detect a dot within the abbreviated name 'sound_v1.1' and will not append the .wav extension, hence the function will fail to find and open the file.

Fortunately the issue is solved quite easily:

// Append .wav extension if necessary
if
( ~(max(strindex(wavfile,'.wav')) == length(wavfile)-3) ) then
    wavfile = wavfile + '.wav';
end

The proposed patch tests whether '.wav' is the last sub-string of the file name.

Note: '.wav' might appear more than once or might even appear only once but in the middle of the name
. In such cases it is not a valid wav extension. This case might appear unlikely, but it is a possibility. For instance, some educator might present an example called:

'example_of_.wav_file.wav'

Regards,

Federico Miyara


 

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in wavread

Hello Federico,

Le 25/02/2019 à 01:06, Federico Miyara a écrit :

Dear all,

I'm reviewing the wavread function code which I could find (on Windows 7) at the following path:

C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci

There is a code segment at the beginninig intended to detect if the wavfile has or not the .wav extension:


// Append .wav extension if necessary

if
( strindex(wavfile, ".") == [] ) then
    wavfile = wavfile + ".wav";
end

This contains a bug, since the wavfile name might contain a dot different from the one between the name and the extension. The normal case would be

sound.wav

and in this case the code works fine if the trailing .wav is absent. But in a case such as

sound_v1.1.wav

the code will detect a dot within the abbreviated name 'sound_v1.1' and will not append the .wav extension, hence the function will fail to find and open the file.

Fortunately the issue is solved quite easily:

// Append .wav extension if necessary
if
( ~(max(strindex(wavfile,'.wav')) == length(wavfile)-3) ) then
    wavfile = wavfile + '.wav';
end

You are right. The current test is very fragile.
The regular way would rather be

if fileparts(wavfile,"extension")<>"wav",
   wavfile = wavfile+ ".wav"
end


Maybe fileparts() did not yet exist when the code was written.

Please do not hesitate to open another bug report to gather all this in a trackable place.

Regards
Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
fmiyara fmiyara
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in wavread


Samuel,

You are right. The current test is very fragile.
The regular way would rather be

if fileparts(wavfile,"extension")<>"wav",
   wavfile = wavfile+ ".wav"
end


Maybe fileparts() did not yet exist when the code was written.

I wasn't aware of fileparts, thank you.

Please do not hesitate to open another bug report to gather all this in a trackable place.

OK, I've submitted it as bug 15981:

http://bugzilla.scilab.org/show_bug.cgi?id=15981

Regards,

Federico Miyara

Libre de virus. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users