gst/audioconvert/gstaudioconvert.c: convert channels correctly. convert correctly...
authorBenjamin Otte <otte@gnome.org>
Fri, 5 Mar 2004 21:05:26 +0000 (21:05 +0000)
committerBenjamin Otte <otte@gnome.org>
Fri, 5 Mar 2004 21:05:26 +0000 (21:05 +0000)
Original commit message from CVS:
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_channels):
convert channels correctly. convert correctly to unsigned.

ChangeLog
common
gst/audioconvert/gstaudioconvert.c

index f60ae11861005d991bafa5af32abc3d8923315c6..2fc974b5f493796fbbf401e7a861ad7cee8e7bf6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-03-05  Benjamin Otte  <otte@gnome.org>
+
+       * gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_channels):
+         convert channels correctly. convert correctly to unsigned.
+
 2004-03-05  Julien MOUTTE <julien@moutte.net>
 
        * sys/xvimage/xvimagesink.c: (gst_xvimagesink_change_state): Check if
diff --git a/common b/common
index 874dab5c3461ad7487f1ae029256b6da82dddf6d..4eb02711e49a6aadf900d6fd9d220c17115fec2a 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit 874dab5c3461ad7487f1ae029256b6da82dddf6d
+Subproject commit 4eb02711e49a6aadf900d6fd9d220c17115fec2a
index 29145e39b07024e07e18760a8272223c08394158..d057d665e29042466dd54cd42110830ac4d8a52c 100644 (file)
@@ -589,16 +589,17 @@ gst_audio_convert_get_buffer (GstBuffer *buf, guint size)
 static inline guint8 GUINT8_IDENTITY (guint8 x) { return x; }
 static inline guint8 GINT8_IDENTITY (gint8 x) { return x; }
 
-#define CONVERT_TO(to, from, type, sign, endianness, LE_FUNC, BE_FUNC) G_STMT_START{\
-  type value;                                                                  \
-  memcpy (&value, from, sizeof (type));                                        \
-  from -= sizeof (type);                                                       \
-  value = (endianness == G_LITTLE_ENDIAN) ? LE_FUNC (value) : BE_FUNC (value); \
-  if (sign) {                                                                  \
-    to = value;                                                                \
-  } else {                                                                     \
-    to = (gint64) value - (1 << (sizeof (type) * 8 - 1));                      \
-  }                                                                            \
+#define CONVERT_TO(to, from, type, sign, endianness, LE_FUNC, BE_FUNC)         \
+G_STMT_START{                                                                  \
+  type value;                                                                  \
+  memcpy (&value, from, sizeof (type));                                                \
+  from -= sizeof (type);                                                       \
+  value = (endianness == G_LITTLE_ENDIAN) ? LE_FUNC (value) : BE_FUNC (value); \
+  if (sign) {                                                                  \
+    to = value;                                                                        \
+  } else {                                                                     \
+    to = (gint64) value - (1 << (sizeof (type) * 8 - 1));                      \
+  }                                                                            \
 }G_STMT_END;
 
 static GstBuffer*
@@ -680,7 +681,11 @@ gst_audio_convert_buffer_to_default_format (GstAudioConvert *this, GstBuffer *bu
   format val;                                                                  \
   format* p = (format *) dest;                                                 \
   int_value >>= (32 - this->srccaps.depth);                                    \
-  val = (format) int_value;                                                    \
+  if (this->srccaps.sign) {                                                    \
+    val = (format) int_value;                                                  \
+  } else {                                                                     \
+    val = (format) int_value + (1 << (this->srccaps.depth - 1));               \
+  }                                                                            \
   switch (this->srccaps.endianness) {                                          \
     case G_LITTLE_ENDIAN:                                                      \
       val = le_func (val);                                                     \
@@ -753,21 +758,21 @@ gst_audio_convert_channels (GstAudioConvert *this, GstBuffer *buf)
 {
   GstBuffer *ret;
   gint i, count;
-  guint32 *src, *dest;
+  gint32 *src, *dest;
 
   if (this->sinkcaps.channels == this->srccaps.channels)
     return buf;
 
   count = GST_BUFFER_SIZE (buf) / 4 / this->sinkcaps.channels;
   ret = gst_audio_convert_get_buffer (buf, count * 4 * this->srccaps.channels);
-  src = (guint32 *) GST_BUFFER_DATA (buf);
-  dest = (guint32 *) GST_BUFFER_DATA (ret);
+  src = (gint32 *) GST_BUFFER_DATA (buf);
+  dest = (gint32 *) GST_BUFFER_DATA (ret);
 
   if (this->sinkcaps.channels > this->srccaps.channels) {
     for (i = 0; i < count; i++) {
       *dest = *src >> 1;
       src++;
-      *dest += (*src + 1) >> 1;
+      *dest += (*src >> 1) + (*src & 1);
       src++;
       dest++;
     }