bugGNU Octave - Bugs: bug #37540, wavwrite doesn't produce a valid...

 
 

bug #37540: wavwrite doesn't produce a valid wav file

Submitter:  None
Submitted:  Wed 10 Oct 2012 06:11:23 PM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  mtmiller
Originator Name:  Guiu Rocafort Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.3
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 16 Oct 2012 02:34:58 AM UTC, comment #6: 

As far as the affected file is an .m script I'm going to replace the wavwrite.m file with the updated one to have this fix included.

thank you for your time mike !


Guiu Rocafort <rocafort8>
Tue 16 Oct 2012 02:00:30 AM UTC, comment #5: 

I had a similar patch ready assuming that would be your answer. I also added a line to the docstring and added a test for this case. Here is the changeset:
http://hg.savannah.gnu.org/hgweb/octave/rev/9a7f73fc304f

This fix will be available in the next major release of Octave. In the meantime you can stick to column vectors as a workaround or you can use the development source.

Mike Miller <mtmiller>
Group Member
Mon 15 Oct 2012 10:19:50 AM UTC, comment #4: 

I've tried the code and wavwrite generates a 8001 tracks wav with one sample each track when passing a 2xN matrix.

I've taken a look at the /usr/share/octave/3.2.4/m/audio/wavwrite.m file and I managed to fix the code so it behaves like matlab. I added a conditional that transposes the variable if it happens to be a row vector. I'm not sure if that's the best way of fixing it but it does the work ;)

I checked the modifications with 1x1, 1xn , nx1 and nxm cases and it seems i didn't broke anything.

Maybe should the documentation be modified to explicitily mention this behaviour ?

(file #26768, file #26769)

Guiu Rocafort <rocafort8>
Thu 11 Oct 2012 01:57:17 PM UTC, comment #3: 

Thanks, I'll work on a fix for this since I also happen to be fixing an unrelated problem in wavread at the same time.

Can you try one more thing in Matlab, do you get a valid stereo WAVE file if the input is a 2xN matrix? Does this:


dur = 1;
fs = 8000;
tt = 0 : (1/fs) : dur;
xx = sin (2 * pi * 2000 * tt);
wavwrite ([xx;xx], fs, 'temp.wav');


produce a stereo version of your example file or not?

Mike Miller <mtmiller>
Group Member
Thu 11 Oct 2012 12:12:31 PM UTC, comment #2: 

I can confirm that Matlab does behave differently using the row vector, I attach the result wav file generated by matlab with the example code and using row vector:



(file #26739)

Guiu Rocafort <rocafort8>
Wed 10 Oct 2012 07:30:16 PM UTC, comment #1: 

Look at the help for wavwrite again. It requires that the first argument contain column vectors only, where each column is a channel. You are using row vectors, so your snippet here is attempting to create a WAVE file with 8001 channels of 1 sample each. Compare:


dur = 1;
fs = 8000;
tt = 0 : (1/fs) : dur;
xx = sin (2 * pi * 2000 * tt);
wavwrite (xx, fs, "temp.wav"); % Will not work
wavwrite (xx(:), fs, "temp.wav"); % OK


I don't see a bug here, unless you or someone else can demonstrate that Matlab behaves differently when given a row vector.

Mike Miller <mtmiller>
Group Member
Wed 10 Oct 2012 06:11:23 PM UTC, original submission:  

OS: GNU/Linux Kubuntu 12.04
Versions affected: 3.2.4 and 3.6.3 ( probably others also )


It seems like wavwrite don't produce a valid sound. I've tryed out generating a simple sine wave and generating the wav. The resulting wav cannot be reader by vlc neither mplayer. soundConverter complains about "Gstreamer: could not determine type of stream". And opening it with audacity causes it to crash. Because of all this, I'm arriving to the conclusion that the wav-generated file has not the right format.

I tryed out in versions 3.2.4 and 3.6.3 ( self complied ) and I've found the problem in both versions.

The full code that i've used to generate the wav file:

dur = 1.0;
fs = 8000;
tt = 0 : (1/fs) : dur;
xx = sin( 2*pi*2000*tt );
wavwrite( xx, fs,‘temp.wav’);

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #26768:  wavwrite.m added by rocafort8 (5KiB - text/x-objcsrc - modified wavwrite.m file which fix the row vector issue.)
file #26769:  wavwrite.diff added by rocafort8 (158B - text/x-patch - modified wavwrite.m file which fix the row vector issue.)
file #26739:  temp.wav added by rocafort8 (16KiB - audio/wav - wav file generated by matlab with row vector.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rocafort8 (Updated the item)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-10-16 mtmiller StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2012-10-15 rocafort8 Attached File- Added wavwrite.m, #26768
        Attached File- Added wavwrite.diff, #26769
    2012-10-11 mtmiller Assigned toNone mtmiller
        Operating SystemGNU/Linux Any
    2012-10-11 rocafort8 Attached File- Added temp.wav, #26739
    2012-10-10 mtmiller StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code