help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Writing binary files is not working properly


From: robert Macy
Subject: Writing binary files is not working properly
Date: Sat, 25 Oct 2003 09:49:41 -0700

I'm trying to convert a waveform into a sound .wav file and
am having great difficulty

excerpts from the file
    wavwrite.m, 
   courtesy of Stephen Simpson 


the file is opened like this....
  fid=fopen(wavefile, 'w', 'ieee-le');

arbitrarily sample length is 8000
data is sig whose size is (1,8000)

depending on whether I select 8 or 16 bits

if format(4) == 8
  sig=round((sig+1) * 128);
  Block = n;
end

or, for 16 bit format

if format(4) == 16
  sig = round(sig*32768) + 32768;  
  Block = 2*n;
end


all works well until....
then the file is written to like this 
       for 8 bit...

if (format(4)+format(2) == 9)
  fwrite(fid,sig,'uchar');
end

       for 16 bit....

if (format(4)+format(2) == 17)
  fwrite(fid,sig,'ushort');
end


I don't seem to have a lot of problems with 8 bit
structure, but the 16 bit adds 0D every time the data
contains 0A     

In other words, fwrite(fid,sig,'ushort'); is adding a
"carriage return" everytime the data has "new line"


I discovered this after - thanks to the help from the
people here I downloaded a free hex editor, XVI32, which is
less than 1MB and doesn't fuss around in my Windows98
system, works VERY WELL -
  Hex-editor XVI32
  Copyright (c) 2003 Christian Maas - All Rights Reserved
                     address@hidden
                     http://www.chmaas.handshake.de

Using the hex editor I search and replace every 0D 0A with
0A, which almost works, most of the time.  Alas, sometimes
the real data is 0D 0A and should not have been touched.  


How do I fix this properly?  I need to be able to write a
binary file without extras being inserted.  

                 - Robert -



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]