summaryrefslogtreecommitdiff
path: root/apps/codecs/libspeex
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2007-05-22 09:50:31 +0000
committerDan Everton <dan@iocaine.org>2007-05-22 09:50:31 +0000
commitdf6f2f9a3c88a7a4a8ad0382ee4ee7c9a3ee3256 (patch)
treed9862e5d04f4014def5911bb4ff8206c85636fb7 /apps/codecs/libspeex
parent8970055ec107a2387eedbb373889d0f540745121 (diff)
downloadrockbox-df6f2f9a3c88a7a4a8ad0382ee4ee7c9a3ee3256.tar.gz
rockbox-df6f2f9a3c88a7a4a8ad0382ee4ee7c9a3ee3256.zip
Upgrade to libspeex 1.2beta2. Very minor performance increase (0.6% on coldfire).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13461 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libspeex')
-rw-r--r--apps/codecs/libspeex/README.rockbox2
-rw-r--r--apps/codecs/libspeex/_kiss_fft_guts.h1
-rw-r--r--apps/codecs/libspeex/arch.h2
-rw-r--r--apps/codecs/libspeex/bits.c24
-rw-r--r--apps/codecs/libspeex/cb_search.c2
-rw-r--r--apps/codecs/libspeex/config-speex.h1
-rw-r--r--apps/codecs/libspeex/filters.c21
-rw-r--r--apps/codecs/libspeex/filters.h1
-rw-r--r--apps/codecs/libspeex/filters_arm4.h1
-rw-r--r--apps/codecs/libspeex/jitter.c13
-rw-r--r--apps/codecs/libspeex/ltp_arm4.h2
-rw-r--r--apps/codecs/libspeex/ltp_bfin.h10
-rw-r--r--apps/codecs/libspeex/mdf.c57
-rw-r--r--apps/codecs/libspeex/medfilter.c4
-rw-r--r--apps/codecs/libspeex/misc.c39
-rw-r--r--apps/codecs/libspeex/misc.h28
-rw-r--r--apps/codecs/libspeex/modes.c2
-rw-r--r--apps/codecs/libspeex/modes.h3
-rw-r--r--apps/codecs/libspeex/nb_celp.c44
-rw-r--r--apps/codecs/libspeex/nb_celp.h6
-rw-r--r--apps/codecs/libspeex/preprocess.c22
-rw-r--r--apps/codecs/libspeex/resample.c380
-rw-r--r--apps/codecs/libspeex/rockbox.c5
-rw-r--r--apps/codecs/libspeex/sb_celp.c64
-rw-r--r--apps/codecs/libspeex/speex/speex.h14
-rw-r--r--apps/codecs/libspeex/speex/speex_bits.h3
-rw-r--r--apps/codecs/libspeex/speex/speex_jitter.h4
-rw-r--r--apps/codecs/libspeex/speex/speex_resampler.h133
-rw-r--r--apps/codecs/libspeex/speex_header.c4
-rw-r--r--apps/codecs/libspeex/testdenoise.c2
-rw-r--r--apps/codecs/libspeex/testecho.c2
-rw-r--r--apps/codecs/libspeex/testenc.c2
-rw-r--r--apps/codecs/libspeex/testenc_uwb.c2
-rw-r--r--apps/codecs/libspeex/testenc_wb.c2
-rw-r--r--apps/codecs/libspeex/testresample.c14
-rw-r--r--apps/codecs/libspeex/vbr.c12
36 files changed, 626 insertions, 302 deletions
diff --git a/apps/codecs/libspeex/README.rockbox b/apps/codecs/libspeex/README.rockbox
index 6aeda714ab..a526420b91 100644
--- a/apps/codecs/libspeex/README.rockbox
+++ b/apps/codecs/libspeex/README.rockbox
@@ -1,4 +1,4 @@
1Library: libspeex-1.2beta1 (SVN version 12735) 1Library: libspeex-1.2beta2 (SVN version 12966)
2Imported: 2007-03-12 by Dan Everton 2Imported: 2007-03-12 by Dan Everton
3 3
4 4
diff --git a/apps/codecs/libspeex/_kiss_fft_guts.h b/apps/codecs/libspeex/_kiss_fft_guts.h
index 322299c197..6eb9bd312b 100644
--- a/apps/codecs/libspeex/_kiss_fft_guts.h
+++ b/apps/codecs/libspeex/_kiss_fft_guts.h
@@ -12,6 +12,7 @@ Redistribution and use in source and binary forms, with or without modification,
12THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*/ 13*/
14 14
15
15/* kiss_fft.h 16/* kiss_fft.h
16 defines kiss_fft_scalar as either short or a float type 17 defines kiss_fft_scalar as either short or a float type
17 and defines 18 and defines
diff --git a/apps/codecs/libspeex/arch.h b/apps/codecs/libspeex/arch.h
index 2bc5061b29..e2d731acc0 100644
--- a/apps/codecs/libspeex/arch.h
+++ b/apps/codecs/libspeex/arch.h
@@ -35,7 +35,9 @@
35#ifndef ARCH_H 35#ifndef ARCH_H
36#define ARCH_H 36#define ARCH_H
37 37
38#ifndef OUTSIDE_SPEEX
38#include "speex/speex_types.h" 39#include "speex/speex_types.h"
40#endif
39 41
40#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ 42#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
41#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ 43#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
diff --git a/apps/codecs/libspeex/bits.c b/apps/codecs/libspeex/bits.c
index 6173246380..379fe748d4 100644
--- a/apps/codecs/libspeex/bits.c
+++ b/apps/codecs/libspeex/bits.c
@@ -67,6 +67,20 @@ void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size)
67 speex_bits_reset(bits); 67 speex_bits_reset(bits);
68} 68}
69 69
70void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size)
71{
72 bits->chars = (char*)buff;
73 bits->buf_size = buf_size;
74
75 bits->owner=0;
76
77 bits->nbBits=buf_size<<LOG2_BITS_PER_CHAR;
78 bits->charPtr=0;
79 bits->bitPtr=0;
80 bits->overflow=0;
81
82}
83
70void speex_bits_destroy(SpeexBits *bits) 84void speex_bits_destroy(SpeexBits *bits)
71{ 85{
72 if (bits->owner) 86 if (bits->owner)
@@ -97,7 +111,7 @@ void speex_bits_read_from(SpeexBits *bits, char *chars, int len)
97 int nchars = len / BYTES_PER_CHAR; 111 int nchars = len / BYTES_PER_CHAR;
98 if (nchars > bits->buf_size) 112 if (nchars > bits->buf_size)
99 { 113 {
100 speex_warning_int("Packet is larger than allocated buffer: ", len); 114 speex_notify("Packet is larger than allocated buffer");
101 if (bits->owner) 115 if (bits->owner)
102 { 116 {
103 char *tmp = (char*)speex_realloc(bits->chars, nchars); 117 char *tmp = (char*)speex_realloc(bits->chars, nchars);
@@ -110,7 +124,7 @@ void speex_bits_read_from(SpeexBits *bits, char *chars, int len)
110 speex_warning("Could not resize input buffer: truncating input"); 124 speex_warning("Could not resize input buffer: truncating input");
111 } 125 }
112 } else { 126 } else {
113 speex_warning("Do not own input buffer: truncating input"); 127 speex_warning("Do not own input buffer: truncating oversize input");
114 nchars=bits->buf_size; 128 nchars=bits->buf_size;
115 } 129 }
116 } 130 }
@@ -159,10 +173,10 @@ void speex_bits_read_whole_bytes(SpeexBits *bits, char *chars, int nbytes)
159 bits->chars=tmp; 173 bits->chars=tmp;
160 } else { 174 } else {
161 nchars=bits->buf_size-(bits->nbBits>>LOG2_BITS_PER_CHAR)-1; 175 nchars=bits->buf_size-(bits->nbBits>>LOG2_BITS_PER_CHAR)-1;
162 speex_warning("Could not resize input buffer: truncating input"); 176 speex_warning("Could not resize input buffer: truncating oversize input");
163 } 177 }
164 } else { 178 } else {
165 speex_warning("Do not own input buffer: truncating input"); 179 speex_warning("Do not own input buffer: truncating oversize input");
166 nchars=bits->buf_size; 180 nchars=bits->buf_size;
167 } 181 }
168 } 182 }
@@ -223,7 +237,7 @@ void speex_bits_pack(SpeexBits *bits, int data, int nbBits)
223 237
224 if (bits->charPtr+((nbBits+bits->bitPtr)>>LOG2_BITS_PER_CHAR) >= bits->buf_size) 238 if (bits->charPtr+((nbBits+bits->bitPtr)>>LOG2_BITS_PER_CHAR) >= bits->buf_size)
225 { 239 {
226 speex_warning("Buffer too small to pack bits"); 240 speex_notify("Buffer too small to pack bits");
227 if (bits->owner) 241 if (bits->owner)
228 { 242 {
229 int new_nchars = ((bits->buf_size+5)*3)>>1; 243 int new_nchars = ((bits->buf_size+5)*3)>>1;
diff --git a/apps/codecs/libspeex/cb_search.c b/apps/codecs/libspeex/cb_search.c
index ce7ae7e8ce..1090af0e08 100644
--- a/apps/codecs/libspeex/cb_search.c
+++ b/apps/codecs/libspeex/cb_search.c
@@ -181,7 +181,7 @@ int update_target
181 t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]); 181 t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]);
182 182
183#ifdef FIXED_POINT 183#ifdef FIXED_POINT
184 if (sign) 184 if (sign==1)
185 { 185 {
186 for (j=0;j<subvect_size;j++) 186 for (j=0;j<subvect_size;j++)
187 e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5); 187 e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5);
diff --git a/apps/codecs/libspeex/config-speex.h b/apps/codecs/libspeex/config-speex.h
index efdb7dbb54..461873945f 100644
--- a/apps/codecs/libspeex/config-speex.h
+++ b/apps/codecs/libspeex/config-speex.h
@@ -163,5 +163,6 @@
163#define OVERRIDE_SPEEX_ERROR 1 163#define OVERRIDE_SPEEX_ERROR 1
164#define OVERRIDE_SPEEX_WARNING 1 164#define OVERRIDE_SPEEX_WARNING 1
165#define OVERRIDE_SPEEX_WARNING_INT 1 165#define OVERRIDE_SPEEX_WARNING_INT 1
166#define OVERRIDE_SPEEX_NOTIFY 1
166#define OVERRIDE_SPEEX_PUTC 1 167#define OVERRIDE_SPEEX_PUTC 1
167 168
diff --git a/apps/codecs/libspeex/filters.c b/apps/codecs/libspeex/filters.c
index 1ae6854d51..3d9d118cb6 100644
--- a/apps/codecs/libspeex/filters.c
+++ b/apps/codecs/libspeex/filters.c
@@ -34,6 +34,7 @@
34#include "config-speex.h" 34#include "config-speex.h"
35#endif 35#endif
36 36
37#include "filters.h"
37#include "stack_alloc.h" 38#include "stack_alloc.h"
38#include "misc.h" 39#include "misc.h"
39#include "math_approx.h" 40#include "math_approx.h"
@@ -46,8 +47,6 @@
46#include "filters_arm4.h" 47#include "filters_arm4.h"
47#elif defined (BFIN_ASM) 48#elif defined (BFIN_ASM)
48#include "filters_bfin.h" 49#include "filters_bfin.h"
49#else
50#include "filters.h"
51#endif 50#endif
52 51
53 52
@@ -63,6 +62,24 @@ void bw_lpc(spx_word16_t gamma, const spx_coef_t *lpc_in, spx_coef_t *lpc_out, i
63 } 62 }
64} 63}
65 64
65void sanitize_values32(spx_word32_t *vec, spx_word32_t min_val, spx_word32_t max_val, int len)
66{
67 int i;
68 for (i=0;i<len;i++)
69 {
70 /* It's important we do the test that way so we can catch NaNs, which are neither greater nor smaller */
71 if (!(vec[i]>=min_val && vec[i] <= max_val))
72 {
73 if (vec[i] < min_val)
74 vec[i] = min_val;
75 else if (vec[i] > max_val)
76 vec[i] = max_val;
77 else /* Has to be NaN */
78 vec[i] = 0;
79 }
80 }
81}
82
66void highpass(const spx_word16_t *x, spx_word16_t *y, int len, int filtID, spx_mem_t *mem) 83void highpass(const spx_word16_t *x, spx_word16_t *y, int len, int filtID, spx_mem_t *mem)
67{ 84{
68 int i; 85 int i;
diff --git a/apps/codecs/libspeex/filters.h b/apps/codecs/libspeex/filters.h
index fee68aba31..b363a9a683 100644
--- a/apps/codecs/libspeex/filters.h
+++ b/apps/codecs/libspeex/filters.h
@@ -67,6 +67,7 @@ void fir_mem16(const spx_word16_t *x, const spx_coef_t *num, spx_word16_t *y, in
67 67
68/* Apply bandwidth expansion on LPC coef */ 68/* Apply bandwidth expansion on LPC coef */
69void bw_lpc(spx_word16_t , const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order); 69void bw_lpc(spx_word16_t , const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order);
70void sanitize_values32(spx_word32_t *vec, spx_word32_t min_val, spx_word32_t max_val, int len);
70 71
71 72
72void syn_percep_zero16(const spx_word16_t *xx, const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack); 73void syn_percep_zero16(const spx_word16_t *xx, const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack);
diff --git a/apps/codecs/libspeex/filters_arm4.h b/apps/codecs/libspeex/filters_arm4.h
index 6bdfe4797c..91386100a4 100644
--- a/apps/codecs/libspeex/filters_arm4.h
+++ b/apps/codecs/libspeex/filters_arm4.h
@@ -35,6 +35,7 @@
35#define OVERRIDE_NORMALIZE16 35#define OVERRIDE_NORMALIZE16
36int normalize16(const spx_sig_t *x, spx_word16_t *y, int max_scale, int len) 36int normalize16(const spx_sig_t *x, spx_word16_t *y, int max_scale, int len)
37{ 37{
38 int i;
38 spx_sig_t max_val=1; 39 spx_sig_t max_val=1;
39 int sig_shift; 40 int sig_shift;
40 int dead1, dead2, dead3, dead4, dead5, dead6; 41 int dead1, dead2, dead3, dead4, dead5, dead6;
diff --git a/apps/codecs/libspeex/jitter.c b/apps/codecs/libspeex/jitter.c
index 02919e2135..81935e9195 100644
--- a/apps/codecs/libspeex/jitter.c
+++ b/apps/codecs/libspeex/jitter.c
@@ -197,7 +197,7 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet)
197 197
198 /* Adjust the buffer size depending on network conditions. 198 /* Adjust the buffer size depending on network conditions.
199 The arrival margin is how much in advance (or late) the packet it */ 199 The arrival margin is how much in advance (or late) the packet it */
200 arrival_margin = (packet->timestamp - jitter->current_timestamp)/jitter->tick_size - jitter->buffer_margin; 200 arrival_margin = (((spx_int32_t)packet->timestamp) - ((spx_int32_t)jitter->current_timestamp))/jitter->tick_size - jitter->buffer_margin;
201 201
202 if (arrival_margin >= -jitter->late_cutoff) 202 if (arrival_margin >= -jitter->late_cutoff)
203 { 203 {
@@ -243,7 +243,7 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet)
243} 243}
244 244
245/** Get one packet from the jitter buffer */ 245/** Get one packet from the jitter buffer */
246int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_uint32_t *start_offset) 246int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
247{ 247{
248 int i; 248 int i;
249 unsigned int j; 249 unsigned int j;
@@ -378,7 +378,7 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_uint
378 jitter->buf[i] = NULL; 378 jitter->buf[i] = NULL;
379 /* Set timestamp and span (if requested) */ 379 /* Set timestamp and span (if requested) */
380 if (start_offset) 380 if (start_offset)
381 *start_offset = jitter->timestamp[i]-jitter->pointer_timestamp; 381 *start_offset = (spx_int32_t)jitter->timestamp[i]-(spx_int32_t)jitter->pointer_timestamp;
382 packet->timestamp = jitter->timestamp[i]; 382 packet->timestamp = jitter->timestamp[i];
383 packet->span = jitter->span[i]; 383 packet->span = jitter->span[i];
384 /* Point at the end of the current packet */ 384 /* Point at the end of the current packet */
@@ -438,7 +438,7 @@ void jitter_buffer_tick(JitterBuffer *jitter)
438} 438}
439 439
440/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */ 440/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
441int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_uint32_t *start_offset) 441int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
442{ 442{
443 int i; 443 int i;
444 float late_ratio_short; 444 float late_ratio_short;
@@ -579,6 +579,7 @@ void speex_jitter_get(SpeexJitter *jitter, short *out, int *current_timestamp)
579{ 579{
580 int i; 580 int i;
581 int ret; 581 int ret;
582 spx_int32_t activity;
582 char data[2048]; 583 char data[2048];
583 JitterBufferPacket packet; 584 JitterBufferPacket packet;
584 packet.data = data; 585 packet.data = data;
@@ -618,7 +619,9 @@ void speex_jitter_get(SpeexJitter *jitter, short *out, int *current_timestamp)
618 out[i]=0; 619 out[i]=0;
619 } 620 }
620 } 621 }
621 jitter_buffer_update_delay(jitter->packets, &packet, NULL); 622 speex_decoder_ctl(jitter->dec, SPEEX_GET_ACTIVITY, &activity);
623 if (activity < 30)
624 jitter_buffer_update_delay(jitter->packets, &packet, NULL);
622 jitter_buffer_tick(jitter->packets); 625 jitter_buffer_tick(jitter->packets);
623} 626}
624 627
diff --git a/apps/codecs/libspeex/ltp_arm4.h b/apps/codecs/libspeex/ltp_arm4.h
index 5f667cf41b..cdb94e603a 100644
--- a/apps/codecs/libspeex/ltp_arm4.h
+++ b/apps/codecs/libspeex/ltp_arm4.h
@@ -171,7 +171,7 @@ void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *c
171 "\tstr %7, %14 \n" 171 "\tstr %7, %14 \n"
172 172
173 : "+r" (y0), "+r" (y1), "+r" (y2), "+r" (y3), 173 : "+r" (y0), "+r" (y1), "+r" (y2), "+r" (y3),
174 "=r" (part1), "=r" (part2), "=r" (part3), "=r" (part4), 174 "=r" (part1), "=r" (part2), "=r" (part3), "=r" (part4),
175 "+r" (x), "+r" (y), "=r" (x0), "+m" (sum1), 175 "+r" (x), "+r" (y), "=r" (x0), "+m" (sum1),
176 "+m" (sum2), "+m" (sum3), "+m" (sum4), "=r" (dead1) 176 "+m" (sum2), "+m" (sum3), "+m" (sum4), "=r" (dead1)
177 : 177 :
diff --git a/apps/codecs/libspeex/ltp_bfin.h b/apps/codecs/libspeex/ltp_bfin.h
index c4669022f1..b530f85986 100644
--- a/apps/codecs/libspeex/ltp_bfin.h
+++ b/apps/codecs/libspeex/ltp_bfin.h
@@ -330,7 +330,6 @@ static int pitch_gain_search_3tap_vq(
330" %0 = 0;\n\t" /* %0: best_sum */ 330" %0 = 0;\n\t" /* %0: best_sum */
331" %1 = 0;\n\t" /* %1: best_cbdk */ 331" %1 = 0;\n\t" /* %1: best_cbdk */
332" P1 = 0;\n\t" /* P1: loop counter */ 332" P1 = 0;\n\t" /* P1: loop counter */
333" R5 = 64;\n\t" /* R5: pitch_control */
334 333
335" LSETUP (pgs1, pgs2) LC1 = %4;\n\t" 334" LSETUP (pgs1, pgs2) LC1 = %4;\n\t"
336"pgs1: R2 = B [P0++] (X);\n\t" /* R2: g[0] */ 335"pgs1: R2 = B [P0++] (X);\n\t" /* R2: g[0] */
@@ -339,6 +338,7 @@ static int pitch_gain_search_3tap_vq(
339" R2 += 32;\n\t" 338" R2 += 32;\n\t"
340" R3 += 32;\n\t" 339" R3 += 32;\n\t"
341" R4 += 32;\n\t" 340" R4 += 32;\n\t"
341" R4.H = 64;\n\t" /* R4.H: pitch_control */
342 342
343" R0 = B [P0++] (X);\n\t" 343" R0 = B [P0++] (X);\n\t"
344" B0 = R0;\n\t" /* BO: gain_sum */ 344" B0 = R0;\n\t" /* BO: gain_sum */
@@ -349,13 +349,13 @@ static int pitch_gain_search_3tap_vq(
349" A0 = 0;\n\t" 349" A0 = 0;\n\t"
350 350
351" R0.L = W[I1++];\n\t" 351" R0.L = W[I1++];\n\t"
352" R1.L = R2.L*R5.L (IS);\n\t" 352" R1.L = R2.L*R4.H (IS);\n\t"
353" A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t" 353" A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
354 354
355" R1.L = R3.L*R5.L (IS);\n\t" 355" R1.L = R3.L*R4.H (IS);\n\t"
356" A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t" 356" A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
357 357
358" R1.L = R4.L*R5.L (IS);\n\t" 358" R1.L = R4.L*R4.H (IS);\n\t"
359" A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t" 359" A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
360 360
361" R1.L = R2.L*R3.L (IS);\n\t" 361" R1.L = R2.L*R3.L (IS);\n\t"
@@ -406,7 +406,7 @@ static int pitch_gain_search_3tap_vq(
406 : "=&d" (best_sum), "=&d" (best_cdbk) 406 : "=&d" (best_sum), "=&d" (best_cdbk)
407 : "a" (gain_cdbk), "a" (C16), "a" (gain_cdbk_size), "a" (max_gain), 407 : "a" (gain_cdbk), "a" (C16), "a" (gain_cdbk_size), "a" (max_gain),
408 "b" (-VERY_LARGE32) 408 "b" (-VERY_LARGE32)
409 : "R0", "R1", "R2", "R3", "R4", "R5", "P0", 409 : "R0", "R1", "R2", "R3", "R4", "P0",
410 "P1", "I1", "L1", "A0", "B0" 410 "P1", "I1", "L1", "A0", "B0"
411#if (__GNUC__ == 4) 411#if (__GNUC__ == 4)
412 , "LC1" 412 , "LC1"
diff --git a/apps/codecs/libspeex/mdf.c b/apps/codecs/libspeex/mdf.c
index d67c36d6dc..2fe3bd08fd 100644
--- a/apps/codecs/libspeex/mdf.c
+++ b/apps/codecs/libspeex/mdf.c
@@ -41,8 +41,8 @@
41 double-talk is achieved using a variable learning rate as described in: 41 double-talk is achieved using a variable learning rate as described in:
42 42
43 Valin, J.-M., On Adjusting the Learning Rate in Frequency Domain Echo 43 Valin, J.-M., On Adjusting the Learning Rate in Frequency Domain Echo
44 Cancellation With Double-Talk. To appear in IEEE Transactions on Audio, 44 Cancellation With Double-Talk. IEEE Transactions on Audio,
45 Speech and Language Processing, 2006. 45 Speech and Language Processing, Vol. 15, No. 3, pp. 1030-1034, 2007.
46 http://people.xiph.org/~jm/papers/valin_taslp2006.pdf 46 http://people.xiph.org/~jm/papers/valin_taslp2006.pdf
47 47
48 There is no explicit double-talk detection, but a continuous variation 48 There is no explicit double-talk detection, but a continuous variation
@@ -360,12 +360,36 @@ static inline void mdf_adjust_prop(const spx_word32_t *W, int N, int M, spx_word
360 /*printf ("\n");*/ 360 /*printf ("\n");*/
361} 361}
362 362
363#ifdef DUMP_ECHO_CANCEL_DATA
364#include <stdio.h>
365static FILE *rFile=NULL, *pFile=NULL, *oFile=NULL;
366
367static void dump_audio(const spx_int16_t *rec, const spx_int16_t *play, const spx_int16_t *out, int len)
368{
369 if (!(rFile && pFile && oFile))
370 {
371 speex_error("Dump files not open");
372 }
373 fwrite(rec, sizeof(spx_int16_t), len, rFile);
374 fwrite(play, sizeof(spx_int16_t), len, pFile);
375 fwrite(out, sizeof(spx_int16_t), len, oFile);
376}
377#endif
378
363/** Creates a new echo canceller state */ 379/** Creates a new echo canceller state */
364SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length) 380SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length)
365{ 381{
366 int i,N,M; 382 int i,N,M;
367 SpeexEchoState *st = (SpeexEchoState *)speex_alloc(sizeof(SpeexEchoState)); 383 SpeexEchoState *st = (SpeexEchoState *)speex_alloc(sizeof(SpeexEchoState));
368 384
385#ifdef DUMP_ECHO_CANCEL_DATA
386 if (rFile || pFile || oFile)
387 speex_error("Opening dump files twice");
388 rFile = fopen("aec_rec.sw", "w");
389 pFile = fopen("aec_play.sw", "w");
390 oFile = fopen("aec_out.sw", "w");
391#endif
392
369 st->frame_size = frame_size; 393 st->frame_size = frame_size;
370 st->window_size = 2*frame_size; 394 st->window_size = 2*frame_size;
371 N = st->window_size; 395 N = st->window_size;
@@ -553,6 +577,13 @@ void speex_echo_state_destroy(SpeexEchoState *st)
553#endif 577#endif
554 speex_free(st->play_buf); 578 speex_free(st->play_buf);
555 speex_free(st); 579 speex_free(st);
580
581#ifdef DUMP_ECHO_CANCEL_DATA
582 fclose(rFile);
583 fclose(pFile);
584 fclose(oFile);
585 rFile = pFile = oFile = NULL;
586#endif
556} 587}
557 588
558void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out) 589void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out)
@@ -701,8 +732,8 @@ void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const sp
701 spectral_mul_accum16(st->X, st->foreground, st->Y, N, M); 732 spectral_mul_accum16(st->X, st->foreground, st->Y, N, M);
702 spx_ifft(st->fft_table, st->Y, st->e); 733 spx_ifft(st->fft_table, st->Y, st->e);
703 for (i=0;i<st->frame_size;i++) 734 for (i=0;i<st->frame_size;i++)
704 st->x[i+st->frame_size] = SUB16(st->input[i], st->e[i+st->frame_size]); 735 st->e[i] = SUB16(st->input[i], st->e[i+st->frame_size]);
705 Sff = mdf_inner_prod(st->x+st->frame_size, st->x+st->frame_size, st->frame_size); 736 Sff = mdf_inner_prod(st->e, st->e, st->frame_size);
706#endif 737#endif
707 738
708 /* Adjust proportional adaption rate */ 739 /* Adjust proportional adaption rate */
@@ -762,13 +793,13 @@ void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const sp
762#ifdef TWO_PATH 793#ifdef TWO_PATH
763 /* Difference in response, this is used to estimate the variance of our residual power estimate */ 794 /* Difference in response, this is used to estimate the variance of our residual power estimate */
764 for (i=0;i<st->frame_size;i++) 795 for (i=0;i<st->frame_size;i++)
765 st->x[i+st->frame_size] = SUB16(st->e[i+st->frame_size], st->y[i+st->frame_size]); 796 st->e[i] = SUB16(st->e[i+st->frame_size], st->y[i+st->frame_size]);
766 Dbf = 10+mdf_inner_prod(st->x+st->frame_size, st->x+st->frame_size, st->frame_size); 797 Dbf = 10+mdf_inner_prod(st->e, st->e, st->frame_size);
767#endif 798#endif
768 799
769 for (i=0;i<st->frame_size;i++) 800 for (i=0;i<st->frame_size;i++)
770 st->x[i+st->frame_size] = SUB16(st->input[i], st->y[i+st->frame_size]); 801 st->e[i] = SUB16(st->input[i], st->y[i+st->frame_size]);
771 See = mdf_inner_prod(st->x+st->frame_size, st->x+st->frame_size, st->frame_size); 802 See = mdf_inner_prod(st->e, st->e, st->frame_size);
772#ifndef TWO_PATH 803#ifndef TWO_PATH
773 Sff = See; 804 Sff = See;
774#endif 805#endif
@@ -828,7 +859,7 @@ void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const sp
828 for (i=0;i<st->frame_size;i++) 859 for (i=0;i<st->frame_size;i++)
829 st->y[i+st->frame_size] = st->e[i+st->frame_size]; 860 st->y[i+st->frame_size] = st->e[i+st->frame_size];
830 for (i=0;i<st->frame_size;i++) 861 for (i=0;i<st->frame_size;i++)
831 st->x[i+st->frame_size] = SUB16(st->input[i], st->y[i+st->frame_size]); 862 st->e[i] = SUB16(st->input[i], st->y[i+st->frame_size]);
832 See = Sff; 863 See = Sff;
833 st->Davg1 = st->Davg2 = 0; 864 st->Davg1 = st->Davg2 = 0;
834 st->Dvar1 = st->Dvar2 = FLOAT_ZERO; 865 st->Dvar1 = st->Dvar2 = FLOAT_ZERO;
@@ -861,12 +892,16 @@ void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const sp
861 out[i] = (spx_int16_t)tmp_out; 892 out[i] = (spx_int16_t)tmp_out;
862 st->memE = tmp_out; 893 st->memE = tmp_out;
863 } 894 }
864 895
896#ifdef DUMP_ECHO_CANCEL_DATA
897 dump_audio(in, far_end, out, st->frame_size);
898#endif
899
865 /* Compute error signal (filter update version) */ 900 /* Compute error signal (filter update version) */
866 for (i=0;i<st->frame_size;i++) 901 for (i=0;i<st->frame_size;i++)
867 { 902 {
903 st->e[i+st->frame_size] = st->e[i];
868 st->e[i] = 0; 904 st->e[i] = 0;
869 st->e[i+st->frame_size] = st->x[i+st->frame_size];
870 } 905 }
871 906
872 /* Compute a bunch of correlations */ 907 /* Compute a bunch of correlations */
diff --git a/apps/codecs/libspeex/medfilter.c b/apps/codecs/libspeex/medfilter.c
index 83872e5474..e4bc1c6ce9 100644
--- a/apps/codecs/libspeex/medfilter.c
+++ b/apps/codecs/libspeex/medfilter.c
@@ -32,6 +32,10 @@
32 32
33*/ 33*/
34 34
35#ifdef HAVE_CONFIG_H
36#include "config-speex.h"
37#endif
38
35#include "medfilter.h" 39#include "medfilter.h"
36#include "misc.h" 40#include "misc.h"
37 41
diff --git a/apps/codecs/libspeex/misc.c b/apps/codecs/libspeex/misc.c
index a0a6e3da37..ae6869781d 100644
--- a/apps/codecs/libspeex/misc.c
+++ b/apps/codecs/libspeex/misc.c
@@ -63,30 +63,6 @@ long long spx_mips=0;
63#endif 63#endif
64 64
65 65
66spx_uint32_t be_int(spx_uint32_t i)
67{
68 spx_uint32_t ret=i;
69#ifndef WORDS_BIGENDIAN
70 ret = i>>24;
71 ret += (i>>8)&0x0000ff00;
72 ret += (i<<8)&0x00ff0000;
73 ret += (i<<24);
74#endif
75 return ret;
76}
77
78spx_uint32_t le_int(spx_uint32_t i)
79{
80 spx_uint32_t ret=i;
81#ifdef WORDS_BIGENDIAN
82 ret = i>>24;
83 ret += (i>>8)&0x0000ff00;
84 ret += (i<<8)&0x00ff0000;
85 ret += (i<<24);
86#endif
87 return ret;
88}
89
90#ifndef OVERRIDE_SPEEX_ALLOC 66#ifndef OVERRIDE_SPEEX_ALLOC
91void *speex_alloc (int size) 67void *speex_alloc (int size)
92{ 68{
@@ -132,7 +108,7 @@ void *speex_move (void *dest, void *src, int n)
132#ifndef OVERRIDE_SPEEX_ERROR 108#ifndef OVERRIDE_SPEEX_ERROR
133void speex_error(const char *str) 109void speex_error(const char *str)
134{ 110{
135 fprintf (stderr, "Fatal error: %s\n", str); 111 fprintf (stderr, "Fatal (internal) error: %s\n", str);
136 exit(1); 112 exit(1);
137} 113}
138#endif 114#endif
@@ -140,14 +116,27 @@ void speex_error(const char *str)
140#ifndef OVERRIDE_SPEEX_WARNING 116#ifndef OVERRIDE_SPEEX_WARNING
141void speex_warning(const char *str) 117void speex_warning(const char *str)
142{ 118{
119#ifndef DISABLE_WARNINGS
143 fprintf (stderr, "warning: %s\n", str); 120 fprintf (stderr, "warning: %s\n", str);
121#endif
144} 122}
145#endif 123#endif
146 124
147#ifndef OVERRIDE_SPEEX_WARNING_INT 125#ifndef OVERRIDE_SPEEX_WARNING_INT
148void speex_warning_int(const char *str, int val) 126void speex_warning_int(const char *str, int val)
149{ 127{
128#ifndef DISABLE_WARNINGS
150 fprintf (stderr, "warning: %s %d\n", str, val); 129 fprintf (stderr, "warning: %s %d\n", str, val);
130#endif
131}
132#endif
133
134#ifndef OVERRIDE_SPEEX_NOTIFY
135void speex_notify(const char *str)
136{
137#ifndef DISABLE_NOTIFICATIONS
138 fprintf (stderr, "notification: %s\n", str);
139#endif
151} 140}
152#endif 141#endif
153 142
diff --git a/apps/codecs/libspeex/misc.h b/apps/codecs/libspeex/misc.h
index 1d6c6cb49f..1664aaed9d 100644
--- a/apps/codecs/libspeex/misc.h
+++ b/apps/codecs/libspeex/misc.h
@@ -38,9 +38,9 @@
38#ifndef SPEEX_VERSION 38#ifndef SPEEX_VERSION
39#define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */ 39#define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */
40#define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */ 40#define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */
41#define SPEEX_MICRO_VERSION 13 /**< Micro Speex version. */ 41#define SPEEX_MICRO_VERSION 14 /**< Micro Speex version. */
42#define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */ 42#define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */
43#define SPEEX_VERSION "speex-1.2beta1" /**< Speex version string. */ 43#define SPEEX_VERSION "speex-1.2beta2" /**< Speex version string. */
44#endif 44#endif
45 45
46/* A couple test to catch stupid option combinations */ 46/* A couple test to catch stupid option combinations */
@@ -75,10 +75,21 @@
75void print_vec(float *vec, int len, char *name); 75void print_vec(float *vec, int len, char *name);
76#endif 76#endif
77 77
78/** Convert big endian */
79spx_uint32_t be_int(spx_uint32_t i);
80/** Convert little endian */ 78/** Convert little endian */
81spx_uint32_t le_int(spx_uint32_t i); 79static inline spx_int32_t le_int(spx_int32_t i)
80{
81#if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
82 spx_uint32_t ui, ret;
83 ui = i;
84 ret = ui>>24;
85 ret |= (ui>>8)&0x0000ff00;
86 ret |= (ui<<8)&0x00ff0000;
87 ret |= (ui<<24);
88 return ret;
89#else
90 return i;
91#endif
92}
82 93
83/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */ 94/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */
84void *speex_alloc (int size); 95void *speex_alloc (int size);
@@ -98,15 +109,18 @@ void speex_free_scratch (void *ptr);
98/** Speex wrapper for mem_move */ 109/** Speex wrapper for mem_move */
99void *speex_move (void *dest, void *src, int n); 110void *speex_move (void *dest, void *src, int n);
100 111
101/** Print error message to stderr */ 112/** Abort with an error message to stderr (internal Speex error) */
102void speex_error(const char *str); 113void speex_error(const char *str);
103 114
104/** Print warning message to stderr */ 115/** Print warning message to stderr (programming error) */
105void speex_warning(const char *str); 116void speex_warning(const char *str);
106 117
107/** Print warning message with integer argument to stderr */ 118/** Print warning message with integer argument to stderr */
108void speex_warning_int(const char *str, int val); 119void speex_warning_int(const char *str, int val);
109 120
121/** Print notification message to stderr */
122void speex_notify(const char *str);
123
110/** Generate a random number */ 124/** Generate a random number */
111spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed); 125spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed);
112 126
diff --git a/apps/codecs/libspeex/modes.c b/apps/codecs/libspeex/modes.c
index 652fcf9550..1d30ce4a15 100644
--- a/apps/codecs/libspeex/modes.c
+++ b/apps/codecs/libspeex/modes.c
@@ -662,7 +662,7 @@ const SpeexMode * speex_lib_get_mode (int mode)
662 if (mode == SPEEX_MODEID_NB_48K) return &speex_nb_48k_mode; 662 if (mode == SPEEX_MODEID_NB_48K) return &speex_nb_48k_mode;
663#endif 663#endif
664 664
665 if (mode < 0 || mode > SPEEX_NB_MODES) return NULL; 665 if (mode < 0 || mode >= SPEEX_NB_MODES) return NULL;
666 666
667 return speex_mode_list[mode]; 667 return speex_mode_list[mode];
668} 668}
diff --git a/apps/codecs/libspeex/modes.h b/apps/codecs/libspeex/modes.h
index 385cec007d..5bf1971c21 100644
--- a/apps/codecs/libspeex/modes.h
+++ b/apps/codecs/libspeex/modes.h
@@ -60,6 +60,9 @@
60/** Used internally*/ 60/** Used internally*/
61#define SPEEX_SET_WIDEBAND 105 61#define SPEEX_SET_WIDEBAND 105
62 62
63/** Used internally*/
64#define SPEEX_GET_STACK 106
65
63 66
64/** Quantizes LSPs */ 67/** Quantizes LSPs */
65typedef void (*lsp_quant_func)(spx_lsp_t *, spx_lsp_t *, int, SpeexBits *); 68typedef void (*lsp_quant_func)(spx_lsp_t *, spx_lsp_t *, int, SpeexBits *);
diff --git a/apps/codecs/libspeex/nb_celp.c b/apps/codecs/libspeex/nb_celp.c
index 85e4ca015e..e41ad6e703 100644
--- a/apps/codecs/libspeex/nb_celp.c
+++ b/apps/codecs/libspeex/nb_celp.c
@@ -1257,7 +1257,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1257 speex_mode_query(&speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &advance); 1257 speex_mode_query(&speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &advance);
1258 if (advance < 0) 1258 if (advance < 0)
1259 { 1259 {
1260 speex_warning ("Invalid wideband mode encountered. Corrupted stream?"); 1260 speex_notify("Invalid mode encountered. The stream is corrupted.");
1261 return -2; 1261 return -2;
1262 } 1262 }
1263 advance -= (SB_SUBMODE_BITS+1); 1263 advance -= (SB_SUBMODE_BITS+1);
@@ -1272,7 +1272,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1272 speex_mode_query(&speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &advance); 1272 speex_mode_query(&speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &advance);
1273 if (advance < 0) 1273 if (advance < 0)
1274 { 1274 {
1275 speex_warning ("Invalid wideband mode encountered: corrupted stream?"); 1275 speex_notify("Invalid mode encountered. The stream is corrupted.");
1276 return -2; 1276 return -2;
1277 } 1277 }
1278 advance -= (SB_SUBMODE_BITS+1); 1278 advance -= (SB_SUBMODE_BITS+1);
@@ -1280,7 +1280,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1280 wideband = speex_bits_unpack_unsigned(bits, 1); 1280 wideband = speex_bits_unpack_unsigned(bits, 1);
1281 if (wideband) 1281 if (wideband)
1282 { 1282 {
1283 speex_warning ("More than two wideband layers found: corrupted stream?"); 1283 speex_notify("More than two wideband layers found. The stream is corrupted.");
1284 return -2; 1284 return -2;
1285 } 1285 }
1286 1286
@@ -1305,7 +1305,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1305 return ret; 1305 return ret;
1306 } else if (m>8) /* Invalid mode */ 1306 } else if (m>8) /* Invalid mode */
1307 { 1307 {
1308 speex_warning("Invalid mode encountered: corrupted stream?"); 1308 speex_notify("Invalid mode encountered. The stream is corrupted.");
1309 return -2; 1309 return -2;
1310 } 1310 }
1311 1311
@@ -1526,7 +1526,11 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1526#ifdef EPIC_48K 1526#ifdef EPIC_48K
1527 } 1527 }
1528#endif 1528#endif
1529 1529 /* Ensuring that things aren't blowing up as would happen if e.g. an encoder is
1530 crafting packets to make us produce NaNs and slow down the decoder (vague DoS threat).
1531 We can probably be even more aggressive and limit to 15000 or so. */
1532 sanitize_values32(exc32, NEG32(QCONST32(32000,SIG_SHIFT-1)), QCONST32(32000,SIG_SHIFT-1), st->subframeSize);
1533
1530 tmp = gain_3tap_to_1tap(pitch_gain); 1534 tmp = gain_3tap_to_1tap(pitch_gain);
1531 1535
1532 pitch_average += tmp; 1536 pitch_average += tmp;
@@ -1698,7 +1702,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1698 for (i=0;i<st->lpcSize;i+=2) 1702 for (i=0;i<st->lpcSize;i+=2)
1699 { 1703 {
1700 /*pi_g += -st->interp_qlpc[i] + st->interp_qlpc[i+1];*/ 1704 /*pi_g += -st->interp_qlpc[i] + st->interp_qlpc[i+1];*/
1701 pi_g = ADD32(pi_g, SUB32(EXTEND32(st->interp_qlpc[i+1]),EXTEND32(st->interp_qlpc[i]))); 1705 pi_g = ADD32(pi_g, SUB32(EXTEND32(ak[i+1]),EXTEND32(ak[i])));
1702 } 1706 }
1703 st->pi_gain[sub] = pi_g; 1707 st->pi_gain[sub] = pi_g;
1704 } 1708 }
@@ -1716,6 +1720,14 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
1716 /*for (i=0;i<st->frameSize;i++) 1720 /*for (i=0;i<st->frameSize;i++)
1717 printf ("%d\n", (int)st->frame[i]);*/ 1721 printf ("%d\n", (int)st->frame[i]);*/
1718 1722
1723 /* Tracking output level */
1724 st->level = 1+PSHR32(ol_gain,SIG_SHIFT);
1725 st->max_level = MAX16(MULT16_16_Q15(QCONST16(.99f,15), st->max_level), st->level);
1726 st->min_level = MIN16(ADD16(1,MULT16_16_Q14(QCONST16(1.01f,14), st->min_level)), st->level);
1727 if (st->max_level < st->min_level+1)
1728 st->max_level = st->min_level+1;
1729 /*printf ("%f %f %f %d\n", og, st->min_level, st->max_level, update);*/
1730
1719 /* Store the LSPs for interpolation in the next frame */ 1731 /* Store the LSPs for interpolation in the next frame */
1720 for (i=0;i<st->lpcSize;i++) 1732 for (i=0;i<st->lpcSize;i++)
1721 st->old_qlsp[i] = qlsp[i]; 1733 st->old_qlsp[i] = qlsp[i];
@@ -1924,6 +1936,9 @@ int nb_encoder_ctl(void *state, int request, void *ptr)
1924 case SPEEX_SET_WIDEBAND: 1936 case SPEEX_SET_WIDEBAND:
1925 st->isWideband = *((spx_int32_t*)ptr); 1937 st->isWideband = *((spx_int32_t*)ptr);
1926 break; 1938 break;
1939 case SPEEX_GET_STACK:
1940 *((char**)ptr) = st->stack;
1941 break;
1927 default: 1942 default:
1928 speex_warning_int("Unknown nb_ctl request: ", request); 1943 speex_warning_int("Unknown nb_ctl request: ", request);
1929 return -1; 1944 return -1;
@@ -2006,7 +2021,19 @@ int nb_decoder_ctl(void *state, int request, void *ptr)
2006 case SPEEX_GET_HIGHPASS: 2021 case SPEEX_GET_HIGHPASS:
2007 (*(spx_int32_t*)ptr) = st->highpass_enabled; 2022 (*(spx_int32_t*)ptr) = st->highpass_enabled;
2008 break; 2023 break;
2009 2024 case SPEEX_GET_ACTIVITY:
2025 {
2026 float ret;
2027 ret = log(st->level/st->min_level)/log(st->max_level/st->min_level);
2028 if (ret>1)
2029 ret = 1;
2030 /* Done in a strange way to catch NaNs as well */
2031 if (!(ret > 0))
2032 ret = 0;
2033 /*printf ("%f %f %f %f\n", st->level, st->min_level, st->max_level, ret);*/
2034 (*(spx_int32_t*)ptr) = (int)(100*ret);
2035 }
2036 break;
2010 case SPEEX_GET_PI_GAIN: 2037 case SPEEX_GET_PI_GAIN:
2011 { 2038 {
2012 int i; 2039 int i;
@@ -2031,6 +2058,9 @@ int nb_decoder_ctl(void *state, int request, void *ptr)
2031 case SPEEX_SET_WIDEBAND: 2058 case SPEEX_SET_WIDEBAND:
2032 st->isWideband = *((spx_int32_t*)ptr); 2059 st->isWideband = *((spx_int32_t*)ptr);
2033 break; 2060 break;
2061 case SPEEX_GET_STACK:
2062 *((char**)ptr) = st->stack;
2063 break;
2034 default: 2064 default:
2035 speex_warning_int("Unknown nb_ctl request: ", request); 2065 speex_warning_int("Unknown nb_ctl request: ", request);
2036 return -1; 2066 return -1;
diff --git a/apps/codecs/libspeex/nb_celp.h b/apps/codecs/libspeex/nb_celp.h
index 1ebf71754c..cc91b1c4fe 100644
--- a/apps/codecs/libspeex/nb_celp.h
+++ b/apps/codecs/libspeex/nb_celp.h
@@ -148,7 +148,11 @@ typedef struct DecState {
148 spx_mem_t *mem_sp; /**< Filter memory for synthesis signal */ 148 spx_mem_t *mem_sp; /**< Filter memory for synthesis signal */
149 spx_mem_t mem_hp[2]; /**< High-pass filter memory */ 149 spx_mem_t mem_hp[2]; /**< High-pass filter memory */
150 spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */ 150 spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */
151 spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ 151 spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */
152
153 spx_word16_t level;
154 spx_word16_t max_level;
155 spx_word16_t min_level;
152 156
153 /* This is used in packet loss concealment */ 157 /* This is used in packet loss concealment */
154 int last_pitch; /**< Pitch of last correctly decoded frame */ 158 int last_pitch; /**< Pitch of last correctly decoded frame */
diff --git a/apps/codecs/libspeex/preprocess.c b/apps/codecs/libspeex/preprocess.c
index d030d3fcb2..7e7f106b55 100644
--- a/apps/codecs/libspeex/preprocess.c
+++ b/apps/codecs/libspeex/preprocess.c
@@ -229,6 +229,7 @@ struct SpeexPreprocessState_ {
229#ifndef FIXED_POINT 229#ifndef FIXED_POINT
230 int agc_enabled; 230 int agc_enabled;
231 float agc_level; 231 float agc_level;
232 float loudness_accum;
232 float *loudness_weight; /**< Perceptual loudness curve */ 233 float *loudness_weight; /**< Perceptual loudness curve */
233 float loudness; /**< Loudness estimate */ 234 float loudness; /**< Loudness estimate */
234 float agc_gain; /**< Current AGC gain */ 235 float agc_gain; /**< Current AGC gain */
@@ -509,12 +510,13 @@ SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_r
509 st->loudness_weight[i]=.01f; 510 st->loudness_weight[i]=.01f;
510 st->loudness_weight[i] *= st->loudness_weight[i]; 511 st->loudness_weight[i] *= st->loudness_weight[i];
511 } 512 }
512 st->loudness = pow(AMP_SCALE*st->agc_level,LOUDNESS_EXP); 513 /*st->loudness = pow(AMP_SCALE*st->agc_level,LOUDNESS_EXP);*/
514 st->loudness = 1e-15;
513 st->agc_gain = 1; 515 st->agc_gain = 1;
514 st->nb_loudness_adapt = 0; 516 st->nb_loudness_adapt = 0;
515 st->max_gain = 10; 517 st->max_gain = 30;
516 st->max_increase_step = exp(0.11513f * 6.*st->frame_size / st->sampling_rate); 518 st->max_increase_step = exp(0.11513f * 12.*st->frame_size / st->sampling_rate);
517 st->max_decrease_step = exp(-0.11513f * 30.*st->frame_size / st->sampling_rate); 519 st->max_decrease_step = exp(-0.11513f * 40.*st->frame_size / st->sampling_rate);
518 st->prev_loudness = 1; 520 st->prev_loudness = 1;
519 st->init_max = 1; 521 st->init_max = 1;
520#endif 522#endif
@@ -578,17 +580,19 @@ static void speex_compute_agc(SpeexPreprocessState *st, spx_word16_t Pframe, spx
578 loudness=sqrt(loudness); 580 loudness=sqrt(loudness);
579 /*if (loudness < 2*pow(st->loudness, 1.0/LOUDNESS_EXP) && 581 /*if (loudness < 2*pow(st->loudness, 1.0/LOUDNESS_EXP) &&
580 loudness*2 > pow(st->loudness, 1.0/LOUDNESS_EXP))*/ 582 loudness*2 > pow(st->loudness, 1.0/LOUDNESS_EXP))*/
581 if (Pframe>.5f) 583 if (Pframe>.3f)
582 { 584 {
583 st->nb_loudness_adapt++; 585 st->nb_loudness_adapt++;
584 rate=2.0f*Pframe*Pframe/(1+st->nb_loudness_adapt); 586 /*rate=2.0f*Pframe*Pframe/(1+st->nb_loudness_adapt);*/
587 rate = .03*Pframe*Pframe;
585 st->loudness = (1-rate)*st->loudness + (rate)*pow(AMP_SCALE*loudness, LOUDNESS_EXP); 588 st->loudness = (1-rate)*st->loudness + (rate)*pow(AMP_SCALE*loudness, LOUDNESS_EXP);
589 st->loudness_accum = (1-rate)*st->loudness_accum + rate;
586 if (st->init_max < st->max_gain && st->nb_adapt > 20) 590 if (st->init_max < st->max_gain && st->nb_adapt > 20)
587 st->init_max *= 1.f + .05f*Pframe*Pframe; 591 st->init_max *= 1.f + .1f*Pframe*Pframe;
588 } 592 }
589 /*printf ("%f %f %f %f\n", Pframe, loudness, pow(st->loudness, 1.0f/LOUDNESS_EXP), st->loudness2);*/ 593 /*printf ("%f %f %f %f\n", Pframe, loudness, pow(st->loudness, 1.0f/LOUDNESS_EXP), st->loudness2);*/
590 594
591 target_gain = AMP_SCALE*st->agc_level*pow(st->loudness, -1.0f/LOUDNESS_EXP); 595 target_gain = AMP_SCALE*st->agc_level*pow(st->loudness/(1e-4+st->loudness_accum), -1.0f/LOUDNESS_EXP);
592 596
593 if ((Pframe>.5 && st->nb_adapt > 20) || target_gain < st->agc_gain) 597 if ((Pframe>.5 && st->nb_adapt > 20) || target_gain < st->agc_gain)
594 { 598 {
@@ -603,7 +607,7 @@ static void speex_compute_agc(SpeexPreprocessState *st, spx_word16_t Pframe, spx
603 607
604 st->agc_gain = target_gain; 608 st->agc_gain = target_gain;
605 } 609 }
606 /*printf ("%f %f %f\n", loudness, (float)AMP_SCALE_1*pow(st->loudness, 1.0f/LOUDNESS_EXP), st->agc_gain);*/ 610 /*fprintf (stderr, "%f %f %f\n", loudness, (float)AMP_SCALE_1*pow(st->loudness, 1.0f/LOUDNESS_EXP), st->agc_gain);*/
607 611
608 for (i=0;i<2*N;i++) 612 for (i=0;i<2*N;i++)
609 ft[i] *= st->agc_gain; 613 ft[i] *= st->agc_gain;
diff --git a/apps/codecs/libspeex/resample.c b/apps/codecs/libspeex/resample.c
index 22ed21c64a..2dfe2dd5f3 100644
--- a/apps/codecs/libspeex/resample.c
+++ b/apps/codecs/libspeex/resample.c
@@ -56,14 +56,16 @@ TODO list:
56 56
57#ifdef OUTSIDE_SPEEX 57#ifdef OUTSIDE_SPEEX
58#include <stdlib.h> 58#include <stdlib.h>
59void *speex_alloc (int size) {return calloc(size,1);} 59static void *speex_alloc (int size) {return calloc(size,1);}
60void *speex_realloc (void *ptr, int size) {return realloc(ptr, size);} 60static void *speex_realloc (void *ptr, int size) {return realloc(ptr, size);}
61void speex_free (void *ptr) {free(ptr);} 61static void speex_free (void *ptr) {free(ptr);}
62#include "speex_resampler.h" 62#include "speex_resampler.h"
63#else 63#include "arch.h"
64#else /* OUTSIDE_SPEEX */
65
64#include "speex/speex_resampler.h" 66#include "speex/speex_resampler.h"
65#include "misc.h" 67#include "misc.h"
66#endif 68#endif /* OUTSIDE_SPEEX */
67 69
68#include <math.h> 70#include <math.h>
69 71
@@ -83,34 +85,37 @@ void speex_free (void *ptr) {free(ptr);}
83 85
84#define IMAX(a,b) ((a) > (b) ? (a) : (b)) 86#define IMAX(a,b) ((a) > (b) ? (a) : (b))
85 87
88#ifndef NULL
89#define NULL 0
90#endif
86 91
87typedef int (*resampler_basic_func)(SpeexResamplerState *, int , const spx_word16_t *, int *, spx_word16_t *, int *); 92typedef int (*resampler_basic_func)(SpeexResamplerState *, spx_uint32_t , const spx_word16_t *, spx_uint32_t *, spx_word16_t *, spx_uint32_t *);
88 93
89struct SpeexResamplerState_ { 94struct SpeexResamplerState_ {
90 int in_rate; 95 spx_uint32_t in_rate;
91 int out_rate; 96 spx_uint32_t out_rate;
92 int num_rate; 97 spx_uint32_t num_rate;
93 int den_rate; 98 spx_uint32_t den_rate;
94 99
95 int quality; 100 int quality;
96 int nb_channels; 101 spx_uint32_t nb_channels;
97 int filt_len; 102 spx_uint32_t filt_len;
98 int mem_alloc_size; 103 spx_uint32_t mem_alloc_size;
99 int int_advance; 104 int int_advance;
100 int frac_advance; 105 int frac_advance;
101 float cutoff; 106 float cutoff;
102 int oversample; 107 spx_uint32_t oversample;
103 int initialised; 108 int initialised;
104 int started; 109 int started;
105 110
106 /* These are per-channel */ 111 /* These are per-channel */
107 int *last_sample; 112 spx_int32_t *last_sample;
108 int *samp_frac_num; 113 spx_uint32_t *samp_frac_num;
109 int *magic_samples; 114 spx_uint32_t *magic_samples;
110 115
111 spx_word16_t *mem; 116 spx_word16_t *mem;
112 spx_word16_t *sinc_table; 117 spx_word16_t *sinc_table;
113 int sinc_table_length; 118 spx_uint32_t sinc_table_length;
114 resampler_basic_func resampler_ptr; 119 resampler_basic_func resampler_ptr;
115 120
116 int in_stride; 121 int in_stride;
@@ -203,12 +208,12 @@ static const struct QualityMapping quality_map[11] = {
203 { 32, 4, 0.882f, 0.910f, KAISER6 }, /* Q2 */ /* 82.3% cutoff ( ~60 dB stop) 6 */ 208 { 32, 4, 0.882f, 0.910f, KAISER6 }, /* Q2 */ /* 82.3% cutoff ( ~60 dB stop) 6 */
204 { 48, 8, 0.895f, 0.917f, KAISER8 }, /* Q3 */ /* 84.9% cutoff ( ~80 dB stop) 8 */ 209 { 48, 8, 0.895f, 0.917f, KAISER8 }, /* Q3 */ /* 84.9% cutoff ( ~80 dB stop) 8 */
205 { 64, 8, 0.921f, 0.940f, KAISER8 }, /* Q4 */ /* 88.7% cutoff ( ~80 dB stop) 8 */ 210 { 64, 8, 0.921f, 0.940f, KAISER8 }, /* Q4 */ /* 88.7% cutoff ( ~80 dB stop) 8 */
206 { 80, 8, 0.922f, 0.940f, KAISER10}, /* Q5 */ /* 89.1% cutoff (~100 dB stop) 10 */ 211 { 80, 16, 0.922f, 0.940f, KAISER10}, /* Q5 */ /* 89.1% cutoff (~100 dB stop) 10 */
207 { 96, 8, 0.940f, 0.945f, KAISER10}, /* Q6 */ /* 91.5% cutoff (~100 dB stop) 10 */ 212 { 96, 16, 0.940f, 0.945f, KAISER10}, /* Q6 */ /* 91.5% cutoff (~100 dB stop) 10 */
208 {128, 16, 0.950f, 0.950f, KAISER10}, /* Q7 */ /* 93.1% cutoff (~100 dB stop) 10 */ 213 {128, 16, 0.950f, 0.950f, KAISER10}, /* Q7 */ /* 93.1% cutoff (~100 dB stop) 10 */
209 {160, 16, 0.960f, 0.960f, KAISER10}, /* Q8 */ /* 94.5% cutoff (~100 dB stop) 10 */ 214 {160, 16, 0.960f, 0.960f, KAISER10}, /* Q8 */ /* 94.5% cutoff (~100 dB stop) 10 */
210 {192, 16, 0.968f, 0.968f, KAISER12}, /* Q9 */ /* 95.5% cutoff (~100 dB stop) 10 */ 215 {192, 32, 0.968f, 0.968f, KAISER12}, /* Q9 */ /* 95.5% cutoff (~100 dB stop) 10 */
211 {256, 16, 0.975f, 0.975f, KAISER12}, /* Q10 */ /* 96.6% cutoff (~100 dB stop) 10 */ 216 {256, 32, 0.975f, 0.975f, KAISER12}, /* Q10 */ /* 96.6% cutoff (~100 dB stop) 10 */
212}; 217};
213/*8,24,40,56,80,104,128,160,200,256,320*/ 218/*8,24,40,56,80,104,128,160,200,256,320*/
214static double compute_func(float x, struct FuncDef *func) 219static double compute_func(float x, struct FuncDef *func)
@@ -302,15 +307,15 @@ static void cubic_coef(spx_word16_t frac, spx_word16_t interp[4])
302} 307}
303#endif 308#endif
304 309
305static int resampler_basic_direct_single(SpeexResamplerState *st, int channel_index, const spx_word16_t *in, int *in_len, spx_word16_t *out, int *out_len) 310static int resampler_basic_direct_single(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
306{ 311{
307 int N = st->filt_len; 312 int N = st->filt_len;
308 int out_sample = 0; 313 int out_sample = 0;
309 spx_word16_t *mem; 314 spx_word16_t *mem;
310 int last_sample = st->last_sample[channel_index]; 315 int last_sample = st->last_sample[channel_index];
311 int samp_frac_num = st->samp_frac_num[channel_index]; 316 spx_uint32_t samp_frac_num = st->samp_frac_num[channel_index];
312 mem = st->mem + channel_index * st->mem_alloc_size; 317 mem = st->mem + channel_index * st->mem_alloc_size;
313 while (!(last_sample >= *in_len || out_sample >= *out_len)) 318 while (!(last_sample >= (spx_int32_t)*in_len || out_sample >= (spx_int32_t)*out_len))
314 { 319 {
315 int j; 320 int j;
316 spx_word32_t sum=0; 321 spx_word32_t sum=0;
@@ -350,15 +355,15 @@ static int resampler_basic_direct_single(SpeexResamplerState *st, int channel_in
350#ifdef FIXED_POINT 355#ifdef FIXED_POINT
351#else 356#else
352/* This is the same as the previous function, except with a double-precision accumulator */ 357/* This is the same as the previous function, except with a double-precision accumulator */
353static int resampler_basic_direct_double(SpeexResamplerState *st, int channel_index, const spx_word16_t *in, int *in_len, spx_word16_t *out, int *out_len) 358static int resampler_basic_direct_double(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
354{ 359{
355 int N = st->filt_len; 360 int N = st->filt_len;
356 int out_sample = 0; 361 int out_sample = 0;
357 spx_word16_t *mem; 362 spx_word16_t *mem;
358 int last_sample = st->last_sample[channel_index]; 363 int last_sample = st->last_sample[channel_index];
359 int samp_frac_num = st->samp_frac_num[channel_index]; 364 spx_uint32_t samp_frac_num = st->samp_frac_num[channel_index];
360 mem = st->mem + channel_index * st->mem_alloc_size; 365 mem = st->mem + channel_index * st->mem_alloc_size;
361 while (!(last_sample >= *in_len || out_sample >= *out_len)) 366 while (!(last_sample >= (spx_int32_t)*in_len || out_sample >= (spx_int32_t)*out_len))
362 { 367 {
363 int j; 368 int j;
364 double sum=0; 369 double sum=0;
@@ -396,15 +401,15 @@ static int resampler_basic_direct_double(SpeexResamplerState *st, int channel_in
396} 401}
397#endif 402#endif
398 403
399static int resampler_basic_interpolate_single(SpeexResamplerState *st, int channel_index, const spx_word16_t *in, int *in_len, spx_word16_t *out, int *out_len) 404static int resampler_basic_interpolate_single(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
400{ 405{
401 int N = st->filt_len; 406 int N = st->filt_len;
402 int out_sample = 0; 407 int out_sample = 0;
403 spx_word16_t *mem; 408 spx_word16_t *mem;
404 int last_sample = st->last_sample[channel_index]; 409 int last_sample = st->last_sample[channel_index];
405 int samp_frac_num = st->samp_frac_num[channel_index]; 410 spx_uint32_t samp_frac_num = st->samp_frac_num[channel_index];
406 mem = st->mem + channel_index * st->mem_alloc_size; 411 mem = st->mem + channel_index * st->mem_alloc_size;
407 while (!(last_sample >= *in_len || out_sample >= *out_len)) 412 while (!(last_sample >= (spx_int32_t)*in_len || out_sample >= (spx_int32_t)*out_len))
408 { 413 {
409 int j; 414 int j;
410 spx_word32_t sum=0; 415 spx_word32_t sum=0;
@@ -465,15 +470,15 @@ static int resampler_basic_interpolate_single(SpeexResamplerState *st, int chann
465#ifdef FIXED_POINT 470#ifdef FIXED_POINT
466#else 471#else
467/* This is the same as the previous function, except with a double-precision accumulator */ 472/* This is the same as the previous function, except with a double-precision accumulator */
468static int resampler_basic_interpolate_double(SpeexResamplerState *st, int channel_index, const spx_word16_t *in, int *in_len, spx_word16_t *out, int *out_len) 473static int resampler_basic_interpolate_double(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
469{ 474{
470 int N = st->filt_len; 475 int N = st->filt_len;
471 int out_sample = 0; 476 int out_sample = 0;
472 spx_word16_t *mem; 477 spx_word16_t *mem;
473 int last_sample = st->last_sample[channel_index]; 478 int last_sample = st->last_sample[channel_index];
474 int samp_frac_num = st->samp_frac_num[channel_index]; 479 spx_uint32_t samp_frac_num = st->samp_frac_num[channel_index];
475 mem = st->mem + channel_index * st->mem_alloc_size; 480 mem = st->mem + channel_index * st->mem_alloc_size;
476 while (!(last_sample >= *in_len || out_sample >= *out_len)) 481 while (!(last_sample >= (spx_int32_t)*in_len || out_sample >= (spx_int32_t)*out_len))
477 { 482 {
478 int j; 483 int j;
479 spx_word32_t sum=0; 484 spx_word32_t sum=0;
@@ -529,8 +534,7 @@ static int resampler_basic_interpolate_double(SpeexResamplerState *st, int chann
529 534
530static void update_filter(SpeexResamplerState *st) 535static void update_filter(SpeexResamplerState *st)
531{ 536{
532 int i; 537 spx_uint32_t old_length;
533 int old_length;
534 538
535 old_length = st->filt_len; 539 old_length = st->filt_len;
536 st->oversample = quality_map[st->quality].oversample; 540 st->oversample = quality_map[st->quality].oversample;
@@ -544,6 +548,16 @@ static void update_filter(SpeexResamplerState *st)
544 st->filt_len = st->filt_len*st->num_rate / st->den_rate; 548 st->filt_len = st->filt_len*st->num_rate / st->den_rate;
545 /* Round down to make sure we have a multiple of 4 */ 549 /* Round down to make sure we have a multiple of 4 */
546 st->filt_len &= (~0x3); 550 st->filt_len &= (~0x3);
551 if (2*st->den_rate < st->num_rate)
552 st->oversample >>= 1;
553 if (4*st->den_rate < st->num_rate)
554 st->oversample >>= 1;
555 if (8*st->den_rate < st->num_rate)
556 st->oversample >>= 1;
557 if (16*st->den_rate < st->num_rate)
558 st->oversample >>= 1;
559 if (st->oversample < 1)
560 st->oversample = 1;
547 } else { 561 } else {
548 /* up-sampling */ 562 /* up-sampling */
549 st->cutoff = quality_map[st->quality].upsample_bandwidth; 563 st->cutoff = quality_map[st->quality].upsample_bandwidth;
@@ -552,6 +566,7 @@ static void update_filter(SpeexResamplerState *st)
552 /* Choose the resampling type that requires the least amount of memory */ 566 /* Choose the resampling type that requires the least amount of memory */
553 if (st->den_rate <= st->oversample) 567 if (st->den_rate <= st->oversample)
554 { 568 {
569 spx_uint32_t i;
555 if (!st->sinc_table) 570 if (!st->sinc_table)
556 st->sinc_table = (spx_word16_t *)speex_alloc(st->filt_len*st->den_rate*sizeof(spx_word16_t)); 571 st->sinc_table = (spx_word16_t *)speex_alloc(st->filt_len*st->den_rate*sizeof(spx_word16_t));
557 else if (st->sinc_table_length < st->filt_len*st->den_rate) 572 else if (st->sinc_table_length < st->filt_len*st->den_rate)
@@ -561,7 +576,7 @@ static void update_filter(SpeexResamplerState *st)
561 } 576 }
562 for (i=0;i<st->den_rate;i++) 577 for (i=0;i<st->den_rate;i++)
563 { 578 {
564 int j; 579 spx_uint32_t j;
565 for (j=0;j<st->filt_len;j++) 580 for (j=0;j<st->filt_len;j++)
566 { 581 {
567 st->sinc_table[i*st->filt_len+j] = sinc(st->cutoff,((j-st->filt_len/2+1)-((float)i)/st->den_rate), st->filt_len, quality_map[st->quality].window_func); 582 st->sinc_table[i*st->filt_len+j] = sinc(st->cutoff,((j-st->filt_len/2+1)-((float)i)/st->den_rate), st->filt_len, quality_map[st->quality].window_func);
@@ -577,6 +592,7 @@ static void update_filter(SpeexResamplerState *st)
577#endif 592#endif
578 /*fprintf (stderr, "resampler uses direct sinc table and normalised cutoff %f\n", cutoff);*/ 593 /*fprintf (stderr, "resampler uses direct sinc table and normalised cutoff %f\n", cutoff);*/
579 } else { 594 } else {
595 spx_int32_t i;
580 if (!st->sinc_table) 596 if (!st->sinc_table)
581 st->sinc_table = (spx_word16_t *)speex_alloc((st->filt_len*st->oversample+8)*sizeof(spx_word16_t)); 597 st->sinc_table = (spx_word16_t *)speex_alloc((st->filt_len*st->oversample+8)*sizeof(spx_word16_t));
582 else if (st->sinc_table_length < st->filt_len*st->oversample+8) 598 else if (st->sinc_table_length < st->filt_len*st->oversample+8)
@@ -584,7 +600,7 @@ static void update_filter(SpeexResamplerState *st)
584 st->sinc_table = (spx_word16_t *)speex_realloc(st->sinc_table,(st->filt_len*st->oversample+8)*sizeof(spx_word16_t)); 600 st->sinc_table = (spx_word16_t *)speex_realloc(st->sinc_table,(st->filt_len*st->oversample+8)*sizeof(spx_word16_t));
585 st->sinc_table_length = st->filt_len*st->oversample+8; 601 st->sinc_table_length = st->filt_len*st->oversample+8;
586 } 602 }
587 for (i=-4;i<st->oversample*st->filt_len+4;i++) 603 for (i=-4;i<(spx_int32_t)(st->oversample*st->filt_len+4);i++)
588 st->sinc_table[i+4] = sinc(st->cutoff,(i/(float)st->oversample - st->filt_len/2), st->filt_len, quality_map[st->quality].window_func); 604 st->sinc_table[i+4] = sinc(st->cutoff,(i/(float)st->oversample - st->filt_len/2), st->filt_len, quality_map[st->quality].window_func);
589#ifdef FIXED_POINT 605#ifdef FIXED_POINT
590 st->resampler_ptr = resampler_basic_interpolate_single; 606 st->resampler_ptr = resampler_basic_interpolate_single;
@@ -599,8 +615,13 @@ static void update_filter(SpeexResamplerState *st)
599 st->int_advance = st->num_rate/st->den_rate; 615 st->int_advance = st->num_rate/st->den_rate;
600 st->frac_advance = st->num_rate%st->den_rate; 616 st->frac_advance = st->num_rate%st->den_rate;
601 617
618
619 /* Here's the place where we update the filter memory to take into account
620 the change in filter length. It's probably the messiest part of the code
621 due to handling of lots of corner cases. */
602 if (!st->mem) 622 if (!st->mem)
603 { 623 {
624 spx_uint32_t i;
604 st->mem = (spx_word16_t*)speex_alloc(st->nb_channels*(st->filt_len-1) * sizeof(spx_word16_t)); 625 st->mem = (spx_word16_t*)speex_alloc(st->nb_channels*(st->filt_len-1) * sizeof(spx_word16_t));
605 for (i=0;i<st->nb_channels*(st->filt_len-1);i++) 626 for (i=0;i<st->nb_channels*(st->filt_len-1);i++)
606 st->mem[i] = 0; 627 st->mem[i] = 0;
@@ -608,6 +629,7 @@ static void update_filter(SpeexResamplerState *st)
608 /*speex_warning("init filter");*/ 629 /*speex_warning("init filter");*/
609 } else if (!st->started) 630 } else if (!st->started)
610 { 631 {
632 spx_uint32_t i;
611 st->mem = (spx_word16_t*)speex_realloc(st->mem, st->nb_channels*(st->filt_len-1) * sizeof(spx_word16_t)); 633 st->mem = (spx_word16_t*)speex_realloc(st->mem, st->nb_channels*(st->filt_len-1) * sizeof(spx_word16_t));
612 for (i=0;i<st->nb_channels*(st->filt_len-1);i++) 634 for (i=0;i<st->nb_channels*(st->filt_len-1);i++)
613 st->mem[i] = 0; 635 st->mem[i] = 0;
@@ -615,6 +637,7 @@ static void update_filter(SpeexResamplerState *st)
615 /*speex_warning("reinit filter");*/ 637 /*speex_warning("reinit filter");*/
616 } else if (st->filt_len > old_length) 638 } else if (st->filt_len > old_length)
617 { 639 {
640 spx_int32_t i;
618 /* Increase the filter length */ 641 /* Increase the filter length */
619 /*speex_warning("increase filter size");*/ 642 /*speex_warning("increase filter size");*/
620 int old_alloc_size = st->mem_alloc_size; 643 int old_alloc_size = st->mem_alloc_size;
@@ -623,45 +646,76 @@ static void update_filter(SpeexResamplerState *st)
623 st->mem = (spx_word16_t*)speex_realloc(st->mem, st->nb_channels*(st->filt_len-1) * sizeof(spx_word16_t)); 646 st->mem = (spx_word16_t*)speex_realloc(st->mem, st->nb_channels*(st->filt_len-1) * sizeof(spx_word16_t));
624 st->mem_alloc_size = st->filt_len-1; 647 st->mem_alloc_size = st->filt_len-1;
625 } 648 }
626 for (i=0;i<st->nb_channels;i++) 649 for (i=st->nb_channels-1;i>=0;i--)
627 { 650 {
628 int j; 651 spx_int32_t j;
629 /* Copy data going backward */ 652 spx_uint32_t olen = old_length;
630 for (j=0;j<old_length-1;j++) 653 /*if (st->magic_samples[i])*/
631 st->mem[i*st->mem_alloc_size+(st->filt_len-2-j)] = st->mem[i*old_alloc_size+(old_length-2-j)]; 654 {
632 /* Then put zeros for lack of anything better */ 655 /* Try and remove the magic samples as if nothing had happened */
633 for (;j<st->filt_len-1;j++) 656
634 st->mem[i*st->mem_alloc_size+(st->filt_len-2-j)] = 0; 657 /* FIXME: This is wrong but for now we need it to avoid going over the array bounds */
635 /* Adjust last_sample */ 658 olen = old_length + 2*st->magic_samples[i];
636 st->last_sample[i] += (st->filt_len - old_length)/2; 659 for (j=old_length-2+st->magic_samples[i];j>=0;j--)
660 st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]] = st->mem[i*old_alloc_size+j];
661 for (j=0;j<st->magic_samples[i];j++)
662 st->mem[i*st->mem_alloc_size+j] = 0;
663 st->magic_samples[i] = 0;
664 }
665 if (st->filt_len > olen)
666 {
667 /* If the new filter length is still bigger than the "augmented" length */
668 /* Copy data going backward */
669 for (j=0;j<olen-1;j++)
670 st->mem[i*st->mem_alloc_size+(st->filt_len-2-j)] = st->mem[i*st->mem_alloc_size+(olen-2-j)];
671 /* Then put zeros for lack of anything better */
672 for (;j<st->filt_len-1;j++)
673 st->mem[i*st->mem_alloc_size+(st->filt_len-2-j)] = 0;
674 /* Adjust last_sample */
675 st->last_sample[i] += (st->filt_len - olen)/2;
676 } else {
677 /* Put back some of the magic! */
678 st->magic_samples[i] = (olen - st->filt_len)/2;
679 for (j=0;j<st->filt_len-1+st->magic_samples[i];j++)
680 st->mem[i*st->mem_alloc_size+j] = st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]];
681 }
637 } 682 }
638 } else if (st->filt_len < old_length) 683 } else if (st->filt_len < old_length)
639 { 684 {
640 /* Reduce filter length, this a bit tricky */ 685 spx_uint32_t i;
641 /*speex_warning("decrease filter size (unimplemented)");*/ 686 /* Reduce filter length, this a bit tricky. We need to store some of the memory as "magic"
642 /* Adjust last_sample (which will likely end up negative) */ 687 samples so they can be used directly as input the next time(s) */
643 /*st->last_sample += (st->filt_len - old_length)/2;*/
644 for (i=0;i<st->nb_channels;i++) 688 for (i=0;i<st->nb_channels;i++)
645 { 689 {
646 int j; 690 spx_uint32_t j;
691 spx_uint32_t old_magic = st->magic_samples[i];
647 st->magic_samples[i] = (old_length - st->filt_len)/2; 692 st->magic_samples[i] = (old_length - st->filt_len)/2;
693 /* We must copy some of the memory that's no longer used */
648 /* Copy data going backward */ 694 /* Copy data going backward */
649 for (j=0;j<st->filt_len-1+st->magic_samples[i];j++) 695 for (j=0;j<st->filt_len-1+st->magic_samples[i]+old_magic;j++)
650 st->mem[i*st->mem_alloc_size+j] = st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]]; 696 st->mem[i*st->mem_alloc_size+j] = st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]];
697 st->magic_samples[i] += old_magic;
651 } 698 }
652 } 699 }
653 700
654} 701}
655 702
656SpeexResamplerState *speex_resampler_init(int nb_channels, int in_rate, int out_rate, int quality) 703SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
657{ 704{
658 return speex_resampler_init_frac(nb_channels, in_rate, out_rate, in_rate, out_rate, quality); 705 return speex_resampler_init_frac(nb_channels, in_rate, out_rate, in_rate, out_rate, quality, err);
659} 706}
660 707
661SpeexResamplerState *speex_resampler_init_frac(int nb_channels, int ratio_num, int ratio_den, int in_rate, int out_rate, int quality) 708SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
662{ 709{
663 int i; 710 spx_uint32_t i;
664 SpeexResamplerState *st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState)); 711 SpeexResamplerState *st;
712 if (quality > 10 || quality < 0)
713 {
714 if (err)
715 *err = RESAMPLER_ERR_INVALID_ARG;
716 return NULL;
717 }
718 st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
665 st->initialised = 0; 719 st->initialised = 0;
666 st->started = 0; 720 st->started = 0;
667 st->in_rate = 0; 721 st->in_rate = 0;
@@ -681,9 +735,9 @@ SpeexResamplerState *speex_resampler_init_frac(int nb_channels, int ratio_num, i
681 st->out_stride = 1; 735 st->out_stride = 1;
682 736
683 /* Per channel data */ 737 /* Per channel data */
684 st->last_sample = (int*)speex_alloc(nb_channels*sizeof(int)); 738 st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(int));
685 st->magic_samples = (int*)speex_alloc(nb_channels*sizeof(int)); 739 st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(int));
686 st->samp_frac_num = (int*)speex_alloc(nb_channels*sizeof(int)); 740 st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(int));
687 for (i=0;i<nb_channels;i++) 741 for (i=0;i<nb_channels;i++)
688 { 742 {
689 st->last_sample[i] = 0; 743 st->last_sample[i] = 0;
@@ -698,6 +752,9 @@ SpeexResamplerState *speex_resampler_init_frac(int nb_channels, int ratio_num, i
698 update_filter(st); 752 update_filter(st);
699 753
700 st->initialised = 1; 754 st->initialised = 1;
755 if (err)
756 *err = RESAMPLER_ERR_SUCCESS;
757
701 return st; 758 return st;
702} 759}
703 760
@@ -713,62 +770,75 @@ void speex_resampler_destroy(SpeexResamplerState *st)
713 770
714 771
715 772
716static void speex_resampler_process_native(SpeexResamplerState *st, int channel_index, const spx_word16_t *in, int *in_len, spx_word16_t *out, int *out_len) 773static int speex_resampler_process_native(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
717{ 774{
718 int j=0; 775 int j=0;
719 int N = st->filt_len; 776 int N = st->filt_len;
720 int out_sample = 0; 777 int out_sample = 0;
721 spx_word16_t *mem; 778 spx_word16_t *mem;
722 int tmp_out_len = 0; 779 spx_uint32_t tmp_out_len = 0;
723 mem = st->mem + channel_index * st->mem_alloc_size; 780 mem = st->mem + channel_index * st->mem_alloc_size;
724 st->started = 1; 781 st->started = 1;
725 782
726 /* Handle the case where we have samples left from a reduction in filter length */ 783 /* Handle the case where we have samples left from a reduction in filter length */
727 if (st->magic_samples[channel_index]) 784 if (st->magic_samples[channel_index])
728 { 785 {
729 int tmp_in_len; 786 int istride_save;
730 int tmp_magic; 787 spx_uint32_t tmp_in_len;
788 spx_uint32_t tmp_magic;
789
790 istride_save = st->in_stride;
731 tmp_in_len = st->magic_samples[channel_index]; 791 tmp_in_len = st->magic_samples[channel_index];
732 tmp_out_len = *out_len; 792 tmp_out_len = *out_len;
733 /* FIXME: Need to handle the case where the out array is too small */
734 /* magic_samples needs to be set to zero to avoid infinite recursion */ 793 /* magic_samples needs to be set to zero to avoid infinite recursion */
735 tmp_magic = st->magic_samples[channel_index]; 794 tmp_magic = st->magic_samples[channel_index];
736 st->magic_samples[channel_index] = 0; 795 st->magic_samples[channel_index] = 0;
796 st->in_stride = 1;
737 speex_resampler_process_native(st, channel_index, mem+N-1, &tmp_in_len, out, &tmp_out_len); 797 speex_resampler_process_native(st, channel_index, mem+N-1, &tmp_in_len, out, &tmp_out_len);
798 st->in_stride = istride_save;
738 /*speex_warning_int("extra samples:", tmp_out_len);*/ 799 /*speex_warning_int("extra samples:", tmp_out_len);*/
739 /* If we couldn't process all "magic" input samples, save the rest for next time */ 800 /* If we couldn't process all "magic" input samples, save the rest for next time */
740 if (tmp_in_len < tmp_magic) 801 if (tmp_in_len < tmp_magic)
741 { 802 {
742 int i; 803 spx_uint32_t i;
743 st->magic_samples[channel_index] = tmp_magic-tmp_in_len; 804 st->magic_samples[channel_index] = tmp_magic-tmp_in_len;
744 for (i=0;i<st->magic_samples[channel_index];i++) 805 for (i=0;i<st->magic_samples[channel_index];i++)
745 mem[N-1+i]=mem[N-1+i+tmp_in_len]; 806 mem[N-1+i]=mem[N-1+i+tmp_in_len];
746 } 807 }
747 out += tmp_out_len; 808 out += tmp_out_len*st->out_stride;
809 *out_len -= tmp_out_len;
748 } 810 }
749 811
750 /* Call the right resampler through the function ptr */ 812 /* Call the right resampler through the function ptr */
751 out_sample = st->resampler_ptr(st, channel_index, in, in_len, out, out_len); 813 out_sample = st->resampler_ptr(st, channel_index, in, in_len, out, out_len);
752 814
753 if (st->last_sample[channel_index] < *in_len) 815 if (st->last_sample[channel_index] < (spx_int32_t)*in_len)
754 *in_len = st->last_sample[channel_index]; 816 *in_len = st->last_sample[channel_index];
755 *out_len = out_sample+tmp_out_len; 817 *out_len = out_sample+tmp_out_len;
756 st->last_sample[channel_index] -= *in_len; 818 st->last_sample[channel_index] -= *in_len;
757 819
758 for (j=0;j<N-1-*in_len;j++) 820 for (j=0;j<N-1-(spx_int32_t)*in_len;j++)
759 mem[j] = mem[j+*in_len]; 821 mem[j] = mem[j+*in_len];
760 for (;j<N-1;j++) 822 for (;j<N-1;j++)
761 mem[j] = in[st->in_stride*(j+*in_len-N+1)]; 823 mem[j] = in[st->in_stride*(j+*in_len-N+1)];
762 824
825 return RESAMPLER_ERR_SUCCESS;
763} 826}
764 827
828#define FIXED_STACK_ALLOC 1024
829
765#ifdef FIXED_POINT 830#ifdef FIXED_POINT
766void speex_resampler_process_float(SpeexResamplerState *st, int channel_index, const float *in, int *in_len, float *out, int *out_len) 831int speex_resampler_process_float(SpeexResamplerState *st, spx_uint32_t channel_index, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
767{ 832{
768 int i; 833 spx_uint32_t i;
769 int istride_save, ostride_save; 834 int istride_save, ostride_save;
835#ifdef VAR_ARRAYS
770 spx_word16_t x[*in_len]; 836 spx_word16_t x[*in_len];
771 spx_word16_t y[*out_len]; 837 spx_word16_t y[*out_len];
838 /*VARDECL(spx_word16_t *x);
839 VARDECL(spx_word16_t *y);
840 ALLOC(x, *in_len, spx_word16_t);
841 ALLOC(y, *out_len, spx_word16_t);*/
772 istride_save = st->in_stride; 842 istride_save = st->in_stride;
773 ostride_save = st->out_stride; 843 ostride_save = st->out_stride;
774 for (i=0;i<*in_len;i++) 844 for (i=0;i<*in_len;i++)
@@ -779,22 +849,59 @@ void speex_resampler_process_float(SpeexResamplerState *st, int channel_index, c
779 st->out_stride = ostride_save; 849 st->out_stride = ostride_save;
780 for (i=0;i<*out_len;i++) 850 for (i=0;i<*out_len;i++)
781 out[i*st->out_stride] = y[i]; 851 out[i*st->out_stride] = y[i];
852#else
853 spx_word16_t x[FIXED_STACK_ALLOC];
854 spx_word16_t y[FIXED_STACK_ALLOC];
855 spx_uint32_t ilen=*in_len, olen=*out_len;
856 istride_save = st->in_stride;
857 ostride_save = st->out_stride;
858 while (ilen && olen)
859 {
860 spx_uint32_t ichunk, ochunk;
861 ichunk = ilen;
862 ochunk = olen;
863 if (ichunk>FIXED_STACK_ALLOC)
864 ichunk=FIXED_STACK_ALLOC;
865 if (ochunk>FIXED_STACK_ALLOC)
866 ochunk=FIXED_STACK_ALLOC;
867 for (i=0;i<ichunk;i++)
868 x[i] = WORD2INT(in[i*st->in_stride]);
869 st->in_stride = st->out_stride = 1;
870 speex_resampler_process_native(st, channel_index, x, &ichunk, y, &ochunk);
871 st->in_stride = istride_save;
872 st->out_stride = ostride_save;
873 for (i=0;i<ochunk;i++)
874 out[i*st->out_stride] = y[i];
875 out += ochunk;
876 in += ichunk;
877 ilen -= ichunk;
878 olen -= ochunk;
879 }
880 *in_len -= ilen;
881 *out_len -= olen;
882#endif
883 return RESAMPLER_ERR_SUCCESS;
782} 884}
783void speex_resampler_process_int(SpeexResamplerState *st, int channel_index, const spx_int16_t *in, int *in_len, spx_int16_t *out, int *out_len) 885int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
784{ 886{
785 speex_resampler_process_native(st, channel_index, in, in_len, out, out_len); 887 return speex_resampler_process_native(st, channel_index, in, in_len, out, out_len);
786} 888}
787#else 889#else
788void speex_resampler_process_float(SpeexResamplerState *st, int channel_index, const float *in, int *in_len, float *out, int *out_len) 890int speex_resampler_process_float(SpeexResamplerState *st, spx_uint32_t channel_index, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
789{ 891{
790 speex_resampler_process_native(st, channel_index, in, in_len, out, out_len); 892 return speex_resampler_process_native(st, channel_index, in, in_len, out, out_len);
791} 893}
792void speex_resampler_process_int(SpeexResamplerState *st, int channel_index, const spx_int16_t *in, int *in_len, spx_int16_t *out, int *out_len) 894int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
793{ 895{
794 int i; 896 spx_uint32_t i;
795 int istride_save, ostride_save; 897 int istride_save, ostride_save;
898#ifdef VAR_ARRAYS
796 spx_word16_t x[*in_len]; 899 spx_word16_t x[*in_len];
797 spx_word16_t y[*out_len]; 900 spx_word16_t y[*out_len];
901 /*VARDECL(spx_word16_t *x);
902 VARDECL(spx_word16_t *y);
903 ALLOC(x, *in_len, spx_word16_t);
904 ALLOC(y, *out_len, spx_word16_t);*/
798 istride_save = st->in_stride; 905 istride_save = st->in_stride;
799 ostride_save = st->out_stride; 906 ostride_save = st->out_stride;
800 for (i=0;i<*in_len;i++) 907 for (i=0;i<*in_len;i++)
@@ -805,55 +912,94 @@ void speex_resampler_process_int(SpeexResamplerState *st, int channel_index, con
805 st->out_stride = ostride_save; 912 st->out_stride = ostride_save;
806 for (i=0;i<*out_len;i++) 913 for (i=0;i<*out_len;i++)
807 out[i*st->out_stride] = WORD2INT(y[i]); 914 out[i*st->out_stride] = WORD2INT(y[i]);
915#else
916 spx_word16_t x[FIXED_STACK_ALLOC];
917 spx_word16_t y[FIXED_STACK_ALLOC];
918 spx_uint32_t ilen=*in_len, olen=*out_len;
919 istride_save = st->in_stride;
920 ostride_save = st->out_stride;
921 while (ilen && olen)
922 {
923 spx_uint32_t ichunk, ochunk;
924 ichunk = ilen;
925 ochunk = olen;
926 if (ichunk>FIXED_STACK_ALLOC)
927 ichunk=FIXED_STACK_ALLOC;
928 if (ochunk>FIXED_STACK_ALLOC)
929 ochunk=FIXED_STACK_ALLOC;
930 for (i=0;i<ichunk;i++)
931 x[i] = in[i*st->in_stride];
932 st->in_stride = st->out_stride = 1;
933 speex_resampler_process_native(st, channel_index, x, &ichunk, y, &ochunk);
934 st->in_stride = istride_save;
935 st->out_stride = ostride_save;
936 for (i=0;i<ochunk;i++)
937 out[i*st->out_stride] = WORD2INT(y[i]);
938 out += ochunk;
939 in += ichunk;
940 ilen -= ichunk;
941 olen -= ochunk;
942 }
943 *in_len -= ilen;
944 *out_len -= olen;
945#endif
946 return RESAMPLER_ERR_SUCCESS;
808} 947}
809#endif 948#endif
810 949
811void speex_resampler_process_interleaved_float(SpeexResamplerState *st, const float *in, int *in_len, float *out, int *out_len) 950int speex_resampler_process_interleaved_float(SpeexResamplerState *st, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
812{ 951{
813 int i; 952 spx_uint32_t i;
814 int istride_save, ostride_save; 953 int istride_save, ostride_save;
954 spx_uint32_t bak_len = *out_len;
815 istride_save = st->in_stride; 955 istride_save = st->in_stride;
816 ostride_save = st->out_stride; 956 ostride_save = st->out_stride;
817 st->in_stride = st->out_stride = st->nb_channels; 957 st->in_stride = st->out_stride = st->nb_channels;
818 for (i=0;i<st->nb_channels;i++) 958 for (i=0;i<st->nb_channels;i++)
819 { 959 {
960 *out_len = bak_len;
820 speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len); 961 speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
821 } 962 }
822 st->in_stride = istride_save; 963 st->in_stride = istride_save;
823 st->out_stride = ostride_save; 964 st->out_stride = ostride_save;
965 return RESAMPLER_ERR_SUCCESS;
824} 966}
825 967
826void speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_int16_t *in, int *in_len, spx_int16_t *out, int *out_len) 968
969int 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)
827{ 970{
828 int i; 971 spx_uint32_t i;
829 int istride_save, ostride_save; 972 int istride_save, ostride_save;
973 spx_uint32_t bak_len = *out_len;
830 istride_save = st->in_stride; 974 istride_save = st->in_stride;
831 ostride_save = st->out_stride; 975 ostride_save = st->out_stride;
832 st->in_stride = st->out_stride = st->nb_channels; 976 st->in_stride = st->out_stride = st->nb_channels;
833 for (i=0;i<st->nb_channels;i++) 977 for (i=0;i<st->nb_channels;i++)
834 { 978 {
979 *out_len = bak_len;
835 speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len); 980 speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len);
836 } 981 }
837 st->in_stride = istride_save; 982 st->in_stride = istride_save;
838 st->out_stride = ostride_save; 983 st->out_stride = ostride_save;
984 return RESAMPLER_ERR_SUCCESS;
839} 985}
840 986
841void speex_resampler_set_rate(SpeexResamplerState *st, int in_rate, int out_rate) 987int speex_resampler_set_rate(SpeexResamplerState *st, spx_uint32_t in_rate, spx_uint32_t out_rate)
842{ 988{
843 speex_resampler_set_rate_frac(st, in_rate, out_rate, in_rate, out_rate); 989 return speex_resampler_set_rate_frac(st, in_rate, out_rate, in_rate, out_rate);
844} 990}
845 991
846void speex_resampler_get_rate(SpeexResamplerState *st, int *in_rate, int *out_rate) 992void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_rate, spx_uint32_t *out_rate)
847{ 993{
848 *in_rate = st->in_rate; 994 *in_rate = st->in_rate;
849 *out_rate = st->out_rate; 995 *out_rate = st->out_rate;
850} 996}
851 997
852void speex_resampler_set_rate_frac(SpeexResamplerState *st, int ratio_num, int ratio_den, int in_rate, int out_rate) 998int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate)
853{ 999{
854 int fact; 1000 int fact;
855 if (st->in_rate == in_rate && st->out_rate == out_rate && st->num_rate == ratio_num && st->den_rate == ratio_den) 1001 if (st->in_rate == in_rate && st->out_rate == out_rate && st->num_rate == ratio_num && st->den_rate == ratio_den)
856 return; 1002 return RESAMPLER_ERR_SUCCESS;
857 1003
858 st->in_rate = in_rate; 1004 st->in_rate = in_rate;
859 st->out_rate = out_rate; 1005 st->out_rate = out_rate;
@@ -871,25 +1017,25 @@ void speex_resampler_set_rate_frac(SpeexResamplerState *st, int ratio_num, int r
871 1017
872 if (st->initialised) 1018 if (st->initialised)
873 update_filter(st); 1019 update_filter(st);
1020 return RESAMPLER_ERR_SUCCESS;
874} 1021}
875 1022
876void speex_resampler_get_ratio(SpeexResamplerState *st, int *ratio_num, int *ratio_den) 1023void speex_resampler_get_ratio(SpeexResamplerState *st, spx_uint32_t *ratio_num, spx_uint32_t *ratio_den)
877{ 1024{
878 *ratio_num = st->num_rate; 1025 *ratio_num = st->num_rate;
879 *ratio_den = st->den_rate; 1026 *ratio_den = st->den_rate;
880} 1027}
881 1028
882void speex_resampler_set_quality(SpeexResamplerState *st, int quality) 1029int speex_resampler_set_quality(SpeexResamplerState *st, int quality)
883{ 1030{
884 if (quality < 0) 1031 if (quality > 10 || quality < 0)
885 quality = 0; 1032 return RESAMPLER_ERR_INVALID_ARG;
886 if (quality > 10)
887 quality = 10;
888 if (st->quality == quality) 1033 if (st->quality == quality)
889 return; 1034 return RESAMPLER_ERR_SUCCESS;
890 st->quality = quality; 1035 st->quality = quality;
891 if (st->initialised) 1036 if (st->initialised)
892 update_filter(st); 1037 update_filter(st);
1038 return RESAMPLER_ERR_SUCCESS;
893} 1039}
894 1040
895void speex_resampler_get_quality(SpeexResamplerState *st, int *quality) 1041void speex_resampler_get_quality(SpeexResamplerState *st, int *quality)
@@ -897,37 +1043,57 @@ void speex_resampler_get_quality(SpeexResamplerState *st, int *quality)
897 *quality = st->quality; 1043 *quality = st->quality;
898} 1044}
899 1045
900void speex_resampler_set_input_stride(SpeexResamplerState *st, int stride) 1046void speex_resampler_set_input_stride(SpeexResamplerState *st, spx_uint32_t stride)
901{ 1047{
902 st->in_stride = stride; 1048 st->in_stride = stride;
903} 1049}
904 1050
905void speex_resampler_get_input_stride(SpeexResamplerState *st, int *stride) 1051void speex_resampler_get_input_stride(SpeexResamplerState *st, spx_uint32_t *stride)
906{ 1052{
907 *stride = st->in_stride; 1053 *stride = st->in_stride;
908} 1054}
909 1055
910void speex_resampler_set_output_stride(SpeexResamplerState *st, int stride) 1056void speex_resampler_set_output_stride(SpeexResamplerState *st, spx_uint32_t stride)
911{ 1057{
912 st->out_stride = stride; 1058 st->out_stride = stride;
913} 1059}
914 1060
915void speex_resampler_get_output_stride(SpeexResamplerState *st, int *stride) 1061void speex_resampler_get_output_stride(SpeexResamplerState *st, spx_uint32_t *stride)
916{ 1062{
917 *stride = st->out_stride; 1063 *stride = st->out_stride;
918} 1064}
919 1065
920void speex_resampler_skip_zeros(SpeexResamplerState *st) 1066int speex_resampler_skip_zeros(SpeexResamplerState *st)
921{ 1067{
922 int i; 1068 spx_uint32_t i;
923 for (i=0;i<st->nb_channels;i++) 1069 for (i=0;i<st->nb_channels;i++)
924 st->last_sample[i] = st->filt_len/2; 1070 st->last_sample[i] = st->filt_len/2;
1071 return RESAMPLER_ERR_SUCCESS;
925} 1072}
926 1073
927void speex_resampler_reset_mem(SpeexResamplerState *st) 1074int speex_resampler_reset_mem(SpeexResamplerState *st)
928{ 1075{
929 int i; 1076 spx_uint32_t i;
930 for (i=0;i<st->nb_channels*(st->filt_len-1);i++) 1077 for (i=0;i<st->nb_channels*(st->filt_len-1);i++)
931 st->mem[i] = 0; 1078 st->mem[i] = 0;
1079 return RESAMPLER_ERR_SUCCESS;
932} 1080}
933 1081
1082const char *speex_resampler_strerror(int err)
1083{
1084 switch (err)
1085 {
1086 case RESAMPLER_ERR_SUCCESS:
1087 return "Success.";
1088 case RESAMPLER_ERR_ALLOC_FAILED:
1089 return "Memory allocation failed.";
1090 case RESAMPLER_ERR_BAD_STATE:
1091 return "Bad resampler state.";
1092 case RESAMPLER_ERR_INVALID_ARG:
1093 return "Invalid argument.";
1094 case RESAMPLER_ERR_PTR_OVERLAP:
1095 return "Input and output buffers overlap.";
1096 default:
1097 return "Unknown error. Bad error code or strange version mismatch.";
1098 }
1099}
diff --git a/apps/codecs/libspeex/rockbox.c b/apps/codecs/libspeex/rockbox.c
index ace2dfb63f..89af3cba5d 100644
--- a/apps/codecs/libspeex/rockbox.c
+++ b/apps/codecs/libspeex/rockbox.c
@@ -81,6 +81,11 @@ void speex_warning_int(const char *str, int val)
81 DEBUGF("warning: %s %d\n", str, val); 81 DEBUGF("warning: %s %d\n", str, val);
82} 82}
83 83
84void speex_notify(const char *str)
85{
86 DEBUGF("notice: %s\n", str);
87}
88
84void _speex_putc(int ch, void *file) 89void _speex_putc(int ch, void *file)
85{ 90{
86 //FILE *f = (FILE *)file; 91 //FILE *f = (FILE *)file;
diff --git a/apps/codecs/libspeex/sb_celp.c b/apps/codecs/libspeex/sb_celp.c
index 0b4b619e52..faabe24766 100644
--- a/apps/codecs/libspeex/sb_celp.c
+++ b/apps/codecs/libspeex/sb_celp.c
@@ -192,16 +192,18 @@ void *sb_encoder_init(const SpeexMode *m)
192 st = (SBEncState*)speex_alloc(sizeof(SBEncState)); 192 st = (SBEncState*)speex_alloc(sizeof(SBEncState));
193 if (!st) 193 if (!st)
194 return NULL; 194 return NULL;
195#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
196 st->stack = NULL;
197#else
198 st->stack = (char*)speex_alloc_scratch(SB_ENC_STACK);
199#endif
200 st->mode = m; 195 st->mode = m;
201 mode = (const SpeexSBMode*)m->mode; 196 mode = (const SpeexSBMode*)m->mode;
202 197
203 198
204 st->st_low = speex_encoder_init(mode->nb_mode); 199 st->st_low = speex_encoder_init(mode->nb_mode);
200#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
201 st->stack = NULL;
202#else
203 /*st->stack = (char*)speex_alloc_scratch(SB_ENC_STACK);*/
204 speex_encoder_ctl(st->st_low, SPEEX_GET_STACK, &st->stack);
205#endif
206
205 st->full_frame_size = 2*mode->frameSize; 207 st->full_frame_size = 2*mode->frameSize;
206 st->frame_size = mode->frameSize; 208 st->frame_size = mode->frameSize;
207 st->subframeSize = mode->subframeSize; 209 st->subframeSize = mode->subframeSize;
@@ -275,7 +277,7 @@ void sb_encoder_destroy(void *state)
275 277
276 speex_encoder_destroy(st->st_low); 278 speex_encoder_destroy(st->st_low);
277#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA)) 279#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA))
278 speex_free_scratch(st->stack); 280 /*speex_free_scratch(st->stack);*/
279#endif 281#endif
280 282
281 speex_free(st->high); 283 speex_free(st->high);
@@ -629,7 +631,11 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
629 quant=31; 631 quant=31;
630 speex_bits_pack(bits, quant, 5); 632 speex_bits_pack(bits, quant, 5);
631 } 633 }
632 634 if (st->innov_rms_save)
635 {
636 st->innov_rms_save[sub] = eh;
637 }
638 st->exc_rms[sub] = eh;
633 } else { 639 } else {
634 spx_word16_t gc; /*Q7*/ 640 spx_word16_t gc; /*Q7*/
635 spx_word32_t scale; /*Q14*/ 641 spx_word32_t scale; /*Q14*/
@@ -716,11 +722,11 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
716 { 722 {
717 st->innov_rms_save[sub] = MULT16_16_Q15(QCONST16(.70711f, 15), compute_rms(innov, st->subframeSize)); 723 st->innov_rms_save[sub] = MULT16_16_Q15(QCONST16(.70711f, 15), compute_rms(innov, st->subframeSize));
718 } 724 }
725 st->exc_rms[sub] = compute_rms16(exc, st->subframeSize);
719 726
720 727
721 } 728 }
722 729
723 st->exc_rms[sub] = compute_rms16(exc, st->subframeSize);
724 730
725 /*Keep the previous memory*/ 731 /*Keep the previous memory*/
726 for (i=0;i<st->lpcSize;i++) 732 for (i=0;i<st->lpcSize;i++)
@@ -754,20 +760,18 @@ void *sb_decoder_init(const SpeexMode *m)
754 st = (SBDecState*)speex_alloc(sizeof(SBDecState)); 760 st = (SBDecState*)speex_alloc(sizeof(SBDecState));
755 if (!st) 761 if (!st)
756 return NULL; 762 return NULL;
757#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
758 st->stack = NULL;
759#else
760 st->stack = (char*)speex_alloc_scratch(SB_DEC_STACK);
761#endif
762 st->mode = m; 763 st->mode = m;
763 mode=(const SpeexSBMode*)m->mode; 764 mode=(const SpeexSBMode*)m->mode;
764
765 st->encode_submode = 1; 765 st->encode_submode = 1;
766 766
767
768
769
770 st->st_low = speex_decoder_init(mode->nb_mode); 767 st->st_low = speex_decoder_init(mode->nb_mode);
768#if defined(VAR_ARRAYS) || defined (USE_ALLOCA)
769 st->stack = NULL;
770#else
771 /*st->stack = (char*)speex_alloc_scratch(SB_DEC_STACK);*/
772 speex_decoder_ctl(st->st_low, SPEEX_GET_STACK, &st->stack);
773#endif
774
771 st->full_frame_size = 2*mode->frameSize; 775 st->full_frame_size = 2*mode->frameSize;
772 st->frame_size = mode->frameSize; 776 st->frame_size = mode->frameSize;
773 st->subframeSize = mode->subframeSize; 777 st->subframeSize = mode->subframeSize;
@@ -813,7 +817,7 @@ void sb_decoder_destroy(void *state)
813 st = (SBDecState*)state; 817 st = (SBDecState*)state;
814 speex_decoder_destroy(st->st_low); 818 speex_decoder_destroy(st->st_low);
815#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA)) 819#if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA))
816 speex_free_scratch(st->stack); 820 /*speex_free_scratch(st->stack);*/
817#endif 821#endif
818 822
819 speex_free(st->g0_mem); 823 speex_free(st->g0_mem);
@@ -882,6 +886,8 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
882 const SpeexSBMode *mode; 886 const SpeexSBMode *mode;
883 spx_word16_t *out = (spx_word16_t*)vout; 887 spx_word16_t *out = (spx_word16_t*)vout;
884 spx_word16_t *low_innov_alias; 888 spx_word16_t *low_innov_alias;
889 spx_word32_t exc_ener_sum = 0;
890
885 st = (SBDecState*)state; 891 st = (SBDecState*)state;
886 stack=st->stack; 892 stack=st->stack;
887 mode = (const SpeexSBMode*)(st->mode->mode); 893 mode = (const SpeexSBMode*)(st->mode->mode);
@@ -925,7 +931,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
925 } 931 }
926 if (st->submodeID != 0 && st->submodes[st->submodeID] == NULL) 932 if (st->submodeID != 0 && st->submodes[st->submodeID] == NULL)
927 { 933 {
928 speex_warning("Invalid mode encountered: corrupted stream?"); 934 speex_notify("Invalid mode encountered. The stream is corrupted.");
929 return -2; 935 return -2;
930 } 936 }
931 } 937 }
@@ -1006,8 +1012,8 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
1006 rh = LPC_SCALING; 1012 rh = LPC_SCALING;
1007 for (i=0;i<st->lpcSize;i+=2) 1013 for (i=0;i<st->lpcSize;i+=2)
1008 { 1014 {
1009 rh += st->interp_qlpc[i+1] - st->interp_qlpc[i]; 1015 rh += ak[i+1] - ak[i];
1010 st->pi_gain[sub] += st->interp_qlpc[i] + st->interp_qlpc[i+1]; 1016 st->pi_gain[sub] += ak[i] + ak[i+1];
1011 } 1017 }
1012 1018
1013 rl = low_pi_gain[sub]; 1019 rl = low_pi_gain[sub];
@@ -1083,9 +1089,9 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
1083 for (i=0;i<st->lpcSize;i++) 1089 for (i=0;i<st->lpcSize;i++)
1084 st->interp_qlpc[i] = ak[i]; 1090 st->interp_qlpc[i] = ak[i];
1085 st->exc_rms[sub] = compute_rms16(st->excBuf, st->subframeSize); 1091 st->exc_rms[sub] = compute_rms16(st->excBuf, st->subframeSize);
1086 1092 exc_ener_sum = ADD32(exc_ener_sum, DIV32(MULT16_16(st->exc_rms[sub],st->exc_rms[sub]), st->nbSubframes));
1087 } 1093 }
1088 st->last_ener = compute_rms16(out+st->frame_size, st->frame_size); 1094 st->last_ener = spx_sqrt(exc_ener_sum);
1089 1095
1090 qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack); 1096 qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack);
1091 for (i=0;i<st->lpcSize;i++) 1097 for (i=0;i<st->lpcSize;i++)
@@ -1335,7 +1341,9 @@ int sb_encoder_ctl(void *state, int request, void *ptr)
1335 case SPEEX_SET_WIDEBAND: 1341 case SPEEX_SET_WIDEBAND:
1336 speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr); 1342 speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr);
1337 break; 1343 break;
1338 1344 case SPEEX_GET_STACK:
1345 *((char**)ptr) = st->stack;
1346 break;
1339 default: 1347 default:
1340 speex_warning_int("Unknown nb_ctl request: ", request); 1348 speex_warning_int("Unknown nb_ctl request: ", request);
1341 return -1; 1349 return -1;
@@ -1433,7 +1441,9 @@ int sb_decoder_ctl(void *state, int request, void *ptr)
1433 case SPEEX_GET_HIGHPASS: 1441 case SPEEX_GET_HIGHPASS:
1434 speex_decoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr); 1442 speex_decoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr);
1435 break; 1443 break;
1436 1444 case SPEEX_GET_ACTIVITY:
1445 speex_decoder_ctl(st->st_low, SPEEX_GET_ACTIVITY, ptr);
1446 break;
1437 case SPEEX_GET_PI_GAIN: 1447 case SPEEX_GET_PI_GAIN:
1438 { 1448 {
1439 int i; 1449 int i;
@@ -1458,7 +1468,9 @@ int sb_decoder_ctl(void *state, int request, void *ptr)
1458 case SPEEX_SET_WIDEBAND: 1468 case SPEEX_SET_WIDEBAND:
1459 speex_decoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr); 1469 speex_decoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr);
1460 break; 1470 break;
1461 1471 case SPEEX_GET_STACK:
1472 *((char**)ptr) = st->stack;
1473 break;
1462 default: 1474 default:
1463 speex_warning_int("Unknown nb_ctl request: ", request); 1475 speex_warning_int("Unknown nb_ctl request: ", request);
1464 return -1; 1476 return -1;
diff --git a/apps/codecs/libspeex/speex/speex.h b/apps/codecs/libspeex/speex/speex.h
index 0ae1abad34..0ff4be135f 100644
--- a/apps/codecs/libspeex/speex/speex.h
+++ b/apps/codecs/libspeex/speex/speex.h
@@ -155,6 +155,10 @@ extern "C" {
155/** Get status of input/output high-pass filtering */ 155/** Get status of input/output high-pass filtering */
156#define SPEEX_GET_HIGHPASS 45 156#define SPEEX_GET_HIGHPASS 45
157 157
158/** Get "activity level" of the last decoded frame, i.e.
159 now much damage we cause if we remove the frame */
160#define SPEEX_GET_ACTIVITY 47
161
158 162
159/* Preserving compatibility:*/ 163/* Preserving compatibility:*/
160/** Equivalent to SPEEX_SET_ENH */ 164/** Equivalent to SPEEX_SET_ENH */
@@ -297,7 +301,7 @@ typedef struct SpeexMode {
297 * encode, you need one state per channel. 301 * encode, you need one state per channel.
298 * 302 *
299 * @param mode The mode to use (either speex_nb_mode or speex_wb.mode) 303 * @param mode The mode to use (either speex_nb_mode or speex_wb.mode)
300 * @return A newly created encoder 304 * @return A newly created encoder state or NULL if state allocation fails
301 */ 305 */
302void *speex_encoder_init(const SpeexMode *mode); 306void *speex_encoder_init(const SpeexMode *mode);
303 307
@@ -330,7 +334,7 @@ int speex_encode_int(void *state, spx_int16_t *in, SpeexBits *bits);
330 * @param state Encoder state 334 * @param state Encoder state
331 * @param request ioctl-type request (one of the SPEEX_* macros) 335 * @param request ioctl-type request (one of the SPEEX_* macros)
332 * @param ptr Data exchanged to-from function 336 * @param ptr Data exchanged to-from function
333 * @return 0 if no error, -1 if request in unknown 337 * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter
334 */ 338 */
335int speex_encoder_ctl(void *state, int request, void *ptr); 339int speex_encoder_ctl(void *state, int request, void *ptr);
336 340
@@ -341,7 +345,7 @@ int speex_encoder_ctl(void *state, int request, void *ptr);
341 * decode, you need one state per channel. 345 * decode, you need one state per channel.
342 * 346 *
343 * @param mode Speex mode (one of speex_nb_mode or speex_wb_mode) 347 * @param mode Speex mode (one of speex_nb_mode or speex_wb_mode)
344 * @return A newly created decoder state 348 * @return A newly created decoder state or NULL if state allocation fails
345 */ 349 */
346void *speex_decoder_init(const SpeexMode *mode); 350void *speex_decoder_init(const SpeexMode *mode);
347 351
@@ -376,7 +380,7 @@ int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out);
376 * @param state Decoder state 380 * @param state Decoder state
377 * @param request ioctl-type request (one of the SPEEX_* macros) 381 * @param request ioctl-type request (one of the SPEEX_* macros)
378 * @param ptr Data exchanged to-from function 382 * @param ptr Data exchanged to-from function
379 * @return 0 if no error, -1 if request in unknown 383 * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter
380 */ 384 */
381int speex_decoder_ctl(void *state, int request, void *ptr); 385int speex_decoder_ctl(void *state, int request, void *ptr);
382 386
@@ -386,12 +390,14 @@ int speex_decoder_ctl(void *state, int request, void *ptr);
386 * @param mode Speex mode 390 * @param mode Speex mode
387 * @param request ioctl-type request (one of the SPEEX_* macros) 391 * @param request ioctl-type request (one of the SPEEX_* macros)
388 * @param ptr Data exchanged to-from function 392 * @param ptr Data exchanged to-from function
393 * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter
389 */ 394 */
390int speex_mode_query(const SpeexMode *mode, int request, void *ptr); 395int speex_mode_query(const SpeexMode *mode, int request, void *ptr);
391 396
392/** Functions for controlling the behavior of libspeex 397/** Functions for controlling the behavior of libspeex
393 * @param request ioctl-type request (one of the SPEEX_LIB_* macros) 398 * @param request ioctl-type request (one of the SPEEX_LIB_* macros)
394 * @param ptr Data exchanged to-from function 399 * @param ptr Data exchanged to-from function
400 * @return 0 if no error, -1 if request in unknown, -2 for invalid parameter
395 */ 401 */
396int speex_lib_ctl(int request, void *ptr); 402int speex_lib_ctl(int request, void *ptr);
397 403
diff --git a/apps/codecs/libspeex/speex/speex_bits.h b/apps/codecs/libspeex/speex/speex_bits.h
index 88334c4214..a26fb4ce0c 100644
--- a/apps/codecs/libspeex/speex/speex_bits.h
+++ b/apps/codecs/libspeex/speex/speex_bits.h
@@ -64,6 +64,9 @@ void speex_bits_init(SpeexBits *bits);
64/** Initializes SpeexBits struct using a pre-allocated buffer*/ 64/** Initializes SpeexBits struct using a pre-allocated buffer*/
65void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size); 65void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size);
66 66
67/** Sets the bits in a SpeexBits struct to use data from an existing buffer (for decoding without copying data) */
68void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size);
69
67/** Frees all resources associated to a SpeexBits struct. Right now this does nothing since no resources are allocated, but this could change in the future.*/ 70/** Frees all resources associated to a SpeexBits struct. Right now this does nothing since no resources are allocated, but this could change in the future.*/
68void speex_bits_destroy(SpeexBits *bits); 71void speex_bits_destroy(SpeexBits *bits);
69 72
diff --git a/apps/codecs/libspeex/speex/speex_jitter.h b/apps/codecs/libspeex/speex/speex_jitter.h
index a5314d6e0a..570e22b1e2 100644
--- a/apps/codecs/libspeex/speex/speex_jitter.h
+++ b/apps/codecs/libspeex/speex/speex_jitter.h
@@ -121,7 +121,7 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet);
121 * @param packet Returned packet 121 * @param packet Returned packet
122 * @param current_timestamp Timestamp for the returned packet 122 * @param current_timestamp Timestamp for the returned packet
123*/ 123*/
124int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_uint32_t *current_timestamp); 124int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset);
125 125
126/** Get pointer timestamp of jitter buffer 126/** Get pointer timestamp of jitter buffer
127 * 127 *
@@ -144,7 +144,7 @@ void jitter_buffer_tick(JitterBuffer *jitter);
144*/ 144*/
145int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr); 145int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr);
146 146
147int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_uint32_t *start_offset); 147int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset);
148 148
149/* @} */ 149/* @} */
150 150
diff --git a/apps/codecs/libspeex/speex/speex_resampler.h b/apps/codecs/libspeex/speex/speex_resampler.h
index 93642ced2f..c44fbcd0d1 100644
--- a/apps/codecs/libspeex/speex/speex_resampler.h
+++ b/apps/codecs/libspeex/speex/speex_resampler.h
@@ -69,29 +69,20 @@
69#define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality) 69#define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
70#define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride) 70#define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)
71#define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride) 71#define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
72#define speex_resample_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resample_set_output_stride) 72#define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
73#define speex_resample_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resample_get_output_stride) 73#define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
74#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros) 74#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
75#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem) 75#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
76#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
76 77
77#define spx_int16_t short 78#define spx_int16_t short
78 79#define spx_int32_t int
79#ifdef FIXED_POINT 80#define spx_uint16_t unsigned short
80#define spx_word16_t short 81#define spx_uint32_t unsigned int
81#define spx_word32_t int 82
82
83#else /* FIXED_POINT */
84
85#define spx_word16_t float
86#define spx_word32_t float
87#define MULT16_16(a,b) ((a)*(b))
88#define MULT16_32_Q15(a,b) ((a)*(b))
89#define PSHR32(a,b) (a)
90#endif /* FIXED_POINT */
91
92#else /* OUTSIDE_SPEEX */ 83#else /* OUTSIDE_SPEEX */
93 84
94#include "speex_types.h" 85#include "speex/speex_types.h"
95 86
96#endif /* OUTSIDE_SPEEX */ 87#endif /* OUTSIDE_SPEEX */
97 88
@@ -104,7 +95,17 @@ extern "C" {
104#define SPEEX_RESAMPLER_QUALITY_DEFAULT 4 95#define SPEEX_RESAMPLER_QUALITY_DEFAULT 4
105#define SPEEX_RESAMPLER_QUALITY_VOIP 3 96#define SPEEX_RESAMPLER_QUALITY_VOIP 3
106#define SPEEX_RESAMPLER_QUALITY_DESKTOP 5 97#define SPEEX_RESAMPLER_QUALITY_DESKTOP 5
98
99enum {
100 RESAMPLER_ERR_SUCCESS = 0,
101 RESAMPLER_ERR_ALLOC_FAILED = 1,
102 RESAMPLER_ERR_BAD_STATE = 2,
103 RESAMPLER_ERR_INVALID_ARG = 3,
104 RESAMPLER_ERR_PTR_OVERLAP = 4,
107 105
106 RESAMPLER_ERR_MAX_ERROR
107};
108
108struct SpeexResamplerState_; 109struct SpeexResamplerState_;
109typedef struct SpeexResamplerState_ SpeexResamplerState; 110typedef struct SpeexResamplerState_ SpeexResamplerState;
110 111
@@ -117,10 +118,11 @@ typedef struct SpeexResamplerState_ SpeexResamplerState;
117 * @return Newly created resampler state 118 * @return Newly created resampler state
118 * @retval NULL Error: not enough memory 119 * @retval NULL Error: not enough memory
119 */ 120 */
120SpeexResamplerState *speex_resampler_init(int nb_channels, 121SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels,
121 int in_rate, 122 spx_uint32_t in_rate,
122 int out_rate, 123 spx_uint32_t out_rate,
123 int quality); 124 int quality,
125 int *err);
124 126
125/** Create a new resampler with fractional input/output rates. The sampling 127/** Create a new resampler with fractional input/output rates. The sampling
126 * rate ratio is an arbitrary rational number with both the numerator and 128 * rate ratio is an arbitrary rational number with both the numerator and
@@ -135,12 +137,13 @@ SpeexResamplerState *speex_resampler_init(int nb_channels,
135 * @return Newly created resampler state 137 * @return Newly created resampler state
136 * @retval NULL Error: not enough memory 138 * @retval NULL Error: not enough memory
137 */ 139 */
138SpeexResamplerState *speex_resampler_init_frac(int nb_channels, 140SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
139 int ratio_num, 141 spx_uint32_t ratio_num,
140 int ratio_den, 142 spx_uint32_t ratio_den,
141 int in_rate, 143 spx_uint32_t in_rate,
142 int out_rate, 144 spx_uint32_t out_rate,
143 int quality); 145 int quality,
146 int *err);
144 147
145/** Destroy a resampler state. 148/** Destroy a resampler state.
146 * @param st Resampler state 149 * @param st Resampler state
@@ -157,12 +160,12 @@ void speex_resampler_destroy(SpeexResamplerState *st);
157 * @param out Output buffer 160 * @param out Output buffer
158 * @param out_len Size of the output buffer. Returns the number of samples written 161 * @param out_len Size of the output buffer. Returns the number of samples written
159 */ 162 */
160void speex_resampler_process_float(SpeexResamplerState *st, 163int speex_resampler_process_float(SpeexResamplerState *st,
161 int channel_index, 164 spx_uint32_t channel_index,
162 const float *in, 165 const float *in,
163 int *in_len, 166 spx_uint32_t *in_len,
164 float *out, 167 float *out,
165 int *out_len); 168 spx_uint32_t *out_len);
166 169
167/** Resample an int array. The input and output buffers must *not* overlap. 170/** Resample an int array. The input and output buffers must *not* overlap.
168 * @param st Resampler state 171 * @param st Resampler state
@@ -174,12 +177,12 @@ void speex_resampler_process_float(SpeexResamplerState *st,
174 * @param out Output buffer 177 * @param out Output buffer
175 * @param out_len Size of the output buffer. Returns the number of samples written 178 * @param out_len Size of the output buffer. Returns the number of samples written
176 */ 179 */
177void speex_resampler_process_int(SpeexResamplerState *st, 180int speex_resampler_process_int(SpeexResamplerState *st,
178 int channel_index, 181 spx_uint32_t channel_index,
179 const spx_int16_t *in, 182 const spx_int16_t *in,
180 int *in_len, 183 spx_uint32_t *in_len,
181 spx_int16_t *out, 184 spx_int16_t *out,
182 int *out_len); 185 spx_uint32_t *out_len);
183 186
184/** Resample an interleaved float array. The input and output buffers must *not* overlap. 187/** Resample an interleaved float array. The input and output buffers must *not* overlap.
185 * @param st Resampler state 188 * @param st Resampler state
@@ -190,11 +193,11 @@ void speex_resampler_process_int(SpeexResamplerState *st,
190 * @param out_len Size of the output buffer. Returns the number of samples written. 193 * @param out_len Size of the output buffer. Returns the number of samples written.
191 * This is all per-channel. 194 * This is all per-channel.
192 */ 195 */
193void speex_resampler_process_interleaved_float(SpeexResamplerState *st, 196int speex_resampler_process_interleaved_float(SpeexResamplerState *st,
194 const float *in, 197 const float *in,
195 int *in_len, 198 spx_uint32_t *in_len,
196 float *out, 199 float *out,
197 int *out_len); 200 spx_uint32_t *out_len);
198 201
199/** Resample an interleaved int array. The input and output buffers must *not* overlap. 202/** Resample an interleaved int array. The input and output buffers must *not* overlap.
200 * @param st Resampler state 203 * @param st Resampler state
@@ -205,20 +208,20 @@ void speex_resampler_process_interleaved_float(SpeexResamplerState *st,
205 * @param out_len Size of the output buffer. Returns the number of samples written. 208 * @param out_len Size of the output buffer. Returns the number of samples written.
206 * This is all per-channel. 209 * This is all per-channel.
207 */ 210 */
208void speex_resampler_process_interleaved_int(SpeexResamplerState *st, 211int speex_resampler_process_interleaved_int(SpeexResamplerState *st,
209 const spx_int16_t *in, 212 const spx_int16_t *in,
210 int *in_len, 213 spx_uint32_t *in_len,
211 spx_int16_t *out, 214 spx_int16_t *out,
212 int *out_len); 215 spx_uint32_t *out_len);
213 216
214/** Set (change) the input/output sampling rates (integer value). 217/** Set (change) the input/output sampling rates (integer value).
215 * @param st Resampler state 218 * @param st Resampler state
216 * @param in_rate Input sampling rate (integer number of Hz). 219 * @param in_rate Input sampling rate (integer number of Hz).
217 * @param out_rate Output sampling rate (integer number of Hz). 220 * @param out_rate Output sampling rate (integer number of Hz).
218 */ 221 */
219void speex_resampler_set_rate(SpeexResamplerState *st, 222int speex_resampler_set_rate(SpeexResamplerState *st,
220 int in_rate, 223 spx_uint32_t in_rate,
221 int out_rate); 224 spx_uint32_t out_rate);
222 225
223/** Get the current input/output sampling rates (integer value). 226/** Get the current input/output sampling rates (integer value).
224 * @param st Resampler state 227 * @param st Resampler state
@@ -226,8 +229,8 @@ void speex_resampler_set_rate(SpeexResamplerState *st,
226 * @param out_rate Output sampling rate (integer number of Hz) copied. 229 * @param out_rate Output sampling rate (integer number of Hz) copied.
227 */ 230 */
228void speex_resampler_get_rate(SpeexResamplerState *st, 231void speex_resampler_get_rate(SpeexResamplerState *st,
229 int *in_rate, 232 spx_uint32_t *in_rate,
230 int *out_rate); 233 spx_uint32_t *out_rate);
231 234
232/** Set (change) the input/output sampling rates and resampling ratio 235/** Set (change) the input/output sampling rates and resampling ratio
233 * (fractional values in Hz supported). 236 * (fractional values in Hz supported).
@@ -237,11 +240,11 @@ void speex_resampler_get_rate(SpeexResamplerState *st,
237 * @param in_rate Input sampling rate rounded to the nearest integer (in Hz). 240 * @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
238 * @param out_rate Output sampling rate rounded to the nearest integer (in Hz). 241 * @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
239 */ 242 */
240void speex_resampler_set_rate_frac(SpeexResamplerState *st, 243int speex_resampler_set_rate_frac(SpeexResamplerState *st,
241 int ratio_num, 244 spx_uint32_t ratio_num,
242 int ratio_den, 245 spx_uint32_t ratio_den,
243 int in_rate, 246 spx_uint32_t in_rate,
244 int out_rate); 247 spx_uint32_t out_rate);
245 248
246/** Get the current resampling ratio. This will be reduced to the least 249/** Get the current resampling ratio. This will be reduced to the least
247 * common denominator. 250 * common denominator.
@@ -250,15 +253,15 @@ void speex_resampler_set_rate_frac(SpeexResamplerState *st,
250 * @param ratio_den Denominator of the sampling rate ratio copied 253 * @param ratio_den Denominator of the sampling rate ratio copied
251 */ 254 */
252void speex_resampler_get_ratio(SpeexResamplerState *st, 255void speex_resampler_get_ratio(SpeexResamplerState *st,
253 int *ratio_num, 256 spx_uint32_t *ratio_num,
254 int *ratio_den); 257 spx_uint32_t *ratio_den);
255 258
256/** Set (change) the conversion quality. 259/** Set (change) the conversion quality.
257 * @param st Resampler state 260 * @param st Resampler state
258 * @param quality Resampling quality between 0 and 10, where 0 has poor 261 * @param quality Resampling quality between 0 and 10, where 0 has poor
259 * quality and 10 has very high quality. 262 * quality and 10 has very high quality.
260 */ 263 */
261void speex_resampler_set_quality(SpeexResamplerState *st, 264int speex_resampler_set_quality(SpeexResamplerState *st,
262 int quality); 265 int quality);
263 266
264/** Get the conversion quality. 267/** Get the conversion quality.
@@ -274,28 +277,28 @@ void speex_resampler_get_quality(SpeexResamplerState *st,
274 * @param stride Input stride 277 * @param stride Input stride
275 */ 278 */
276void speex_resampler_set_input_stride(SpeexResamplerState *st, 279void speex_resampler_set_input_stride(SpeexResamplerState *st,
277 int stride); 280 spx_uint32_t stride);
278 281
279/** Get the input stride. 282/** Get the input stride.
280 * @param st Resampler state 283 * @param st Resampler state
281 * @param stride Input stride copied 284 * @param stride Input stride copied
282 */ 285 */
283void speex_resampler_get_input_stride(SpeexResamplerState *st, 286void speex_resampler_get_input_stride(SpeexResamplerState *st,
284 int *stride); 287 spx_uint32_t *stride);
285 288
286/** Set (change) the output stride. 289/** Set (change) the output stride.
287 * @param st Resampler state 290 * @param st Resampler state
288 * @param stride Output stride 291 * @param stride Output stride
289 */ 292 */
290void speex_resample_set_output_stride(SpeexResamplerState *st, 293void speex_resampler_set_output_stride(SpeexResamplerState *st,
291 int stride); 294 spx_uint32_t stride);
292 295
293/** Get the output stride. 296/** Get the output stride.
294 * @param st Resampler state copied 297 * @param st Resampler state copied
295 * @param stride Output stride 298 * @param stride Output stride
296 */ 299 */
297void speex_resample_get_output_stride(SpeexResamplerState *st, 300void speex_resampler_get_output_stride(SpeexResamplerState *st,
298 int *stride); 301 spx_uint32_t *stride);
299 302
300/** Make sure that the first samples to go out of the resamplers don't have 303/** Make sure that the first samples to go out of the resamplers don't have
301 * leading zeros. This is only useful before starting to use a newly created 304 * leading zeros. This is only useful before starting to use a newly created
@@ -305,12 +308,18 @@ void speex_resample_get_output_stride(SpeexResamplerState *st,
305 * is the same for the first frame). 308 * is the same for the first frame).
306 * @param st Resampler state 309 * @param st Resampler state
307 */ 310 */
308void speex_resampler_skip_zeros(SpeexResamplerState *st); 311int speex_resampler_skip_zeros(SpeexResamplerState *st);
309 312
310/** Reset a resampler so a new (unrelated) stream can be processed. 313/** Reset a resampler so a new (unrelated) stream can be processed.
311 * @param st Resampler state 314 * @param st Resampler state
312 */ 315 */
313void speex_resampler_reset_mem(SpeexResamplerState *st); 316int speex_resampler_reset_mem(SpeexResamplerState *st);
317
318/** Returns the English meaning for an error code
319 * @param err Error code
320 * @return English string
321 */
322const char *speex_resampler_strerror(int err);
314 323
315#ifdef __cplusplus 324#ifdef __cplusplus
316} 325}
diff --git a/apps/codecs/libspeex/speex_header.c b/apps/codecs/libspeex/speex_header.c
index 13b114a3bc..5719eb1298 100644
--- a/apps/codecs/libspeex/speex_header.c
+++ b/apps/codecs/libspeex/speex_header.c
@@ -133,14 +133,14 @@ SpeexHeader *speex_packet_to_header(char *packet, int size)
133 for (i=0;i<8;i++) 133 for (i=0;i<8;i++)
134 if (packet[i]!=h[i]) 134 if (packet[i]!=h[i])
135 { 135 {
136 speex_warning ("This doesn't look like a Speex file"); 136 speex_notify("This doesn't look like a Speex file");
137 return NULL; 137 return NULL;
138 } 138 }
139 139
140 /*FIXME: Do we allow larger headers?*/ 140 /*FIXME: Do we allow larger headers?*/
141 if (size < (int)sizeof(SpeexHeader)) 141 if (size < (int)sizeof(SpeexHeader))
142 { 142 {
143 speex_warning("Speex header too small"); 143 speex_notify("Speex header too small");
144 return NULL; 144 return NULL;
145 } 145 }
146 146
diff --git a/apps/codecs/libspeex/testdenoise.c b/apps/codecs/libspeex/testdenoise.c
index 1b681866de..42644cb011 100644
--- a/apps/codecs/libspeex/testdenoise.c
+++ b/apps/codecs/libspeex/testdenoise.c
@@ -1,5 +1,5 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2#include "config-speex.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include <speex/speex_preprocess.h> 5#include <speex/speex_preprocess.h>
diff --git a/apps/codecs/libspeex/testecho.c b/apps/codecs/libspeex/testecho.c
index d59dbf94cf..7c32c8f60e 100644
--- a/apps/codecs/libspeex/testecho.c
+++ b/apps/codecs/libspeex/testecho.c
@@ -1,5 +1,5 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2#include "config-speex.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include <stdio.h> 5#include <stdio.h>
diff --git a/apps/codecs/libspeex/testenc.c b/apps/codecs/libspeex/testenc.c
index 17141fa09e..eabd02cc76 100644
--- a/apps/codecs/libspeex/testenc.c
+++ b/apps/codecs/libspeex/testenc.c
@@ -1,5 +1,5 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2#include "config-speex.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include <speex/speex.h> 5#include <speex/speex.h>
diff --git a/apps/codecs/libspeex/testenc_uwb.c b/apps/codecs/libspeex/testenc_uwb.c
index f6b943d46f..e9bf18a667 100644
--- a/apps/codecs/libspeex/testenc_uwb.c
+++ b/apps/codecs/libspeex/testenc_uwb.c
@@ -1,5 +1,5 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2#include "config-speex.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include <speex/speex.h> 5#include <speex/speex.h>
diff --git a/apps/codecs/libspeex/testenc_wb.c b/apps/codecs/libspeex/testenc_wb.c
index f55dffaaba..8e515cb13c 100644
--- a/apps/codecs/libspeex/testenc_wb.c
+++ b/apps/codecs/libspeex/testenc_wb.c
@@ -1,5 +1,5 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2#include "config-speex.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include <speex/speex.h> 5#include <speex/speex.h>
diff --git a/apps/codecs/libspeex/testresample.c b/apps/codecs/libspeex/testresample.c
index bb7ab74db0..71392cc011 100644
--- a/apps/codecs/libspeex/testresample.c
+++ b/apps/codecs/libspeex/testresample.c
@@ -31,7 +31,7 @@
31*/ 31*/
32 32
33#ifdef HAVE_CONFIG_H 33#ifdef HAVE_CONFIG_H
34#include "config-speex.h" 34#include "config.h"
35#endif 35#endif
36 36
37#include <stdio.h> 37#include <stdio.h>
@@ -41,15 +41,15 @@
41 41
42#define NN 256 42#define NN 256
43 43
44int main(int argc, char **argv) 44int main()
45{ 45{
46 int i; 46 spx_uint32_t i;
47 short *in; 47 short *in;
48 short *out; 48 short *out;
49 float *fin, *fout; 49 float *fin, *fout;
50 int count = 0; 50 int count = 0;
51 SpeexResamplerState *st = speex_resampler_init(1, 8000, 12000, 10); 51 SpeexResamplerState *st = speex_resampler_init(1, 8000, 12000, 10, NULL);
52 speex_resampler_set_rate(st, 8000, 15999); 52 speex_resampler_set_rate(st, 96000, 44100);
53 speex_resampler_skip_zeros(st); 53 speex_resampler_skip_zeros(st);
54 54
55 in = malloc(NN*sizeof(short)); 55 in = malloc(NN*sizeof(short));
@@ -58,8 +58,8 @@ int main(int argc, char **argv)
58 fout = malloc(2*NN*sizeof(float)); 58 fout = malloc(2*NN*sizeof(float));
59 while (1) 59 while (1)
60 { 60 {
61 int in_len; 61 spx_uint32_t in_len;
62 int out_len; 62 spx_uint32_t out_len;
63 fread(in, sizeof(short), NN, stdin); 63 fread(in, sizeof(short), NN, stdin);
64 if (feof(stdin)) 64 if (feof(stdin))
65 break; 65 break;
diff --git a/apps/codecs/libspeex/vbr.c b/apps/codecs/libspeex/vbr.c
index 405b7bd887..cc538b3fe9 100644
--- a/apps/codecs/libspeex/vbr.c
+++ b/apps/codecs/libspeex/vbr.c
@@ -48,14 +48,14 @@
48 48
49const float vbr_nb_thresh[9][11]={ 49const float vbr_nb_thresh[9][11]={
50 {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* CNG */ 50 {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* CNG */
51 { 3.5f, 2.5f, 2.0f, 1.2f, 0.5f, 0.0f, -0.5f, -0.7f, -0.8f, -0.9f, -1.0f}, /* 2 kbps */ 51 { 4.0f, 2.5f, 2.0f, 1.2f, 0.5f, 0.0f, -0.5f, -0.7f, -0.8f, -0.9f, -1.0f}, /* 2 kbps */
52 {10.0f, 6.5f, 5.2f, 4.5f, 3.9f, 3.5f, 3.0f, 2.5f, 2.3f, 1.8f, 1.0f}, /* 6 kbps */ 52 {10.0f, 6.5f, 5.2f, 4.5f, 3.9f, 3.5f, 3.0f, 2.5f, 2.3f, 1.8f, 1.0f}, /* 6 kbps */
53 {11.0f, 8.8f, 7.5f, 6.5f, 5.0f, 3.9f, 3.9f, 3.9f, 3.5f, 3.0f, 1.0f}, /* 8 kbps */ 53 {11.0f, 8.8f, 7.5f, 6.5f, 5.0f, 3.9f, 3.9f, 3.9f, 3.5f, 3.0f, 1.0f}, /* 8 kbps */
54 {11.0f, 11.0f, 9.9f, 9.0f, 8.0f, 7.0f, 6.5f, 6.0f, 5.0f, 4.0f, 2.0f}, /* 11 kbps */ 54 {11.0f, 11.0f, 9.9f, 8.5f, 7.0f, 6.0f, 4.5f, 4.0f, 4.0f, 4.0f, 2.0f}, /* 11 kbps */
55 {11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 9.0f, 8.0f, 7.0f, 6.5f, 5.0f, 3.0f}, /* 15 kbps */ 55 {11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 8.5f, 8.0f, 7.0f, 6.0f, 5.0f, 3.0f}, /* 15 kbps */
56 {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 8.5f, 8.0f, 6.5f, 4.0f}, /* 18 kbps */ 56 {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 8.5f, 7.0f, 6.0f, 5.0f}, /* 18 kbps */
57 {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.8f, 7.5f, 5.5f}, /* 24 kbps */ 57 {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.8f, 9.5f, 7.5f}, /* 24 kbps */
58 { 8.0f, 5.0f, 3.7f, 3.0f, 2.5f, 2.0f, 1.8f, 1.5f, 1.0f, 0.0f, 0.0f} /* 4 kbps */ 58 { 7.0f, 4.5f, 3.7f, 3.0f, 2.5f, 2.0f, 1.8f, 1.5f, 1.0f, 0.0f, 0.0f} /* 4 kbps */
59}; 59};
60 60
61 61