[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 24-bit wav files and other observations
From: |
Daniel J Sebald |
Subject: |
Re: 24-bit wav files and other observations |
Date: |
Thu, 21 Feb 2008 19:01:10 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020 |
John W. Eaton wrote:
On 21-Feb-2008, Daniel J Sebald wrote:
| I wanted to read a WAV file with 24 bit data width using
| auload()--rather than the 8, 16, or 32-bit facility. I've made some
| simple changes (see attached patch), which brings up a few issues.
|
|
| 1) The fread() routine always returns a variable of type 'double'.
| You'd think that the variable would have the native format. E.g.,
|
| data = fread(file, samples, 'uint8', 0, arch);
|
| would mean 'data' to be of type 'uint8'.
If you want that, then you need to write
data = fread(file, samples, 'uint8=>uint8', 0, arch);
or
data = fread(file, samples, '*uint8', 0, arch);
This feature is documented in the help for fread.
Ahh!
| 2) Why does Octave/Matlab not have 'uint24' throughout? For
| example, there'd be nothing unusual about
|
| data = fread(file, samples, 'int24', 0, arch);
|
| and a type 'int24'.
What general-purpose systems have 24-bit ints as a native data type?
Well, probably few general-purpose systems. There are many 24-bit embedded processors, of course,
and then there are plenty of data files that use 24-bit data. So, from an analytical standpoint
there are reasons for having 24-bit "native" types. It's similar to the situation that
we have very few 8 bit CPU's anymore, but the 8-bit width "native" format is still
ubiquitous.
| I would think that bitor(-2,1) should be -1. Is this a bug?
The documentation for bitor says:
-- Built-in Function: bitor (X, Y)
Return the bitwise OR of nonnegative integers. X, Y must be in
range [0..bitmax]
Maybe it is a bug that it doesn't warn or give an error for negative
values.
Ehhh, what I wrote isn't exactly true, as the behavior doesn't quite reflect
what the documentation says. Note the following:
octave:8> x = 1
x = 1
octave:9> y = -2
y = -2
octave:10> bitor(x,y)
ans = 1
octave:11> x = cast(1,"int8")
x = 1
octave:12> y = cast(-2,"int8")
y = -2
octave:13> bitor(x,y)
ans = -1
When the types are "double" then bit-wise ops behave in the range [0..bitmax]. But when the types
are "int8" then bit-wise ops behave the way I would expect. I suppose there is some logic to that,
as "floating point" has a more arcane definition to it, i.e., mantisa, exponent.
Perhaps the behavior is acceptable and all that is needed is a bit more detail
in the documentation? Or is there more to this?
Dan