# [gst-devel] General question for converting audio/x-raw-int from/to audio/x-raw-float

Sebastian Dröge slomo at circular-chaos.org
Wed May 2 11:46:40 CEST 2007

```Hi,
I have a general question for converting audio/x-raw-int from or to
audio/x-raw-float.
Let's assume a width/depth of 32 for audio/x-raw-int in this mail.

When converting from integer to float the goal is to get everything in
the range [-1.0,1.0] but two's complement integers have an asymmetric
range of values, going for -2^31 to 2^31 - 1.

The possibilities I see here are:
a) float = int / 2^31;  // never gives float == -1.0
b) float = int / (2^31 - 1); // could give float < -1.0
c) float = int / (int >= 0) ? (2^31 - 1) : (2^31);

For the conversion from float to integer the same problem applies the
other way around:
a) int = float * 2^31; // can overflow
b) int = float * (2^31 - 1); // never gives -2^31
c) int = float * (float >= 0) ? (2^31 - 1) : (2^31);

Also it would be possible to "move" the integer range to make it
symmetric, i.e. substract -0.5 from it. This would make it impossible to
hit the 0 though:

float = (int - 0.5)/ (2^31-0.5); // gives full [-1,1] range but never 0
int = (float + 0.5) * (2^31 - 0.5);

The question now is, which of these methods is the correct one and
yields in as less distortions as possible?

Gstreamer's audioconvert currently does method b).

Thanks and Bye
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20070502/7cdcba91/attachment.pgp>
```