audioconvert: change multiplier for int<->float conversion
authorWim Taymans <wtaymans@redhat.com>
Tue, 3 Nov 2015 10:44:54 +0000 (11:44 +0100)
committerWim Taymans <wtaymans@redhat.com>
Tue, 3 Nov 2015 11:12:08 +0000 (12:12 +0100)
Use (1 << 31) as the multiplier for int<->float conversions. This makes
sure that int->float conversions always end up with floats between
[-1.0, 1.0].
For the conversion from float to int, this multiplier will give the complete
int range after we perform clipping.
Change the unit test to take this into consideration.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=755301

gst/audioconvert/gstaudioconvertorc.orc
tests/check/elements/audioconvert.c

index 24fdf02..a5a0939 100644 (file)
@@ -4,14 +4,14 @@
 .temp 8 t1
 
 convld t1, s1
-divd d1, t1, 0x41DFFFFFFFC00000L
+divd d1, t1, 2147483648.0L
 
 .function audio_convert_orc_double_to_s32
 .dest 4 d1 gint32
 .source 8 s1 gdouble
 .temp 8 t1
 
-muld t1, s1, 0x41DFFFFFFFC00000L
+muld t1, s1, 2147483648.0L
 convdl d1, t1
 
 .function audio_convert_orc_int_bias
index 5c450c4..ee1f003 100644 (file)
@@ -747,9 +747,9 @@ GST_START_TEST (test_float_conversion)
   {
     gint16 in[] = { 0, -32768, 16384, -16384 };
     gdouble out[] = { 0.0,
-      (gdouble) (-32768L << 16) / 2147483647.0, /* ~ -1.0 */
-      (gdouble) (16384L << 16) / 2147483647.0,  /* ~  0.5 */
-      (gdouble) (-16384L << 16) / 2147483647.0, /* ~ -0.5 */
+      (gdouble) (-32768L << 16) / 2147483648.0, /* ~ -1.0 */
+      (gdouble) (16384L << 16) / 2147483648.0,  /* ~  0.5 */
+      (gdouble) (-16384L << 16) / 2147483648.0, /* ~ -0.5 */
     };
 
     RUN_CONVERSION ("16 signed to 64 float",
@@ -759,9 +759,9 @@ GST_START_TEST (test_float_conversion)
   {
     gint32 in[] = { 0, (-1L << 31), (1L << 30), (-1L << 30) };
     gdouble out[] = { 0.0,
-      (gdouble) (-1L << 31) / 2147483647.0,     /* ~ -1.0 */
-      (gdouble) (1L << 30) / 2147483647.0,      /* ~  0.5 */
-      (gdouble) (-1L << 30) / 2147483647.0,     /* ~ -0.5 */
+      (gdouble) (-1L << 31) / 2147483648.0,     /* ~ -1.0 */
+      (gdouble) (1L << 30) / 2147483648.0,      /* ~  0.5 */
+      (gdouble) (-1L << 30) / 2147483648.0,     /* ~ -0.5 */
     };
 
     RUN_CONVERSION ("32 signed to 64 float",