[Swfdec] 5 commits - libswfdec/swfdec_as_function.c libswfdec/swfdec_sound.c test/sound

Benjamin Otte company at kemper.freedesktop.org
Tue Nov 13 02:14:49 PST 2007


 libswfdec/swfdec_as_function.c   |    8 +
 libswfdec/swfdec_sound.c         |  177 +++++++++++++++++++--------------------
 test/sound/adpcm-2-2.swf.1.0.raw |binary
 test/sound/adpcm-3-2.swf.1.0.raw |binary
 test/sound/adpcm-3.swf.1.0.raw   |binary
 test/sound/adpcm-4.swf.1.0.raw   |binary
 test/sound/adpcm-5.swf.1.0.raw   |binary
 7 files changed, 95 insertions(+), 90 deletions(-)

New commits:
commit 564dd4c0b0472b22a0bd163b53f8ff29b8142be2
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Nov 13 11:14:38 2007 +0100

    fix testsuite breakage of Function.apply() and Function.call()

diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c
index 2c265c5..8d2f927 100644
--- a/libswfdec/swfdec_as_function.c
+++ b/libswfdec/swfdec_as_function.c
@@ -156,13 +156,17 @@ swfdec_as_function_do_call (SwfdecAsContext *cx, SwfdecAsObject *object,
   SwfdecAsFunction *fun;
   SwfdecAsObject *thisp;
 
-  SWFDEC_AS_CHECK (SWFDEC_TYPE_AS_FUNCTION, &fun, "O", &thisp);
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_AS_FUNCTION, &fun, "|O", &thisp);
 
   if (thisp == NULL) {
     thisp = swfdec_as_object_new_empty (cx);
     if (thisp == NULL)
       return;
   }
+  if (argc > 0) {
+    argc--;
+    argv++;
+  }
   swfdec_as_function_call (fun, thisp, argc, argv, ret);
   swfdec_as_context_run (cx);
 }
@@ -177,7 +181,7 @@ swfdec_as_function_apply (SwfdecAsContext *cx, SwfdecAsObject *object,
   SwfdecAsFunction *fun;
   SwfdecAsObject *thisp;
 
-  SWFDEC_AS_CHECK (SWFDEC_TYPE_AS_FUNCTION, &fun, "O", &thisp);
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_AS_FUNCTION, &fun, "|O", &thisp);
 
   if (thisp == NULL) {
     thisp = swfdec_as_object_new_empty (cx);
commit 8da5b0ddb910c1539387fb531ead8b79a3f6973f
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Nov 13 11:06:41 2007 +0100

    make the g_print a debug message

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 405b9f1..9dc13ad 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -530,7 +530,7 @@ swfdec_sound_buffer_render (gint16 *dest, const SwfdecBuffer *source,
   g_return_if_fail (previous == NULL || swfdec_sound_buffer_get_n_samples (previous, format) > 0);
 
   total_samples = (source->length / channels / width) * rate;
-  g_print ("total: %u - rendering @ %u %u\n", total_samples, offset, n_samples);
+  SWFDEC_LOG ("rendering [%u %u) - total: %u samples", offset, n_samples, total_samples);
   /* FIXME: warn about this? */
   n_samples = MIN (n_samples, total_samples - offset);
   
commit c899e26a85e9ce9931887e4fadbbad7fcdd861d5
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Nov 13 10:56:09 2007 +0100

    add hack that makes (or at least is supposed to make) 8bit sound work

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index a869041..405b9f1 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -522,6 +522,7 @@ swfdec_sound_buffer_render (gint16 *dest, const SwfdecBuffer *source,
   guint rate = swfdec_audio_format_get_granularity (format);
   guint width = swfdec_audio_format_is_16bit (format) ? 2 : 1;
   guint total_samples;
+  gint16 *fixme = NULL;
 
   g_return_if_fail (dest != NULL);
   g_return_if_fail (source != NULL);
@@ -533,12 +534,21 @@ swfdec_sound_buffer_render (gint16 *dest, const SwfdecBuffer *source,
   /* FIXME: warn about this? */
   n_samples = MIN (n_samples, total_samples - offset);
   
-  /* FIXME! */
-  g_return_if_fail (width == 2);
+  if (width == 1) {
+    guint i;
+    /* FIXME: make this faster */
+    fixme = g_try_malloc (source->length * 2);
+    if (fixme == NULL)
+      return;
+    for (i = 0; i < source->length; i++) {
+      fixme[i] = (((gint16) source->data[i]) << 8) - 32768;
+    }
+  }
   if (channels == 2) {
     swfdec_sound_buffer_render_stereo (dest, (const gint16 *) source->data, offset, n_samples, rate);
   } else {
     swfdec_sound_buffer_render_mono (dest, (const gint16 *) source->data, offset, n_samples, rate);
   }
+  g_free (fixme);
 }
 
commit b679aca1d552038a2eeab559554035ec4bab06f5
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Nov 13 10:40:38 2007 +0100

    get rid of the Flash upsampling algorithm
    
    It was broken and the testsuite can cope with a different upscaling method

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 0d795e7..a869041 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -434,6 +434,72 @@ swfdec_sound_buffer_get_n_samples (const SwfdecBuffer *buffer, SwfdecAudioFormat
     swfdec_audio_format_get_granularity (format);
 }
 
+static void
+swfdec_sound_buffer_render_stereo (gint16 *dest, const gint16 *source, guint offset,
+    guint n_samples, guint rate)
+{
+  guint i, j;
+
+  source += 2 * (offset / rate);
+  offset %= rate;
+
+  if (offset) {
+    offset = MIN (rate - offset, n_samples);
+    for (i = 0; i < offset; i++) {
+      *dest++ = source[0];
+      *dest++ = source[1];
+    }
+    source += 2;
+    n_samples -= offset;
+  }
+  for (i = rate; i < n_samples; i += rate) {
+    for (j = 0; j < rate; j++) {
+      *dest++ = source[0];
+      *dest++ = source[1];
+    }
+    source += 2;
+  }
+  n_samples -= i - rate;
+  g_assert (n_samples < rate);
+  for (i = 0; i < n_samples; i++) {
+    *dest++ = source[0];
+    *dest++ = source[1];
+  }
+}
+
+static void
+swfdec_sound_buffer_render_mono (gint16 *dest, const gint16 *source, guint offset,
+    guint n_samples, guint rate)
+{
+  guint i, j;
+
+  source += (offset / rate);
+  offset %= rate;
+
+  if (offset) {
+    offset = MIN (rate - offset, n_samples);
+    for (i = 0; i < offset; i++) {
+      *dest++ = *source;
+      *dest++ = *source;
+    }
+    source++;
+    n_samples -= offset;
+  }
+  for (i = rate; i <= n_samples; i += rate) {
+    for (j = 0; j < rate; j++) {
+      *dest++ = *source;
+      *dest++ = *source;
+    }
+    source++;
+  }
+  n_samples -= i - rate;
+  g_assert (n_samples < rate);
+  for (i = 0; i < n_samples; i++) {
+    *dest++ = *source;
+    *dest++ = *source;
+  }
+}
+
 /**
  * swfdec_sound_render_buffer:
  * @dest: target buffer to render to
@@ -445,109 +511,34 @@ swfdec_sound_buffer_get_n_samples (const SwfdecBuffer *buffer, SwfdecAudioFormat
  * @n_samples: number of samples to render into @dest. If more data would be
  *	       rendered than is available in @source, 0 samples are used instead.
  *
- * Adds data from @source into @dest using the same upsampling algorithm as
- * Flash player.
+ * Adds data from @source into @dest
  **/
-/* NB: if you improve the upsampling algorithm, tests might start to break */
 void
 swfdec_sound_buffer_render (gint16 *dest, const SwfdecBuffer *source, 
-    SwfdecAudioFormat format, const SwfdecBuffer *previous, 
+    SwfdecAudioFormat format, const SwfdecBuffer *previous,
     guint offset, guint n_samples)
 {
-  guint i, j;
   guint channels = swfdec_audio_format_get_channels (format);
   guint rate = swfdec_audio_format_get_granularity (format);
-  gint16 *src, *end;
+  guint width = swfdec_audio_format_is_16bit (format) ? 2 : 1;
+  guint total_samples;
 
   g_return_if_fail (dest != NULL);
   g_return_if_fail (source != NULL);
   g_return_if_fail (swfdec_sound_buffer_get_n_samples (source, format) > 0);
   g_return_if_fail (previous == NULL || swfdec_sound_buffer_get_n_samples (previous, format) > 0);
 
-  src = (gint16 *) source->data;
-  end = (gint16 *) (source->data + source->length);
-  src += channels * (offset / rate);
-  offset %= rate;
-  if (offset) {
-    offset = rate - offset;
-    /* NB: dest will be pointing to uninitialized memory now */
-    dest -= offset * 2;
-    n_samples += offset;
-  }
-  /* this is almost the same as the channels == 1 case, so check for bugfixes in both branches */
-  if (channels == 1) {
-    int values[rate + 1];
-    if (src >= end)
-      n_samples = 0;
-    else if (src != (gint16 *) source->data)
-      values[0] = src[-1];
-    else if (previous)
-      values[0] = ((gint16 *) previous->data)[previous->length / 2 - 1];
-    else
-      values[0] = *src;
-    while (n_samples > 0) {
-      if (src > end)
-	break;
-      else if (src == end)
-	values[rate] = 0;
-      else
-	values[rate] = *src;
-      src++;
-      for (i = rate / 2; i >= 1; i /= 2) {
-	for (j = i; j < rate; j += 2 * i) {
-	  values[j] = (values[j + i] + values[j - i]) / 2;
-	}
-      }
-      for (i = offset; i < MIN (rate, n_samples); i++) {
-	dest[2 * i] += values[i + 1];
-	dest[2 * i + 1] += values[i + 1];
-      }
-      dest += 2 * rate;
-      values[0] = values[rate];
-      offset = 0;
-      n_samples -= MIN (n_samples, rate);
-    }
+  total_samples = (source->length / channels / width) * rate;
+  g_print ("total: %u - rendering @ %u %u\n", total_samples, offset, n_samples);
+  /* FIXME: warn about this? */
+  n_samples = MIN (n_samples, total_samples - offset);
+  
+  /* FIXME! */
+  g_return_if_fail (width == 2);
+  if (channels == 2) {
+    swfdec_sound_buffer_render_stereo (dest, (const gint16 *) source->data, offset, n_samples, rate);
   } else {
-    int values[2][rate + 1];
-    if (src >= end) {
-      n_samples = 0;
-    } else if (src != (gint16 *) source->data) {
-      values[0][0] = src[-2];
-      values[1][0] = src[-1];
-    } else if (previous) {
-      values[0][0] = ((gint16 *) previous->data)[previous->length / 2 - 2];
-      values[1][0] = ((gint16 *) previous->data)[previous->length / 2 - 1];
-    } else {
-      values[0][0] = src[0];
-      values[1][0] = src[1];
-    }
-    while (n_samples > 0) {
-      if (src > end) {
-	break;
-      } else if (src == end) {
-	values[0][rate] = 0;
-	values[1][rate] = 0;
-      } else {
-	values[0][rate] = src[0];
-	values[1][rate] = src[1];
-      }
-      src += 2;
-      for (i = rate / 2; i >= 1; i /= 2) {
-	for (j = i; j < rate; j += 2 * i) {
-	  values[0][j] = (values[0][j + i] + values[0][j - i]) / 2;
-	  values[1][j] = (values[1][j + i] + values[1][j - i]) / 2;
-	}
-      }
-      for (i = offset; i < MIN (rate, n_samples); i++) {
-	dest[2 * i] += values[0][i + 1];
-	dest[2 * i + 1] += values[1][i + 1];
-      }
-      dest += 2 * rate;
-      values[0][0] = values[0][rate];
-      values[1][0] = values[1][rate];
-      offset = 0;
-      n_samples -= MIN (n_samples, rate);
-    }
+    swfdec_sound_buffer_render_mono (dest, (const gint16 *) source->data, offset, n_samples, rate);
   }
 }
 
commit c33b1f84cb237a3506350cb87836edbb262326c1
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Nov 13 10:39:35 2007 +0100

    remove silence from the end of the raw files

diff --git a/test/sound/adpcm-2-2.swf.1.0.raw b/test/sound/adpcm-2-2.swf.1.0.raw
index e5b8175..a6cb08a 100644
Binary files a/test/sound/adpcm-2-2.swf.1.0.raw and b/test/sound/adpcm-2-2.swf.1.0.raw differ
diff --git a/test/sound/adpcm-3-2.swf.1.0.raw b/test/sound/adpcm-3-2.swf.1.0.raw
index 949b1da..a40b57e 100644
Binary files a/test/sound/adpcm-3-2.swf.1.0.raw and b/test/sound/adpcm-3-2.swf.1.0.raw differ
diff --git a/test/sound/adpcm-3.swf.1.0.raw b/test/sound/adpcm-3.swf.1.0.raw
index bae56ea..0d47370 100644
Binary files a/test/sound/adpcm-3.swf.1.0.raw and b/test/sound/adpcm-3.swf.1.0.raw differ
diff --git a/test/sound/adpcm-4.swf.1.0.raw b/test/sound/adpcm-4.swf.1.0.raw
index f89a04c..b38f2dd 100644
Binary files a/test/sound/adpcm-4.swf.1.0.raw and b/test/sound/adpcm-4.swf.1.0.raw differ
diff --git a/test/sound/adpcm-5.swf.1.0.raw b/test/sound/adpcm-5.swf.1.0.raw
index e14b571..d61f5f3 100644
Binary files a/test/sound/adpcm-5.swf.1.0.raw and b/test/sound/adpcm-5.swf.1.0.raw differ


More information about the Swfdec mailing list