[PATCH] Bug 829724 - Fix short buffer resampler returns. r=padenot,kinetik
authorRalph Giles <giles@mozilla.com>
Fri, 11 Jan 2013 14:58:22 -0800
changeset 118834 79addb03eb8672db2be1251846a234696550e316
parent 118833 743e8fac6d505fb4d091a073cf6fe5efef3571cf
child 118835 cebb008a72f9a08b37f68c34d4ccd51137e7a978
push id24180
push useremorley@mozilla.com
push dateTue, 15 Jan 2013 22:58:27 +0000
treeherdermozilla-central@72e34ce7fd92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, kinetik
bugs829724, 100644
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
[PATCH] Bug 829724 - Fix short buffer resampler returns. r=padenot,kinetik From 763e746e97f0c234cea9ad1b674d406f55a2fb51 Mon Sep 17 00:00:00 2001 This applies a patch from the opus-tools fork of the speex resampler, fixing an issue where the resampler could return less that the requested number of samples. https://git.xiph.org/?p=opus-tools.git;a=commitdiff;h=5adadc5 --- media/libspeex_resampler/README_MOZILLA | 3 +- media/libspeex_resampler/src/resample.c | 12 ++++--- media/libspeex_resampler/truncation.patch | 54 +++++++++++++++++++++++++++++++ media/libspeex_resampler/update.sh | 4 +++ 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 media/libspeex_resampler/truncation.patch
media/libspeex_resampler/README_MOZILLA
media/libspeex_resampler/src/resample.c
media/libspeex_resampler/truncation.patch
media/libspeex_resampler/update.sh
--- a/media/libspeex_resampler/README_MOZILLA
+++ b/media/libspeex_resampler/README_MOZILLA
@@ -1,6 +1,5 @@
 This source is from the Speex library (http://git.xiph.org/speex.git/), from
 commit a6d05eb5.
 
 It consists in the audio resampling code (resampler.c) and its header files
-dependancies. No changes have been made to those files, imported in the tree
-using the update.sh script.
+dependancies, imported into the tree using the update.sh script.
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
@@ -955,44 +955,48 @@ EXPORT int speex_resampler_process_int(S
 
    return RESAMPLER_ERR_SUCCESS;
 }
 
 EXPORT int speex_resampler_process_interleaved_float(SpeexResamplerState *st, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
 {
    spx_uint32_t i;
    int istride_save, ostride_save;
-   spx_uint32_t bak_len = *out_len;
+   spx_uint32_t bak_out_len = *out_len;
+   spx_uint32_t bak_in_len = *in_len;
    istride_save = st->in_stride;
    ostride_save = st->out_stride;
    st->in_stride = st->out_stride = st->nb_channels;
    for (i=0;i<st->nb_channels;i++)
    {
-      *out_len = bak_len;
+      *out_len = bak_out_len;
+      *in_len = bak_in_len;
       if (in != NULL)
          speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
       else
          speex_resampler_process_float(st, i, NULL, in_len, out+i, out_len);
    }
    st->in_stride = istride_save;
    st->out_stride = ostride_save;
    return RESAMPLER_ERR_SUCCESS;
 }
                
 EXPORT int speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
 {
    spx_uint32_t i;
    int istride_save, ostride_save;
-   spx_uint32_t bak_len = *out_len;
+   spx_uint32_t bak_out_len = *out_len;
+   spx_uint32_t bak_in_len = *in_len;
    istride_save = st->in_stride;
    ostride_save = st->out_stride;
    st->in_stride = st->out_stride = st->nb_channels;
    for (i=0;i<st->nb_channels;i++)
    {
-      *out_len = bak_len;
+      *out_len = bak_out_len;
+      *in_len = bak_in_len;
       if (in != NULL)
          speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len);
       else
          speex_resampler_process_int(st, i, NULL, in_len, out+i, out_len);
    }
    st->in_stride = istride_save;
    st->out_stride = ostride_save;
    return RESAMPLER_ERR_SUCCESS;
new file mode 100644
--- /dev/null
+++ b/media/libspeex_resampler/truncation.patch
@@ -0,0 +1,54 @@
+From 5adadc5626ee2d5d3a3ca21e70fd195b9d002a0b Mon Sep 17 00:00:00 2001
+From: Jean-Marc Valin <jmvalin@jmvalin.ca>
+Date: Wed, 1 Aug 2012 13:19:38 -0400
+Subject: [PATCH] Properly save in_len for multiple channels in the resampler.
+
+This fixes issues with clicking in one channel and/or truncation
+with some unusual sample rates.
+---
+ src/resample.c |   12 ++++++++----
+ 1 files changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/src/resample.c b/src/resample.c
+index 84aaf59..6e92bd0 100644
+--- a/src/resample.c
++++ b/src/resample.c
+@@ -966,13 +966,15 @@ SPX_RESAMPLE_EXPORT int speex_resampler_process_interleaved_float(SpeexResampler
+ {
+    spx_uint32_t i;
+    int istride_save, ostride_save;
+-   spx_uint32_t bak_len = *out_len;
++   spx_uint32_t bak_out_len = *out_len;
++   spx_uint32_t bak_in_len = *in_len;
+    istride_save = st->in_stride;
+    ostride_save = st->out_stride;
+    st->in_stride = st->out_stride = st->nb_channels;
+    for (i=0;i<st->nb_channels;i++)
+    {
+-      *out_len = bak_len;
++      *out_len = bak_out_len;
++      *in_len = bak_in_len;
+       if (in != NULL)
+          speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
+       else
+@@ -987,13 +989,15 @@ SPX_RESAMPLE_EXPORT int speex_resampler_process_interleaved_int(SpeexResamplerSt
+ {
+    spx_uint32_t i;
+    int istride_save, ostride_save;
+-   spx_uint32_t bak_len = *out_len;
++   spx_uint32_t bak_out_len = *out_len;
++   spx_uint32_t bak_in_len = *in_len;
+    istride_save = st->in_stride;
+    ostride_save = st->out_stride;
+    st->in_stride = st->out_stride = st->nb_channels;
+    for (i=0;i<st->nb_channels;i++)
+    {
+-      *out_len = bak_len;
++      *out_len = bak_out_len;
++      *in_len = bak_in_len;
+       if (in != NULL)
+          speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len);
+       else
+-- 
+1.7.2.5
+
--- a/media/libspeex_resampler/update.sh
+++ b/media/libspeex_resampler/update.sh
@@ -1,17 +1,21 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Usage: ./update.sh <libspeex_src_directory>
 #
 # Copies the needed files from a directory containing the original
 # libspeex sources that we need for HTML5 media playback rate change.
+
 cp $1/libspeex/resample.c src
 cp $1/libspeex/arch.h src
 cp $1/libspeex/stack_alloc.h src
 cp $1/libspeex/fixed_generic.h src
 cp $1/include/speex/speex_resampler.h src
 cp $1/include/speex/speex_types.h src
 sed -e 's/unsigned @SIZE16@/uint16_t/g' -e 's/unsigned @SIZE32@/uint32_t/g' -e 's/@SIZE16@/int16_t/g' -e 's/@SIZE32@/int32_t/g' < $1/include/speex/speex_config_types.h.in > src/speex_config_types.h
 cp $1/AUTHORS .
 cp $1/COPYING .
+
+# apply outstanding local patches
+patch -p1 < truncation.patch