help-octave
[Top][All Lists]
Advanced

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

Re: Writing binary files is not working properly


From: robert Macy
Subject: Re: Writing binary files is not working properly
Date: Mon, 27 Oct 2003 09:41:51 -0800

Does happen in 8 bit format, just not as noticeable.

The program inserts a "samesize sample" near the value of
0A, so the data stream is not disrupted and the value is
close to 0A. All you hear is the slightest of tones from
the addition.  

With 16 bit format the shift in data causes horrendous
damage to the sound.  

If you purposely write a file of all 0A in 8 bit format,
you get a file twice as long of 0D 0A's  which make a
fairly quiet scream.  

When you say "patch"; I don't understand.  All I had to do
was to change the open statement method from "w" to "wb"
and all was well.  Also, in wavread.m change the open
statement from "r" to "rb" and that worked too.  


However, in wavread for the 8 bit format, I would change
the 8 bit digitization method so that as the signal
approaches zero level, the digitization stops.  Right now,
the smallest zero to minus value (smallest!) causes the
bits to toggle - makes for a "buzz" when the signal should
have died.  

was...
  sig=round((sig+1) * 255/2);

should be...
  sig=round((sig+1) * 128);

              - Robert -


On Mon, 27 Oct 2003 09:30:31 -0500 (EST)
 Przemek Klosowski <address@hidden> wrote:
>    robert Macy wrote:
> 
>    | In other words, fwrite(fid,sig,'ushort'); is adding
> a
>    | "carriage return" everytime the data has "new line"
>    |
> 
>    Looks like your problem could be due to the way
> various operating
>    systems mark the end of lines in text files
>          ...
>    There are utilities available that can convert files
> from one form to
>    the other: http://www.google.com/search?q=dos2unix
> 
> But, it's in general impossible to fix up a binary file a
> posteriori,
> because you can't know if 0x0d 0x0a is a result of
> botched line ending
> fix or a real data from the file.
> 
> On a Windows platform, you need to use the 'wb' mode in
> the fopen()
> call.  I don't know when it was introduced but I checked
> that it is
> there in 2.1.40; check your own version. This actually
> probably should
> be a default for wavwrite.m, because it should work right
> on Windows/Mac
> and should not make a difference on Unix. Could you check
> and submit 
> a patch if it's correct?
> 
>       p
> 
> 
> 
> 
> PS. Actually, it's surprising that the problem only
> happens for 16-bit
> data; a non-binary mode should expand every 0d value...
> perhaps there
> just weren't any in your 8-bit files??
> 
> 
> 
>
-------------------------------------------------------------
> 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
>
-------------------------------------------------------------
> 



-------------------------------------------------------------
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]