[gst-devel] float caps, category, audioconvert changes

Ronald Bultje rbultje at ronald.bitfreak.net
Sun Jul 20 09:29:05 CEST 2003


Hey Leif,

On Sun, 2003-07-20 at 15:50, Leif Johnson wrote:
> I suppose I could just typecast the result from the macros, that might be a
> good idea in any case.

No, because you lose any precision. Once you've got a uint, you'll never
get the precision of the float back.

Test it: gfloat val = 1.567; (gfloat) (guint32) val = 1, unfortunately.
however, * (gfloat *) (guint32 *) &val = 1.567. :).

So unless you do casts from pointers (in which case you're casting the
bytes as is, and not the value), it won't work. And what I'm doing is
basically the pointer-cast, so an ugly hack which works.

> >From </usr/include/glib-2.0/glib/gtypes.h> :
> 
>   #if G_BYTE_ORDER == G_LITTLE_ENDIAN
>   union _GFloatIEEE754
>   {
>     gfloat v_float;
>     struct {
>       guint mantissa : 23;
>       guint biased_exponent : 8;
>       guint sign : 1;
>     } mpn;
>   };
>   /* ... */
>   #elif G_BYTE_ORDER == G_BIG_ENDIAN
>   union _GFloatIEEE754
>   {
>     gfloat v_float;
>     struct {
>       guint sign : 1;
>       guint biased_exponent : 8;
>       guint mantissa : 23;
>     } mpn;
>   };
>
> But using the integer byte swap functions still works, since reversing the
> entire union will reverse the order of the component parts *and* the bit
> order in each of the respective parts. ... Is that right ? :)

I don't think so, but I might be misunderstanding you...

Actually, the above doesn't seem to make sense at all to me: it's doing
**bit** swapped floats, not **byte**swapped floats. It seems just plain
wrong to me. Can someone with a brain enlighten me on why the above is
correct?

Ronald

-- 
Ronald Bultje <rbultje at ronald.bitfreak.net>





More information about the gstreamer-devel mailing list