summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThom Johansen <thomj@rockbox.org>2007-10-19 21:10:25 +0000
committerThom Johansen <thomj@rockbox.org>2007-10-19 21:10:25 +0000
commit56db5597548d0e9b9733b556a5c14ab4e38547e6 (patch)
tree8846e7d3a15f264853e6ee238994e3522e3bcc5a
parent6dc3a743addde6146b736ec5e1c71159c2150f95 (diff)
downloadrockbox-56db5597548d0e9b9733b556a5c14ab4e38547e6.tar.gz
rockbox-56db5597548d0e9b9733b556a5c14ab4e38547e6.zip
Sync Speex to SVN. Add new header file to adapt to Speex' new way of doing wrapper functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15209 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libspeex/_kiss_fft_guts.h8
-rw-r--r--apps/codecs/libspeex/cb_search.c7
-rw-r--r--apps/codecs/libspeex/config-speex.h8
-rw-r--r--apps/codecs/libspeex/filterbank.c2
-rw-r--r--apps/codecs/libspeex/filters.c11
-rw-r--r--apps/codecs/libspeex/jitter.c87
-rw-r--r--apps/codecs/libspeex/kiss_fft.c9
-rw-r--r--apps/codecs/libspeex/kiss_fftr.c8
-rw-r--r--apps/codecs/libspeex/math_approx.c253
-rw-r--r--apps/codecs/libspeex/math_approx.h275
-rw-r--r--apps/codecs/libspeex/mdf.c14
-rw-r--r--apps/codecs/libspeex/misc.c121
-rw-r--r--apps/codecs/libspeex/misc.h148
-rw-r--r--apps/codecs/libspeex/modes.h2
-rw-r--r--apps/codecs/libspeex/nb_celp.c77
-rw-r--r--apps/codecs/libspeex/nb_celp.h2
-rw-r--r--apps/codecs/libspeex/preprocess.c4
-rw-r--r--apps/codecs/libspeex/pseudofloat.h4
-rw-r--r--apps/codecs/libspeex/quant_lsp.c4
-rw-r--r--apps/codecs/libspeex/resample.c49
-rw-r--r--apps/codecs/libspeex/rockbox.c59
-rw-r--r--apps/codecs/libspeex/rockbox.h99
-rw-r--r--apps/codecs/libspeex/sb_celp.c21
-rw-r--r--apps/codecs/libspeex/speex/speex.h2
-rw-r--r--apps/codecs/libspeex/speex/speex_callbacks.h2
-rw-r--r--apps/codecs/libspeex/speex/speex_echo.h6
-rw-r--r--apps/codecs/libspeex/speex/speex_jitter.h10
-rw-r--r--apps/codecs/libspeex/stack_alloc.h14
-rw-r--r--apps/codecs/libspeex/vorbis_psy.h2
29 files changed, 637 insertions, 671 deletions
diff --git a/apps/codecs/libspeex/_kiss_fft_guts.h b/apps/codecs/libspeex/_kiss_fft_guts.h
index 6eb9bd312b..3023b98b06 100644
--- a/apps/codecs/libspeex/_kiss_fft_guts.h
+++ b/apps/codecs/libspeex/_kiss_fft_guts.h
@@ -12,6 +12,14 @@ Redistribution and use in source and binary forms, with or without modification,
THIS 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.
*/
+#ifdef MIN
+#undef MIN
+#endif
+#define MIN(a,b) ((a)<(b) ? (a):(b))
+#ifdef MAX
+#undef MAX
+#endif
+#define MAX(a,b) ((a)>(b) ? (a):(b))
/* kiss_fft.h
defines kiss_fft_scalar as either short or a float type
diff --git a/apps/codecs/libspeex/cb_search.c b/apps/codecs/libspeex/cb_search.c
index 1090af0e08..ad883cc07f 100644
--- a/apps/codecs/libspeex/cb_search.c
+++ b/apps/codecs/libspeex/cb_search.c
@@ -359,7 +359,11 @@ int update_target
/*"erase" nbest list*/
for (j=0;j<N;j++)
ndist[j]=VERY_LARGE32;
-
+ /* This is not strictly necessary, but it provides an additonal safety
+ to prevent crashes in case something goes wrong in the previous
+ steps (e.g. NaNs) */
+ for (j=0;j<N;j++)
+ best_nind[j] = best_ntarget[j] = 0;
/*For all n-bests of previous subvector*/
for (j=0;j<N;j++)
{
@@ -397,6 +401,7 @@ int update_target
best_nind[n] = best_nind[n-1];
best_ntarget[n] = best_ntarget[n-1];
}
+ /* n is equal to m here, so they're interchangeable */
ndist[m] = err;
best_nind[n] = best_index[k];
best_ntarget[n] = j;
diff --git a/apps/codecs/libspeex/config-speex.h b/apps/codecs/libspeex/config-speex.h
index 461873945f..52c71e9e82 100644
--- a/apps/codecs/libspeex/config-speex.h
+++ b/apps/codecs/libspeex/config-speex.h
@@ -102,19 +102,19 @@
#define SIZEOF_SHORT 2
/* Version extra */
-#define SPEEX_EXTRA_VERSION "-svn"
+#define SPEEX_EXTRA_VERSION "-git"
/* Version major */
#define SPEEX_MAJOR_VERSION 1
/* Version micro */
-#define SPEEX_MICRO_VERSION 14
+#define SPEEX_MICRO_VERSION 15
/* Version minor */
#define SPEEX_MINOR_VERSION 1
/* Complete version string */
-#define SPEEX_VERSION "1.1.14-svn"
+#define SPEEX_VERSION "1.2beta3"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
@@ -160,7 +160,7 @@
#define OVERRIDE_SPEEX_FREE 1
#define OVERRIDE_SPEEX_FREE_SCRATCH 1
#define OVERRIDE_SPEEX_MOVE 1
-#define OVERRIDE_SPEEX_ERROR 1
+#define OVERRIDE_SPEEX_FATAL 1
#define OVERRIDE_SPEEX_WARNING 1
#define OVERRIDE_SPEEX_WARNING_INT 1
#define OVERRIDE_SPEEX_NOTIFY 1
diff --git a/apps/codecs/libspeex/filterbank.c b/apps/codecs/libspeex/filterbank.c
index e665560bff..00391ebf7f 100644
--- a/apps/codecs/libspeex/filterbank.c
+++ b/apps/codecs/libspeex/filterbank.c
@@ -59,7 +59,7 @@ FilterBank *filterbank_new(int banks, spx_word32_t sampling, int len, int type)
int id1;
int id2;
df = DIV32(SHL32(sampling,15),MULT16_16(2,len));
- max_mel = toBARK(EXTRACT16(MULT16_16_Q15(QCONST16(.5f,15),sampling)));
+ max_mel = toBARK(EXTRACT16(sampling/2));
mel_interval = PDIV32(max_mel,banks-1);
bank = (FilterBank*)speex_alloc(sizeof(FilterBank));
diff --git a/apps/codecs/libspeex/filters.c b/apps/codecs/libspeex/filters.c
index fcb8ed4bac..a6a5f62d26 100644
--- a/apps/codecs/libspeex/filters.c
+++ b/apps/codecs/libspeex/filters.c
@@ -80,17 +80,16 @@ void sanitize_values32(spx_word32_t *vec, spx_word32_t min_val, spx_word32_t max
}
}
+void highpass(const spx_word16_t *x, spx_word16_t *y, int len, int filtID, spx_mem_t *mem)
+{
+ int i;
#ifdef FIXED_POINT
- const spx_word16_t Pcoef[5][3] ICONST_ATTR = {{16384, -31313, 14991}, {16384, -31569, 15249}, {16384, -31677, 15328}, {16384, -32313, 15947}, {16384, -22446, 6537}};
- const spx_word16_t Zcoef[5][3] ICONST_ATTR = {{15672, -31344, 15672}, {15802, -31601, 15802}, {15847, -31694, 15847}, {16162, -32322, 16162}, {14418, -28836, 14418}};
+ static const spx_word16_t Pcoef[5][3] ICONST_ATTR = {{16384, -31313, 14991}, {16384, -31569, 15249}, {16384, -31677, 15328}, {16384, -32313, 15947}, {16384, -22446, 6537}};
+ static const spx_word16_t Zcoef[5][3] ICONST_ATTR = {{15672, -31344, 15672}, {15802, -31601, 15802}, {15847, -31694, 15847}, {16162, -32322, 16162}, {14418, -28836, 14418}};
#else
const spx_word16_t Pcoef[5][3] = {{1.00000f, -1.91120f, 0.91498f}, {1.00000f, -1.92683f, 0.93071f}, {1.00000f, -1.93338f, 0.93553f}, {1.00000f, -1.97226f, 0.97332f}, {1.00000f, -1.37000f, 0.39900f}};
const spx_word16_t Zcoef[5][3] = {{0.95654f, -1.91309f, 0.95654f}, {0.96446f, -1.92879f, 0.96446f}, {0.96723f, -1.93445f, 0.96723f}, {0.98645f, -1.97277f, 0.98645f}, {0.88000f, -1.76000f, 0.88000f}};
#endif
-
-void highpass(const spx_word16_t *x, spx_word16_t *y, int len, int filtID, spx_mem_t *mem)
-{
- int i;
const spx_word16_t *den, *num;
if (filtID>4)
filtID=4;
diff --git a/apps/codecs/libspeex/jitter.c b/apps/codecs/libspeex/jitter.c
index 81935e9195..6806b4ff22 100644
--- a/apps/codecs/libspeex/jitter.c
+++ b/apps/codecs/libspeex/jitter.c
@@ -133,8 +133,7 @@ void jitter_buffer_destroy(JitterBuffer *jitter)
/** Put one packet into the jitter buffer */
void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet)
{
- int i;
- unsigned int j;
+ int i,j;
spx_int32_t arrival_margin;
/*fprintf (stderr, "put packet %d %d\n", timestamp, span);*/
if (jitter->reset_state)
@@ -545,87 +544,3 @@ int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr)
return 0;
}
-
-
-void speex_jitter_init(SpeexJitter *jitter, void *decoder, int sampling_rate)
-{
- jitter->dec = decoder;
- speex_decoder_ctl(decoder, SPEEX_GET_FRAME_SIZE, &jitter->frame_size);
-
- jitter->packets = jitter_buffer_init(jitter->frame_size);
-
- speex_bits_init(&jitter->current_packet);
- jitter->valid_bits = 0;
-
-}
-
-void speex_jitter_destroy(SpeexJitter *jitter)
-{
- jitter_buffer_destroy(jitter->packets);
- speex_bits_destroy(&jitter->current_packet);
-}
-
-void speex_jitter_put(SpeexJitter *jitter, char *packet, int len, int timestamp)
-{
- JitterBufferPacket p;
- p.data = packet;
- p.len = len;
- p.timestamp = timestamp;
- p.span = jitter->frame_size;
- jitter_buffer_put(jitter->packets, &p);
-}
-
-void speex_jitter_get(SpeexJitter *jitter, short *out, int *current_timestamp)
-{
- int i;
- int ret;
- spx_int32_t activity;
- char data[2048];
- JitterBufferPacket packet;
- packet.data = data;
-
- if (jitter->valid_bits)
- {
- /* Try decoding last received packet */
- ret = speex_decode_int(jitter->dec, &jitter->current_packet, out);
- if (ret == 0)
- {
- jitter_buffer_tick(jitter->packets);
- return;
- } else {
- jitter->valid_bits = 0;
- }
- }
-
- ret = jitter_buffer_get(jitter->packets, &packet, NULL);
-
- if (ret != JITTER_BUFFER_OK)
- {
- /* No packet found */
-
- /*fprintf (stderr, "lost/late frame\n");*/
- /*Packet is late or lost*/
- speex_decode_int(jitter->dec, NULL, out);
- } else {
- speex_bits_read_from(&jitter->current_packet, packet.data, packet.len);
- /* Decode packet */
- ret = speex_decode_int(jitter->dec, &jitter->current_packet, out);
- if (ret == 0)
- {
- jitter->valid_bits = 1;
- } else {
- /* Error while decoding */
- for (i=0;i<jitter->frame_size;i++)
- out[i]=0;
- }
- }
- speex_decoder_ctl(jitter->dec, SPEEX_GET_ACTIVITY, &activity);
- if (activity < 30)
- jitter_buffer_update_delay(jitter->packets, &packet, NULL);
- jitter_buffer_tick(jitter->packets);
-}
-
-int speex_jitter_get_pointer_timestamp(SpeexJitter *jitter)
-{
- return jitter_buffer_get_pointer_timestamp(jitter->packets);
-}
diff --git a/apps/codecs/libspeex/kiss_fft.c b/apps/codecs/libspeex/kiss_fft.c
index 3470d1108e..c5c0345820 100644
--- a/apps/codecs/libspeex/kiss_fft.c
+++ b/apps/codecs/libspeex/kiss_fft.c
@@ -86,7 +86,7 @@ static void kf_bfly4(
kiss_fft_cpx * Fout,
const size_t fstride,
const kiss_fft_cfg st,
- const size_t m,
+ int m,
int N,
int mm
)
@@ -95,8 +95,7 @@ static void kf_bfly4(
kiss_fft_cpx scratch[6];
const size_t m2=2*m;
const size_t m3=3*m;
- int i;
- unsigned int j;
+ int i, j;
if (st->inverse)
{
@@ -291,7 +290,7 @@ static void kf_bfly_generic(
/*CHECKBUF(scratchbuf,nscratchbuf,p);*/
if (p>17)
- speex_error("KissFFT: max radix supported is 17");
+ speex_fatal("KissFFT: max radix supported is 17");
for ( u=0; u<m; ++u ) {
k=u;
@@ -506,7 +505,7 @@ void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,
{
if (fin == fout)
{
- speex_error("In-place FFT not supported");
+ speex_fatal("In-place FFT not supported");
/*CHECKBUF(tmpbuf,ntmpbuf,st->nfft);
kf_work(tmpbuf,fin,1,in_stride, st->factors,st);
speex_move(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);*/
diff --git a/apps/codecs/libspeex/kiss_fftr.c b/apps/codecs/libspeex/kiss_fftr.c
index ef8e464dcd..9bb4763169 100644
--- a/apps/codecs/libspeex/kiss_fftr.c
+++ b/apps/codecs/libspeex/kiss_fftr.c
@@ -84,7 +84,7 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr
kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc;
if ( st->substate->inverse) {
- speex_error("kiss fft usage error: improper alloc\n");
+ speex_fatal("kiss fft usage error: improper alloc\n");
}
ncfft = st->substate->nfft;
@@ -138,7 +138,7 @@ void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata, kiss_fft_scalar *
int k, ncfft;
if (st->substate->inverse == 0) {
- speex_error ("kiss fft usage error: improper alloc\n");
+ speex_fatal("kiss fft usage error: improper alloc\n");
}
ncfft = st->substate->nfft;
@@ -177,7 +177,7 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar
spx_word32_t f1kr, f1ki, twr, twi;
if ( st->substate->inverse) {
- speex_error("kiss fft usage error: improper alloc\n");
+ speex_fatal("kiss fft usage error: improper alloc\n");
}
ncfft = st->substate->nfft;
@@ -263,7 +263,7 @@ void kiss_fftri2(kiss_fftr_cfg st,const kiss_fft_scalar *freqdata,kiss_fft_scala
int k, ncfft;
if (st->substate->inverse == 0) {
- speex_error ("kiss fft usage error: improper alloc\n");
+ speex_fatal ("kiss fft usage error: improper alloc\n");
}
ncfft = st->substate->nfft;
diff --git a/apps/codecs/libspeex/math_approx.c b/apps/codecs/libspeex/math_approx.c
index 5c8b3498c4..cf5853e313 100644
--- a/apps/codecs/libspeex/math_approx.c
+++ b/apps/codecs/libspeex/math_approx.c
@@ -36,256 +36,3 @@
#include "math_approx.h"
#include "misc.h"
-
-spx_int16_t spx_ilog2(spx_uint32_t x)
-{
- int r=0;
- if (x>=(spx_int32_t)65536)
- {
- x >>= 16;
- r += 16;
- }
- if (x>=256)
- {
- x >>= 8;
- r += 8;
- }
- if (x>=16)
- {
- x >>= 4;
- r += 4;
- }
- if (x>=4)
- {
- x >>= 2;
- r += 2;
- }
- if (x>=2)
- {
- r += 1;
- }
- return r;
-}
-
-spx_int16_t spx_ilog4(spx_uint32_t x)
-{
- int r=0;
- if (x>=(spx_int32_t)65536)
- {
- x >>= 16;
- r += 8;
- }
- if (x>=256)
- {
- x >>= 8;
- r += 4;
- }
- if (x>=16)
- {
- x >>= 4;
- r += 2;
- }
- if (x>=4)
- {
- r += 1;
- }
- return r;
-}
-
-#ifdef FIXED_POINT
-
-/* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25723*x^3 (for .25 < x < 1) */
-/*#define C0 3634
-#define C1 21173
-#define C2 -12627
-#define C3 4215*/
-
-/* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25659*x^3 (for .25 < x < 1) */
-#define C0 3634
-#define C1 21173
-#define C2 -12627
-#define C3 4204
-
-spx_word16_t spx_sqrt(spx_word32_t x)
-{
- int k;
- spx_word32_t rt;
- k = spx_ilog4(x)-6;
- x = VSHR32(x, (k<<1));
- rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
- rt = VSHR32(rt,7-k);
- return rt;
-}
-
-/* log(x) ~= -2.18151 + 4.20592*x - 2.88938*x^2 + 0.86535*x^3 (for .5 < x < 1) */
-
-
-#define A1 16469
-#define A2 2242
-#define A3 1486
-
-spx_word16_t spx_acos(spx_word16_t x)
-{
- int s=0;
- spx_word16_t ret;
- spx_word16_t sq;
- if (x<0)
- {
- s=1;
- x = NEG16(x);
- }
- x = SUB16(16384,x);
-
- x = x >> 1;
- sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3))))));
- ret = spx_sqrt(SHL32(EXTEND32(sq),13));
-
- /*ret = spx_sqrt(67108864*(-1.6129e-04 + 2.0104e+00*f + 2.7373e-01*f*f + 1.8136e-01*f*f*f));*/
- if (s)
- ret = SUB16(25736,ret);
- return ret;
-}
-
-
-#define K1 8192
-#define K2 -4096
-#define K3 340
-#define K4 -10
-
-spx_word16_t spx_cos(spx_word16_t x)
-{
- spx_word16_t x2;
-
- if (x<12868)
- {
- x2 = MULT16_16_P13(x,x);
- return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
- } else {
- x = SUB16(25736,x);
- x2 = MULT16_16_P13(x,x);
- return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
- }
-}
-
-#define L1 32767
-#define L2 -7651
-#define L3 8277
-#define L4 -626
-
-static inline spx_word16_t _spx_cos_pi_2(spx_word16_t x)
-{
- spx_word16_t x2;
-
- x2 = MULT16_16_P15(x,x);
- return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2))))))));
-}
-
-spx_word16_t spx_cos_norm(spx_word32_t x)
-{
- x = x&0x0001ffff;
- if (x>SHL32(EXTEND32(1), 16))
- x = SUB32(SHL32(EXTEND32(1), 17),x);
- if (x&0x00007fff)
- {
- if (x<SHL32(EXTEND32(1), 15))
- {
- return _spx_cos_pi_2(EXTRACT16(x));
- } else {
- return NEG32(_spx_cos_pi_2(EXTRACT16(65536-x)));
- }
- } else {
- if (x&0x0000ffff)
- return 0;
- else if (x&0x0001ffff)
- return -32767;
- else
- return 32767;
- }
-}
-
-/*
- K0 = 1
- K1 = log(2)
- K2 = 3-4*log(2)
- K3 = 3*log(2) - 2
-*/
-#define D0 16384
-#define D1 11356
-#define D2 3726
-#define D3 1301
-/* Input in Q11 format, output in Q16 */
-static spx_word32_t spx_exp2(spx_word16_t x)
-{
- int integer;
- spx_word16_t frac;
- integer = SHR16(x,11);
- if (integer>14)
- return 0x7fffffff;
- else if (integer < -15)
- return 0;
- frac = SHL16(x-SHL16(integer,11),3);
- frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
- return VSHR32(EXTEND32(frac), -integer-2);
-}
-
-/* Input in Q11 format, output in Q16 */
-spx_word32_t spx_exp(spx_word16_t x)
-{
- if (x>21290)
- return 0x7fffffff;
- else if (x<-21290)
- return 0;
- else
- return spx_exp2(MULT16_16_P14(23637,x));
-}
-#define M1 32767
-#define M2 -21
-#define M3 -11943
-#define M4 4936
-
-static inline spx_word16_t spx_atan01(spx_word16_t x)
-{
- return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x)))))));
-}
-
-/* Input in Q15, output in Q14 */
-spx_word16_t spx_atan(spx_word32_t x)
-{
- if (x <= 32767)
- {
- return SHR16(spx_atan01(x),1);
- } else {
- int e = spx_ilog2(x);
- if (e>=29)
- return 25736;
- x = DIV32_16(SHL32(EXTEND32(32767),29-e), EXTRACT16(SHR32(x, e-14)));
- return SUB16(25736, SHR16(spx_atan01(x),1));
- }
-}
-#else
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846 /* pi */
-#endif
-
-#define C1 0.9999932946f
-#define C2 -0.4999124376f
-#define C3 0.0414877472f
-#define C4 -0.0012712095f
-
-
-#define SPX_PI_2 1.5707963268
-spx_word16_t spx_cos(spx_word16_t x)
-{
- if (x<SPX_PI_2)
- {
- x *= x;
- return C1 + x*(C2+x*(C3+C4*x));
- } else {
- x = M_PI-x;
- x *= x;
- return NEG16(C1 + x*(C2+x*(C3+C4*x)));
- }
-}
-
-#endif
diff --git a/apps/codecs/libspeex/math_approx.h b/apps/codecs/libspeex/math_approx.h
index 49cfda6ebe..8421d634bb 100644
--- a/apps/codecs/libspeex/math_approx.h
+++ b/apps/codecs/libspeex/math_approx.h
@@ -37,19 +37,7 @@
#include "misc.h"
-spx_word16_t spx_cos(spx_word16_t x);
-spx_int16_t spx_ilog2(spx_uint32_t x);
-spx_int16_t spx_ilog4(spx_uint32_t x);
-#ifdef FIXED_POINT
-spx_word16_t spx_sqrt(spx_word32_t x);
-spx_word16_t spx_acos(spx_word16_t x);
-spx_word32_t spx_exp(spx_word16_t x);
-spx_word16_t spx_cos_norm(spx_word32_t x);
-
-/* Input in Q15, output in Q14 */
-spx_word16_t spx_atan(spx_word32_t x);
-
-#else
+#ifndef FIXED_POINT
#define spx_sqrt sqrt
#define spx_acos acos
@@ -59,4 +47,265 @@ spx_word16_t spx_atan(spx_word32_t x);
#endif
+
+
+static inline spx_int16_t spx_ilog2(spx_uint32_t x)
+{
+ int r=0;
+ if (x>=(spx_int32_t)65536)
+ {
+ x >>= 16;
+ r += 16;
+ }
+ if (x>=256)
+ {
+ x >>= 8;
+ r += 8;
+ }
+ if (x>=16)
+ {
+ x >>= 4;
+ r += 4;
+ }
+ if (x>=4)
+ {
+ x >>= 2;
+ r += 2;
+ }
+ if (x>=2)
+ {
+ r += 1;
+ }
+ return r;
+}
+
+static inline spx_int16_t spx_ilog4(spx_uint32_t x)
+{
+ int r=0;
+ if (x>=(spx_int32_t)65536)
+ {
+ x >>= 16;
+ r += 8;
+ }
+ if (x>=256)
+ {
+ x >>= 8;
+ r += 4;
+ }
+ if (x>=16)
+ {
+ x >>= 4;
+ r += 2;
+ }
+ if (x>=4)
+ {
+ r += 1;
+ }
+ return r;
+}
+
+#ifdef FIXED_POINT
+
+/* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25723*x^3 (for .25 < x < 1) */
+/*#define C0 3634
+#define C1 21173
+#define C2 -12627
+#define C3 4215*/
+
+/* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25659*x^3 (for .25 < x < 1) */
+#define C0 3634
+#define C1 21173
+#define C2 -12627
+#define C3 4204
+
+static inline spx_word16_t spx_sqrt(spx_word32_t x)
+{
+ int k;
+ spx_word32_t rt;
+ k = spx_ilog4(x)-6;
+ x = VSHR32(x, (k<<1));
+ rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
+ rt = VSHR32(rt,7-k);
+ return rt;
+}
+
+/* log(x) ~= -2.18151 + 4.20592*x - 2.88938*x^2 + 0.86535*x^3 (for .5 < x < 1) */
+
+
+#define A1 16469
+#define A2 2242
+#define A3 1486
+
+static inline spx_word16_t spx_acos(spx_word16_t x)
+{
+ int s=0;
+ spx_word16_t ret;
+ spx_word16_t sq;
+ if (x<0)
+ {
+ s=1;
+ x = NEG16(x);
+ }
+ x = SUB16(16384,x);
+
+ x = x >> 1;
+ sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3))))));
+ ret = spx_sqrt(SHL32(EXTEND32(sq),13));
+
+ /*ret = spx_sqrt(67108864*(-1.6129e-04 + 2.0104e+00*f + 2.7373e-01*f*f + 1.8136e-01*f*f*f));*/
+ if (s)
+ ret = SUB16(25736,ret);
+ return ret;
+}
+
+
+#define K1 8192
+#define K2 -4096
+#define K3 340
+#define K4 -10
+
+static inline spx_word16_t spx_cos(spx_word16_t x)
+{
+ spx_word16_t x2;
+
+ if (x<12868)
+ {
+ x2 = MULT16_16_P13(x,x);
+ return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
+ } else {
+ x = SUB16(25736,x);
+ x2 = MULT16_16_P13(x,x);
+ return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
+ }
+}
+
+#define L1 32767
+#define L2 -7651
+#define L3 8277
+#define L4 -626
+
+static inline spx_word16_t _spx_cos_pi_2(spx_word16_t x)
+{
+ spx_word16_t x2;
+
+ x2 = MULT16_16_P15(x,x);
+ return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2))))))));
+}
+
+static inline spx_word16_t spx_cos_norm(spx_word32_t x)
+{
+ x = x&0x0001ffff;
+ if (x>SHL32(EXTEND32(1), 16))
+ x = SUB32(SHL32(EXTEND32(1), 17),x);
+ if (x&0x00007fff)
+ {
+ if (x<SHL32(EXTEND32(1), 15))
+ {
+ return _spx_cos_pi_2(EXTRACT16(x));
+ } else {
+ return NEG32(_spx_cos_pi_2(EXTRACT16(65536-x)));
+ }
+ } else {
+ if (x&0x0000ffff)
+ return 0;
+ else if (x&0x0001ffff)
+ return -32767;
+ else
+ return 32767;
+ }
+}
+
+/*
+ K0 = 1
+ K1 = log(2)
+ K2 = 3-4*log(2)
+ K3 = 3*log(2) - 2
+*/
+#define D0 16384
+#define D1 11356
+#define D2 3726
+#define D3 1301
+/* Input in Q11 format, output in Q16 */
+static inline spx_word32_t spx_exp2(spx_word16_t x)
+{
+ int integer;
+ spx_word16_t frac;
+ integer = SHR16(x,11);
+ if (integer>14)
+ return 0x7fffffff;
+ else if (integer < -15)
+ return 0;
+ frac = SHL16(x-SHL16(integer,11),3);
+ frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
+ return VSHR32(EXTEND32(frac), -integer-2);
+}
+
+/* Input in Q11 format, output in Q16 */
+static inline spx_word32_t spx_exp(spx_word16_t x)
+{
+ if (x>21290)
+ return 0x7fffffff;
+ else if (x<-21290)
+ return 0;
+ else
+ return spx_exp2(MULT16_16_P14(23637,x));
+}
+#define M1 32767
+#define M2 -21
+#define M3 -11943
+#define M4 4936
+
+static inline spx_word16_t spx_atan01(spx_word16_t x)
+{
+ return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x)))))));
+}
+
+#undef M1
+#undef M2
+#undef M3
+#undef M4
+
+/* Input in Q15, output in Q14 */
+static inline spx_word16_t spx_atan(spx_word32_t x)
+{
+ if (x <= 32767)
+ {
+ return SHR16(spx_atan01(x),1);
+ } else {
+ int e = spx_ilog2(x);
+ if (e>=29)
+ return 25736;
+ x = DIV32_16(SHL32(EXTEND32(32767),29-e), EXTRACT16(SHR32(x, e-14)));
+ return SUB16(25736, SHR16(spx_atan01(x),1));
+ }
+}
+#else
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846 /* pi */
+#endif
+
+#define C1 0.9999932946f
+#define C2 -0.4999124376f
+#define C3 0.0414877472f
+#define C4 -0.0012712095f
+
+
+#define SPX_PI_2 1.5707963268
+static inline spx_word16_t spx_cos(spx_word16_t x)
+{
+ if (x<SPX_PI_2)
+ {
+ x *= x;
+ return C1 + x*(C2+x*(C3+C4*x));
+ } else {
+ x = M_PI-x;
+ x *= x;
+ return NEG16(C1 + x*(C2+x*(C3+C4*x)));
+ }
+}
+
+#endif
+
+
#endif
diff --git a/apps/codecs/libspeex/mdf.c b/apps/codecs/libspeex/mdf.c
index 2fe3bd08fd..e9ea0fadba 100644
--- a/apps/codecs/libspeex/mdf.c
+++ b/apps/codecs/libspeex/mdf.c
@@ -368,7 +368,7 @@ static void dump_audio(const spx_int16_t *rec, const spx_int16_t *play, const sp
{
if (!(rFile && pFile && oFile))
{
- speex_error("Dump files not open");
+ speex_fatal("Dump files not open");
}
fwrite(rec, sizeof(spx_int16_t), len, rFile);
fwrite(play, sizeof(spx_int16_t), len, pFile);
@@ -384,10 +384,10 @@ SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length)
#ifdef DUMP_ECHO_CANCEL_DATA
if (rFile || pFile || oFile)
- speex_error("Opening dump files twice");
- rFile = fopen("aec_rec.sw", "w");
- pFile = fopen("aec_play.sw", "w");
- oFile = fopen("aec_out.sw", "w");
+ speex_fatal("Opening dump files twice");
+ rFile = fopen("aec_rec.sw", "wb");
+ pFile = fopen("aec_play.sw", "wb");
+ oFile = fopen("aec_out.sw", "wb");
#endif
st->frame_size = frame_size;
@@ -635,13 +635,13 @@ void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play)
}
}
-/** Performs echo cancellation on a frame */
+/** Performs echo cancellation on a frame (deprecated, last arg now ignored) */
void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *in, const spx_int16_t *far_end, spx_int16_t *out, spx_int32_t *Yout)
{
speex_echo_cancellation(st, in, far_end, out);
}
-/** Performs echo cancellation on a frame (deprecated, last arg now ignored) */
+/** Performs echo cancellation on a frame */
void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const spx_int16_t *far_end, spx_int16_t *out)
{
int i,j;
diff --git a/apps/codecs/libspeex/misc.c b/apps/codecs/libspeex/misc.c
index ae6869781d..e33b910850 100644
--- a/apps/codecs/libspeex/misc.c
+++ b/apps/codecs/libspeex/misc.c
@@ -47,124 +47,3 @@
#include "misc_bfin.h"
#endif
-#ifndef RELEASE
-void print_vec(float *vec, int len, char *name)
-{
- int i;
- printf ("%s ", name);
- for (i=0;i<len;i++)
- printf (" %f", vec[i]);
- printf ("\n");
-}
-#endif
-
-#ifdef FIXED_DEBUG
-long long spx_mips=0;
-#endif
-
-
-#ifndef OVERRIDE_SPEEX_ALLOC
-void *speex_alloc (int size)
-{
- return calloc(size,1);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH
-void *speex_alloc_scratch (int size)
-{
- return calloc(size,1);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_REALLOC
-void *speex_realloc (void *ptr, int size)
-{
- return realloc(ptr, size);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_FREE
-void speex_free (void *ptr)
-{
- free(ptr);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_FREE_SCRATCH
-void speex_free_scratch (void *ptr)
-{
- free(ptr);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_MOVE
-void *speex_move (void *dest, void *src, int n)
-{
- return memmove(dest,src,n);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_ERROR
-void speex_error(const char *str)
-{
- fprintf (stderr, "Fatal (internal) error: %s\n", str);
- exit(1);
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_WARNING
-void speex_warning(const char *str)
-{
-#ifndef DISABLE_WARNINGS
- fprintf (stderr, "warning: %s\n", str);
-#endif
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_WARNING_INT
-void speex_warning_int(const char *str, int val)
-{
-#ifndef DISABLE_WARNINGS
- fprintf (stderr, "warning: %s %d\n", str, val);
-#endif
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_NOTIFY
-void speex_notify(const char *str)
-{
-#ifndef DISABLE_NOTIFICATIONS
- fprintf (stderr, "notification: %s\n", str);
-#endif
-}
-#endif
-
-#ifdef FIXED_POINT
-spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)
-{
- spx_word32_t res;
- *seed = 1664525 * *seed + 1013904223;
- res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
- return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
-}
-#else
-spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)
-{
- const unsigned int jflone = 0x3f800000;
- const unsigned int jflmsk = 0x007fffff;
- union {int i; float f;} ran;
- *seed = 1664525 * *seed + 1013904223;
- ran.i = jflone | (jflmsk & *seed);
- ran.f -= 1.5;
- return 3.4642*std*ran.f;
-}
-#endif
-
-#ifndef OVERRIDE_SPEEX_PUTC
-void _speex_putc(int ch, void *file)
-{
- FILE *f = (FILE *)file;
- fprintf(f, "%c", ch);
-}
-#endif
diff --git a/apps/codecs/libspeex/misc.h b/apps/codecs/libspeex/misc.h
index 1664aaed9d..8702919b7b 100644
--- a/apps/codecs/libspeex/misc.h
+++ b/apps/codecs/libspeex/misc.h
@@ -35,6 +35,8 @@
#ifndef MISC_H
#define MISC_H
+#include "config-speex.h"
+
#ifndef SPEEX_VERSION
#define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */
#define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */
@@ -69,16 +71,14 @@
#endif
#include "arch.h"
-
-#ifndef RELEASE
-/** Print a named vector to stdout */
-void print_vec(float *vec, int len, char *name);
-#endif
+#include "rockbox.h"
/** Convert little endian */
static inline spx_int32_t le_int(spx_int32_t i)
{
-#if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
+#if 1
+ return letoh32(i);
+#elif !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
spx_uint32_t ui, ret;
ui = i;
ret = ui>>24;
@@ -91,40 +91,138 @@ static inline spx_int32_t le_int(spx_int32_t i)
#endif
}
+#define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__);
+#define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}}
+
+#ifndef RELEASE
+static void print_vec(float *vec, int len, char *name)
+{
+ int i;
+ printf ("%s ", name);
+ for (i=0;i<len;i++)
+ printf (" %f", vec[i]);
+ printf ("\n");
+}
+#endif
+
+#ifdef FIXED_DEBUG
+long long spx_mips=0;
+#endif
+
+
/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */
-void *speex_alloc (int size);
+#ifndef OVERRIDE_SPEEX_ALLOC
+static inline void *speex_alloc (int size)
+{
+ return calloc(size,1);
+}
+#endif
/** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
-void *speex_alloc_scratch (int size);
+#ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH
+static inline void *speex_alloc_scratch (int size)
+{
+ return calloc(size,1);
+}
+#endif
/** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */
-void *speex_realloc (void *ptr, int size);
+#ifndef OVERRIDE_SPEEX_REALLOC
+static inline void *speex_realloc (void *ptr, int size)
+{
+ return realloc(ptr, size);
+}
+#endif
/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */
-void speex_free (void *ptr);
+#ifndef OVERRIDE_SPEEX_FREE
+static inline void speex_free (void *ptr)
+{
+ free(ptr);
+}
+#endif
-/** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
-void speex_free_scratch (void *ptr);
+/** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
+#ifndef OVERRIDE_SPEEX_FREE_SCRATCH
+static inline void speex_free_scratch (void *ptr)
+{
+ free(ptr);
+}
+#endif
-/** Speex wrapper for mem_move */
-void *speex_move (void *dest, void *src, int n);
+/** Print warning message with integer argument to stderr */
+#ifndef OVERRIDE_SPEEX_MOVE
+static inline void *speex_move (void *dest, void *src, int n)
+{
+ return memmove(dest,src,n);
+}
+#endif
-/** Abort with an error message to stderr (internal Speex error) */
-void speex_error(const char *str);
+#ifndef OVERRIDE_SPEEX_FATAL
+static inline void _speex_fatal(const char *str, const char *file, int line)
+{
+ fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
+ exit(1);
+}
+#endif
-/** Print warning message to stderr (programming error) */
-void speex_warning(const char *str);
+#ifndef OVERRIDE_SPEEX_WARNING
+static inline void speex_warning(const char *str)
+{
+#ifndef DISABLE_WARNINGS
+ fprintf (stderr, "warning: %s\n", str);
+#endif
+}
+#endif
-/** Print warning message with integer argument to stderr */
-void speex_warning_int(const char *str, int val);
+#ifndef OVERRIDE_SPEEX_WARNING_INT
+static inline void speex_warning_int(const char *str, int val)
+{
+#ifndef DISABLE_WARNINGS
+ fprintf (stderr, "warning: %s %d\n", str, val);
+#endif
+}
+#endif
-/** Print notification message to stderr */
-void speex_notify(const char *str);
+#ifndef OVERRIDE_SPEEX_NOTIFY
+static inline void speex_notify(const char *str)
+{
+#ifndef DISABLE_NOTIFICATIONS
+ fprintf (stderr, "notification: %s\n", str);
+#endif
+}
+#endif
-/** Generate a random number */
-spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed);
+#ifdef FIXED_POINT
+/** Generate a pseudo-random number */
+static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)
+{
+ spx_word32_t res;
+ *seed = 1664525 * *seed + 1013904223;
+ res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
+ return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
+}
+#else
+/** Generate a pseudo-random number */
+static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)
+{
+ const unsigned int jflone = 0x3f800000;
+ const unsigned int jflmsk = 0x007fffff;
+ union {int i; float f;} ran;
+ *seed = 1664525 * *seed + 1013904223;
+ ran.i = jflone | (jflmsk & *seed);
+ ran.f -= 1.5;
+ return 3.4642*std*ran.f;
+}
+#endif
+#ifndef OVERRIDE_SPEEX_PUTC
/** Speex wrapper for putc */
-void _speex_putc(int ch, void *file);
+static inline void _speex_putc(int ch, void *file)
+{
+ FILE *f = (FILE *)file;
+ fprintf(f, "%c", ch);
+}
+#endif
#endif
diff --git a/apps/codecs/libspeex/modes.h b/apps/codecs/libspeex/modes.h
index 5bf1971c21..730c80fb07 100644
--- a/apps/codecs/libspeex/modes.h
+++ b/apps/codecs/libspeex/modes.h
@@ -98,7 +98,7 @@ typedef struct SpeexSubmode {
lsp_quant_func lsp_quant; /**< LSP quantization function */
lsp_unquant_func lsp_unquant; /**< LSP unquantization function */
- /*Lont-term predictor functions*/
+ /*Long-term predictor functions*/
ltp_quant_func ltp_quant; /**< Long-term predictor (pitch) quantizer */
ltp_unquant_func ltp_unquant; /**< Long-term predictor (pitch) un-quantizer */
const void *ltp_params; /**< Pitch parameters (options) */
diff --git a/apps/codecs/libspeex/nb_celp.c b/apps/codecs/libspeex/nb_celp.c
index a2da760156..64ecb58689 100644
--- a/apps/codecs/libspeex/nb_celp.c
+++ b/apps/codecs/libspeex/nb_celp.c
@@ -209,7 +209,7 @@ void *nb_encoder_init(const SpeexMode *m)
st->highpass_enabled = 1;
#ifdef ENABLE_VALGRIND
- VALGRIND_MAKE_READABLE(st, (st->stack-(char*)st));
+ VALGRIND_MAKE_READABLE(st, NB_ENC_STACK);
#endif
return st;
}
@@ -355,7 +355,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
/*Open-loop pitch*/
- if (st->complexity>2 || !st->submodes[st->submodeID] || st->vbr_enabled || st->vad_enabled || SUBMODE(forced_pitch_gain) ||
+ if (!st->submodes[st->submodeID] || (st->complexity>2 && SUBMODE(have_subframe_gain)<3) || st->vbr_enabled || st->vad_enabled || SUBMODE(forced_pitch_gain) ||
SUBMODE(lbr_pitch) != -1)
{
int nol_pitch[6];
@@ -440,7 +440,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
#endif
{
spx_word16_t g = compute_rms16(st->exc, st->frameSize);
- if (ol_pitch>0)
+ if (st->submodeID!=1 && ol_pitch>0)
ol_gain = MULT16_16(g, MULT16_16_Q14(QCONST16(1.1,14),
spx_sqrt(QCONST32(1.,28)-MULT16_32_Q15(QCONST16(.8,15),SHL32(MULT16_16(ol_pitch_coef,ol_pitch_coef),16)))));
else
@@ -787,18 +787,15 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
/*print_vec(st->bw_lpc1, 10, "bw_lpc");*/
#endif
+ /*FIXME: This will break if we change the window size */
+ speex_assert(st->windowSize-st->frameSize == st->subframeSize);
+ if (sub==0)
{
- /*FIXME: This will break if we change the window size */
- if (st->windowSize-st->frameSize != st->subframeSize)
- speex_error("windowSize-frameSize != subframeSize");
- if (sub==0)
- {
- for (i=0;i<st->subframeSize;i++)
- real_exc[i] = sw[i] = st->winBuf[i];
- } else {
- for (i=0;i<st->subframeSize;i++)
- real_exc[i] = sw[i] = in[i+((sub-1)*st->subframeSize)];
- }
+ for (i=0;i<st->subframeSize;i++)
+ real_exc[i] = sw[i] = st->winBuf[i];
+ } else {
+ for (i=0;i<st->subframeSize;i++)
+ real_exc[i] = sw[i] = in[i+((sub-1)*st->subframeSize)];
}
fir_mem16(real_exc, interp_qlpc, real_exc, st->subframeSize, st->lpcSize, st->mem_exc2, stack);
@@ -845,7 +842,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
exc[i]=0;
/* If we have a long-term predictor (otherwise, something's wrong) */
- if (SUBMODE(ltp_quant))
+ speex_assert (SUBMODE(ltp_quant));
{
int pit_min, pit_max;
/* Long-term prediction */
@@ -894,10 +891,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
#endif
st->pitch[sub]=pitch;
- } else {
- speex_error ("No pitch prediction, what's wrong");
}
-
/* Quantization of innovation */
for (i=0;i<st->subframeSize;i++)
innov[i]=0;
@@ -944,7 +938,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
signal_div(target, target, ener, st->subframeSize);
/* Quantize innovation */
- if (SUBMODE(innovation_quant))
+ speex_assert (SUBMODE(innovation_quant));
{
/* Codebook search */
SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2,
@@ -980,11 +974,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
{
st->innov_rms_save[sub] = compute_rms(innov, st->subframeSize);
}
- } else {
- speex_error("No fixed codebook");
}
-
for (i=0;i<st->subframeSize;i++)
sw[i] = exc[i];
/* Final signal synthesis from excitation */
@@ -1101,7 +1092,7 @@ void *nb_decoder_init(const SpeexMode *m)
st->highpass_enabled = 1;
#ifdef ENABLE_VALGRIND
- VALGRIND_MAKE_READABLE(st, (st->stack-(char*)st));
+ VALGRIND_MAKE_READABLE(st, NB_DEC_STACK);
#endif
return st;
}
@@ -1330,10 +1321,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
ALLOC(lpc, st->lpcSize, spx_coef_t);
bw_lpc(QCONST16(0.93f,15), st->interp_qlpc, lpc, st->lpcSize);
{
- float innov_gain=0;
- float pgain=GAIN_SCALING_1*st->last_pitch_gain;
- if (pgain>.6)
- pgain=.6;
+ spx_word16_t innov_gain=0;
/* FIXME: This was innov, not exc */
innov_gain = compute_rms16(st->exc, st->frameSize);
for (i=0;i<st->frameSize;i++)
@@ -1477,7 +1465,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
exc[i]=0;
/*Adaptive codebook contribution*/
- if (SUBMODE(ltp_unquant))
+ speex_assert (SUBMODE(ltp_unquant));
{
int pit_min, pit_max;
/* Handle pitch constraints if any */
@@ -1542,8 +1530,6 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
if (tmp > best_pitch_gain)
best_pitch_gain = tmp;
}
- } else {
- speex_error("No pitch prediction, what's wrong");
}
/* Unquantize the innovation */
@@ -1567,7 +1553,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
ener = ol_gain;
}
- if (SUBMODE(innovation_unquant))
+ speex_assert (SUBMODE(innovation_unquant));
{
/*Fixed codebook contribution*/
SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed);
@@ -1599,39 +1585,40 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
for (i=0;i<st->subframeSize;i++)
innov_save[i] = EXTRACT16(PSHR32(innov[i], SIG_SHIFT));
}
- } else {
- speex_error("No fixed codebook");
}
/*Vocoder mode*/
if (st->submodeID==1)
{
- float g=ol_pitch_coef*GAIN_SCALING_1;
-
+ spx_word16_t g=ol_pitch_coef;
+ g=MULT16_16_P14(QCONST16(1.5f,14),(g-QCONST16(.2f,6)));
+ if (g<0)
+ g=0;
+ if (g>GAIN_SCALING)
+ g=GAIN_SCALING;
for (i=0;i<st->subframeSize;i++)
exc[i]=0;
while (st->voc_offset<st->subframeSize)
{
+ /* exc[st->voc_offset]= g*sqrt(2*ol_pitch)*ol_gain;
+ Not quite sure why we need the factor of two in the sqrt */
if (st->voc_offset>=0)
- exc[st->voc_offset]=sqrt(1.0*ol_pitch);
+ exc[st->voc_offset]=MULT16_16(spx_sqrt(MULT16_16_16(2,ol_pitch)),EXTRACT16(PSHR32(MULT16_16(g,PSHR32(ol_gain,SIG_SHIFT)),6)));
st->voc_offset+=ol_pitch;
}
st->voc_offset -= st->subframeSize;
-
- g=.5+2*(g-.6);
- if (g<0)
- g=0;
- if (g>1)
- g=1;
+
for (i=0;i<st->subframeSize;i++)
{
spx_word16_t exci=exc[i];
- /* FIXME: cleanup the innov[i]/SIG_SCALING */
- exc[i]=.8*g*exc[i]*PSHR32(ol_gain,SIG_SHIFT) + .6*g*st->voc_m1*PSHR32(ol_gain,SIG_SHIFT) + (1-.5*g)*PSHR32(innov[i],SIG_SHIFT) - .5*g*PSHR32(st->voc_m2,SIG_SHIFT);
+ exc[i]= ADD16(ADD16(MULT16_16_Q15(QCONST16(.7f,15),exc[i]) , MULT16_16_Q15(QCONST16(.3f,15),st->voc_m1)),
+ SUB16(MULT16_16_Q15(Q15_ONE-MULT16_16_16(QCONST16(.85f,9),g),EXTRACT16(PSHR32(innov[i],SIG_SHIFT))),
+ MULT16_16_Q15(MULT16_16_16(QCONST16(.15f,9),g),EXTRACT16(PSHR32(st->voc_m2,SIG_SHIFT)))
+ ));
st->voc_m1 = exci;
st->voc_m2=innov[i];
- st->voc_mean = .95*st->voc_mean + .05*exc[i];
+ st->voc_mean = EXTRACT16(PSHR32(ADD32(MULT16_16(QCONST16(.8f,15),st->voc_mean), MULT16_16(QCONST16(.2f,15),exc[i])), 15));
exc[i]-=st->voc_mean;
}
}
diff --git a/apps/codecs/libspeex/nb_celp.h b/apps/codecs/libspeex/nb_celp.h
index cc91b1c4fe..fe30d38669 100644
--- a/apps/codecs/libspeex/nb_celp.h
+++ b/apps/codecs/libspeex/nb_celp.h
@@ -172,7 +172,7 @@ typedef struct DecState {
/*Vocoder data*/
spx_word16_t voc_m1;
spx_word32_t voc_m2;
- float voc_mean;
+ spx_word16_t voc_mean;
int voc_offset;
int dtx_enabled;
diff --git a/apps/codecs/libspeex/preprocess.c b/apps/codecs/libspeex/preprocess.c
index 7e7f106b55..a720e88479 100644
--- a/apps/codecs/libspeex/preprocess.c
+++ b/apps/codecs/libspeex/preprocess.c
@@ -215,7 +215,7 @@ struct SpeexPreprocessState_ {
spx_word32_t *S; /**< Smoothed power spectrum */
spx_word32_t *Smin; /**< See Cohen paper */
spx_word32_t *Stmp; /**< See Cohen paper */
- int *update_prob; /**< Propability of speech presence for noise update */
+ int *update_prob; /**< Probability of speech presence for noise update */
spx_word16_t *zeta; /**< Smoothed a priori SNR */
spx_word32_t *echo_noise;
@@ -737,6 +737,8 @@ int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x)
spx_word16_t effective_echo_suppress;
st->nb_adapt++;
+ if (st->nb_adapt>20000)
+ st->nb_adapt = 20000;
st->min_count++;
beta = MAX16(QCONST16(.03,15),DIV32_16(Q15_ONE,st->nb_adapt));
diff --git a/apps/codecs/libspeex/pseudofloat.h b/apps/codecs/libspeex/pseudofloat.h
index 05542f1d7f..9d588642a8 100644
--- a/apps/codecs/libspeex/pseudofloat.h
+++ b/apps/codecs/libspeex/pseudofloat.h
@@ -59,6 +59,10 @@ static const spx_float_t FLOAT_ZERO = {0,0};
static const spx_float_t FLOAT_ONE = {16384,-14};
static const spx_float_t FLOAT_HALF = {16384,-15};
+#ifdef MIN
+#undef MIN
+#endif
+#define MIN(a,b) ((a)<(b)?(a):(b))
static inline spx_float_t PSEUDOFLOAT(spx_int32_t x)
{
int e=0;
diff --git a/apps/codecs/libspeex/quant_lsp.c b/apps/codecs/libspeex/quant_lsp.c
index 472efa95a6..b2f4f85497 100644
--- a/apps/codecs/libspeex/quant_lsp.c
+++ b/apps/codecs/libspeex/quant_lsp.c
@@ -304,11 +304,11 @@ void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
#ifdef DISABLE_WIDEBAND
void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
}
void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
}
#else
extern const signed char high_lsp_cdbk[];
diff --git a/apps/codecs/libspeex/resample.c b/apps/codecs/libspeex/resample.c
index 2dfe2dd5f3..51270c572d 100644
--- a/apps/codecs/libspeex/resample.c
+++ b/apps/codecs/libspeex/resample.c
@@ -37,17 +37,23 @@
- Low memory requirement
- Good *perceptual* quality (and not best SNR)
- The code is working, but it's in a very early stage, so it may have
- artifacts, noise or subliminal messages from satan. Also, the API
- isn't stable and I can actually promise that I *will* change the API
- some time in the future.
+ Warning: This resampler is relatively new. Although I think I got rid of
+ all the major bugs and I don't expect the API to change anymore, there
+ may be something I've missed. So use with caution.
-TODO list:
- - Variable calculation resolution depending on quality setting
- - Single vs double in float mode
- - 16-bit vs 32-bit (sinc only) in fixed-point mode
- - Make sure the filter update works even when changing params
- after only a few samples procesed
+ This algorithm is based on this original resampling algorithm:
+ Smith, Julius O. Digital Audio Resampling Home Page
+ Center for Computer Research in Music and Acoustics (CCRMA),
+ Stanford University, 2007.
+ Web published at http://www-ccrma.stanford.edu/~jos/resample/.
+
+ There is one main difference, though. This resampler uses cubic
+ interpolation instead of linear interpolation in the above paper. This
+ makes the table much smaller and makes it possible to compute that table
+ on a per-stream basis. In turn, being able to tweak the table for each
+ stream makes it possible to both reduce complexity on simple ratios
+ (e.g. 2/3), and get rid of the rounding operations in the inner loop.
+ The latter both reduces CPU time and makes the algorithm more SIMD-friendly.
*/
#ifdef HAVE_CONFIG_H
@@ -84,6 +90,7 @@ static void speex_free (void *ptr) {free(ptr);}
#define OVERSAMPLE 8
#define IMAX(a,b) ((a) > (b) ? (a) : (b))
+#define IMIN(a,b) ((a) < (b) ? (a) : (b))
#ifndef NULL
#define NULL 0
@@ -576,10 +583,10 @@ static void update_filter(SpeexResamplerState *st)
}
for (i=0;i<st->den_rate;i++)
{
- spx_uint32_t j;
+ spx_int32_t j;
for (j=0;j<st->filt_len;j++)
{
- 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);
+ st->sinc_table[i*st->filt_len+j] = sinc(st->cutoff,((j-(spx_int32_t)st->filt_len/2+1)-((float)i)/st->den_rate), st->filt_len, quality_map[st->quality].window_func);
}
}
#ifdef FIXED_POINT
@@ -997,16 +1004,19 @@ void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_rate, sp
int 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)
{
- int fact;
+ spx_uint32_t fact;
+ spx_uint32_t old_den;
+ spx_uint32_t i;
if (st->in_rate == in_rate && st->out_rate == out_rate && st->num_rate == ratio_num && st->den_rate == ratio_den)
return RESAMPLER_ERR_SUCCESS;
+ old_den = st->den_rate;
st->in_rate = in_rate;
st->out_rate = out_rate;
st->num_rate = ratio_num;
st->den_rate = ratio_den;
/* FIXME: This is terribly inefficient, but who cares (at least for now)? */
- for (fact=2;fact<=sqrt(IMAX(in_rate, out_rate));fact++)
+ for (fact=2;fact<=IMIN(st->num_rate, st->den_rate);fact++)
{
while ((st->num_rate % fact == 0) && (st->den_rate % fact == 0))
{
@@ -1015,6 +1025,17 @@ int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_nu
}
}
+ if (old_den > 0)
+ {
+ for (i=0;i<st->nb_channels;i++)
+ {
+ st->samp_frac_num[i]=st->samp_frac_num[i]*st->den_rate/old_den;
+ /* Safety net */
+ if (st->samp_frac_num[i] >= st->den_rate)
+ st->samp_frac_num[i] = st->den_rate-1;
+ }
+ }
+
if (st->initialised)
update_filter(st);
return RESAMPLER_ERR_SUCCESS;
diff --git a/apps/codecs/libspeex/rockbox.c b/apps/codecs/libspeex/rockbox.c
index 89af3cba5d..2abf8ccb32 100644
--- a/apps/codecs/libspeex/rockbox.c
+++ b/apps/codecs/libspeex/rockbox.c
@@ -19,8 +19,6 @@
#include "../codec.h"
#include "../lib/codeclib.h"
-extern struct codec_api* ci;
-
#if defined(DEBUG) || defined(SIMULATOR)
#undef DEBUGF
#define DEBUGF ci->debugf
@@ -35,62 +33,7 @@ extern struct codec_api* ci;
#define LOGF(...)
#endif
-void *speex_alloc (int size)
-{
- return codec_calloc(size, 1);
-}
-
-void *speex_alloc_scratch (int size)
-{
- return codec_calloc(size,1);
-}
-
-void *speex_realloc (void *ptr, int size)
-{
- return codec_realloc(ptr, size);
-}
-
-void speex_free (void *ptr)
-{
- codec_free(ptr);
-}
-
-void speex_free_scratch (void *ptr)
-{
- codec_free(ptr);
-}
-
-void *speex_move (void *dest, void *src, int n)
-{
- return memmove(dest,src,n);
-}
-
-void speex_error(const char *str)
-{
- DEBUGF("Fatal error: %s\n", str);
- //exit(1);
-}
-
-void speex_warning(const char *str)
-{
- DEBUGF("warning: %s\n", str);
-}
-
-void speex_warning_int(const char *str, int val)
-{
- DEBUGF("warning: %s %d\n", str, val);
-}
-
-void speex_notify(const char *str)
-{
- DEBUGF("notice: %s\n", str);
-}
-
-void _speex_putc(int ch, void *file)
-{
- //FILE *f = (FILE *)file;
- //printf("%c", ch);
-}
+extern struct codec_api* ci;
float floor(float x) {
return ((float)(((int)x)));
diff --git a/apps/codecs/libspeex/rockbox.h b/apps/codecs/libspeex/rockbox.h
new file mode 100644
index 0000000000..368f1fb2d2
--- /dev/null
+++ b/apps/codecs/libspeex/rockbox.h
@@ -0,0 +1,99 @@
+/**************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2007 Dan Everton
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#ifndef SPEEX_ROCKBOX_H
+#define SPEEX_ROCKBOX_H
+
+#include "../codec.h"
+#include "../lib/codeclib.h"
+
+#if defined(DEBUG) || defined(SIMULATOR)
+#undef DEBUGF
+#define DEBUGF ci->debugf
+#else
+#define DEBUGF(...)
+#endif
+
+#ifdef ROCKBOX_HAS_LOGF
+#undef LOGF
+#define LOGF ci->logf
+#else
+#define LOGF(...)
+#endif
+
+extern struct codec_api* ci;
+
+static inline void *speex_alloc (int size)
+{
+ return codec_calloc(size, 1);
+}
+
+static inline void *speex_alloc_scratch (int size)
+{
+ return codec_calloc(size,1);
+}
+
+static inline void *speex_realloc (void *ptr, int size)
+{
+ return codec_realloc(ptr, size);
+}
+
+static inline void speex_free (void *ptr)
+{
+ codec_free(ptr);
+}
+
+static inline void speex_free_scratch (void *ptr)
+{
+ codec_free(ptr);
+}
+
+static inline void *speex_move (void *dest, void *src, int n)
+{
+ return memmove(dest,src,n);
+}
+
+static inline void _speex_fatal(const char *str, const char *file, int line)
+{
+ DEBUGF("Fatal error: %s\n", str);
+ //exit(1);
+}
+
+static inline void speex_warning(const char *str)
+{
+ DEBUGF("warning: %s\n", str);
+}
+
+static inline void speex_warning_int(const char *str, int val)
+{
+ DEBUGF("warning: %s %d\n", str, val);
+}
+
+static inline void speex_notify(const char *str)
+{
+ DEBUGF("notice: %s\n", str);
+}
+
+static inline void _speex_putc(int ch, void *file)
+{
+ //FILE *f = (FILE *)file;
+ //printf("%c", ch);
+}
+
+#endif
+
diff --git a/apps/codecs/libspeex/sb_celp.c b/apps/codecs/libspeex/sb_celp.c
index 6066c8c51b..c44cfffb58 100644
--- a/apps/codecs/libspeex/sb_celp.c
+++ b/apps/codecs/libspeex/sb_celp.c
@@ -35,7 +35,6 @@
#include <math.h>
#include "sb_celp.h"
-#include "stdlib.h"
#include "filters.h"
#include "lpc.h"
#include "lsp.h"
@@ -47,6 +46,10 @@
#include "misc.h"
#include "math_approx.h"
+#ifndef NULL
+#define NULL 0
+#endif
+
/* Default size for the encoder and decoder stack (can be changed at compile time).
This does not apply when using variable-size arrays or alloca. */
#ifndef SB_ENC_STACK
@@ -61,40 +64,40 @@
#ifdef DISABLE_WIDEBAND
void *sb_encoder_init(const SpeexMode *m)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
return NULL;
}
void sb_encoder_destroy(void *state)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
}
int sb_encode(void *state, void *vin, SpeexBits *bits)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
return -2;
}
void *sb_decoder_init(const SpeexMode *m)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
return NULL;
}
void sb_decoder_destroy(void *state)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
}
int sb_decode(void *state, SpeexBits *bits, void *vout)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
return -2;
}
int sb_encoder_ctl(void *state, int request, void *ptr)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
return -2;
}
int sb_decoder_ctl(void *state, int request, void *ptr)
{
- speex_error("Wideband and Ultra-wideband are disabled");
+ speex_fatal("Wideband and Ultra-wideband are disabled");
return -2;
}
#else
diff --git a/apps/codecs/libspeex/speex/speex.h b/apps/codecs/libspeex/speex/speex.h
index 0ff4be135f..9ac1d2da6c 100644
--- a/apps/codecs/libspeex/speex/speex.h
+++ b/apps/codecs/libspeex/speex/speex.h
@@ -156,7 +156,7 @@ extern "C" {
#define SPEEX_GET_HIGHPASS 45
/** Get "activity level" of the last decoded frame, i.e.
- now much damage we cause if we remove the frame */
+ how much damage we cause if we remove the frame */
#define SPEEX_GET_ACTIVITY 47
diff --git a/apps/codecs/libspeex/speex/speex_callbacks.h b/apps/codecs/libspeex/speex/speex_callbacks.h
index 7892e2f9eb..6f450b3a3a 100644
--- a/apps/codecs/libspeex/speex/speex_callbacks.h
+++ b/apps/codecs/libspeex/speex/speex_callbacks.h
@@ -119,7 +119,7 @@ int speex_std_low_mode_request_handler(SpeexBits *bits, void *state, void *data)
/** Standard handler for VBR request (Set VBR, no questions asked) */
int speex_std_vbr_request_handler(SpeexBits *bits, void *state, void *data);
-/** Standard handler for enhancer request (Turn ehnancer on/off, no questions asked) */
+/** Standard handler for enhancer request (Turn enhancer on/off, no questions asked) */
int speex_std_enh_request_handler(SpeexBits *bits, void *state, void *data);
/** Standard handler for VBR quality request (Set VBR quality, no questions asked) */
diff --git a/apps/codecs/libspeex/speex/speex_echo.h b/apps/codecs/libspeex/speex/speex_echo.h
index 5b5eccd1d5..6fcb0c00d7 100644
--- a/apps/codecs/libspeex/speex/speex_echo.h
+++ b/apps/codecs/libspeex/speex/speex_echo.h
@@ -74,10 +74,10 @@ SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length);
void speex_echo_state_destroy(SpeexEchoState *st);
/** Performs echo cancellation a frame, based on the audio sent to the speaker (no delay is added
- * to playback ni this form)
+ * to playback in this form)
*
* @param st Echo canceller state
- * @param rec signal from the microphone (near end + far end echo)
+ * @param rec Signal from the microphone (near end + far end echo)
* @param play Signal played to the speaker (received from far end)
* @param out Returns near-end signal with echo removed
*/
@@ -89,7 +89,7 @@ void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *rec, const spx_int
/** Perform echo cancellation using internal playback buffer, which is delayed by two frames
* to account for the delay introduced by most soundcards (but it could be off!)
* @param st Echo canceller state
- * @param rec signal from the microphone (near end + far end echo)
+ * @param rec Signal from the microphone (near end + far end echo)
* @param out Returns near-end signal with echo removed
*/
void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out);
diff --git a/apps/codecs/libspeex/speex/speex_jitter.h b/apps/codecs/libspeex/speex/speex_jitter.h
index 570e22b1e2..3f3a43c240 100644
--- a/apps/codecs/libspeex/speex/speex_jitter.h
+++ b/apps/codecs/libspeex/speex/speex_jitter.h
@@ -69,7 +69,7 @@ struct _JitterBufferPacket {
#define JITTER_BUFFER_OK 0
/** Packet is missing */
#define JITTER_BUFFER_MISSING 1
-/** Packet is incomplete (does not cover the entive tick */
+/** Packet is incomplete (does not cover the entire tick */
#define JITTER_BUFFER_INCOMPLETE 2
/** There was an error in the jitter buffer */
#define JITTER_BUFFER_INTERNAL_ERROR -1
@@ -81,10 +81,14 @@ struct _JitterBufferPacket {
#define JITTER_BUFFER_SET_MARGIN 0
/** Get minimum amount of extra buffering required (margin) */
#define JITTER_BUFFER_GET_MARGIN 1
-/* JITTER_BUFFER_SET_AVALIABLE_COUNT wouldn't make sense */
-/** Get the amount of avaliable packets currently buffered */
+/* JITTER_BUFFER_SET_AVAILABLE_COUNT wouldn't make sense */
+/** Get the amount of available packets currently buffered */
+#define JITTER_BUFFER_GET_AVAILABLE_COUNT 3
+/** Included because of an early misspelling (will remove in next release) */
#define JITTER_BUFFER_GET_AVALIABLE_COUNT 3
+
+
#define JITTER_BUFFER_ADJUST_INTERPOLATE -1
#define JITTER_BUFFER_ADJUST_OK 0
#define JITTER_BUFFER_ADJUST_DROP 1
diff --git a/apps/codecs/libspeex/stack_alloc.h b/apps/codecs/libspeex/stack_alloc.h
index cb048fa55e..f9056b472d 100644
--- a/apps/codecs/libspeex/stack_alloc.h
+++ b/apps/codecs/libspeex/stack_alloc.h
@@ -36,11 +36,15 @@
#define STACK_ALLOC_H
#ifdef USE_ALLOCA
-#ifdef WIN32
-#include <malloc.h>
-#else
-#include <alloca.h>
-#endif
+# ifdef WIN32
+# include <malloc.h>
+# else
+# ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# include <stdlib.h>
+# endif
+# endif
#endif
/**
diff --git a/apps/codecs/libspeex/vorbis_psy.h b/apps/codecs/libspeex/vorbis_psy.h
index fbdb7c5506..6871057753 100644
--- a/apps/codecs/libspeex/vorbis_psy.h
+++ b/apps/codecs/libspeex/vorbis_psy.h
@@ -39,7 +39,7 @@
#define NOISE_COMPAND_LEVELS 40
-#define todB(x) ((x)==0?-400.f:log((x)*(x))*4.34294480f)
+#define todB(x) ((x)>1e-13?log((x)*(x))*4.34294480f:-30)
#define fromdB(x) (exp((x)*.11512925f))
/* The bark scale equations are approximations, since the original