summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorThom Johansen <thomj@rockbox.org>2007-11-24 19:14:29 +0000
committerThom Johansen <thomj@rockbox.org>2007-11-24 19:14:29 +0000
commit929443cca52e53696d776661af42d5737a0af10d (patch)
treefe118429b9c1467b721fe2e1cab5b7ae4a0fa873 /apps/codecs
parentd6e22443c4406d94038fdf19955371d38e2ab71f (diff)
Sync to SVN.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15792 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/libspeex/arch.h4
-rw-r--r--apps/codecs/libspeex/bits.c8
-rw-r--r--apps/codecs/libspeex/cb_search.c11
-rw-r--r--apps/codecs/libspeex/jitter.c194
-rw-r--r--apps/codecs/libspeex/kiss_fft.c2
-rw-r--r--apps/codecs/libspeex/ltp.c27
-rw-r--r--apps/codecs/libspeex/mdf.c2
-rw-r--r--apps/codecs/libspeex/nb_celp.c79
-rw-r--r--apps/codecs/libspeex/os_support.h22
-rw-r--r--apps/codecs/libspeex/resample.c79
-rw-r--r--apps/codecs/libspeex/rockbox.h6
-rw-r--r--apps/codecs/libspeex/sb_celp.c21
-rw-r--r--apps/codecs/libspeex/speex/speex_jitter.h13
-rw-r--r--apps/codecs/libspeex/speex_header.c4
14 files changed, 247 insertions, 225 deletions
diff --git a/apps/codecs/libspeex/arch.h b/apps/codecs/libspeex/arch.h
index 9db16ff34d..9f81e0c51e 100644
--- a/apps/codecs/libspeex/arch.h
+++ b/apps/codecs/libspeex/arch.h
@@ -42,7 +42,7 @@
#define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */
#define SPEEX_MICRO_VERSION 15 /**< Micro Speex version. */
#define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */
-#define SPEEX_VERSION "speex-1.2beta3" /**< Speex version string. */
+#define SPEEX_VERSION "speex-1.2beta4" /**< Speex version string. */
#endif
/* A couple test to catch stupid option combinations */
@@ -127,8 +127,6 @@ typedef spx_word32_t spx_sig_t;
#include "fixed_arm5e.h"
#elif defined (ARM4_ASM)
#include "fixed_arm4.h"
-#elif defined (ARM5E_ASM)
-#include "fixed_arm5e.h"
#elif defined (BFIN_ASM)
#include "fixed_bfin.h"
#endif
diff --git a/apps/codecs/libspeex/bits.c b/apps/codecs/libspeex/bits.c
index 4629012c57..78b38db44e 100644
--- a/apps/codecs/libspeex/bits.c
+++ b/apps/codecs/libspeex/bits.c
@@ -151,13 +151,9 @@ void speex_bits_read_from(SpeexBits *bits, char *chars, int len)
static void speex_bits_flush(SpeexBits *bits)
{
- int i;
int nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR);
if (bits->charPtr>0)
- {
- for (i=bits->charPtr;i<nchars; i++)
- bits->chars[i-bits->charPtr]=bits->chars[i];
- }
+ SPEEX_MOVE(bits->chars, &bits->chars[bits->charPtr], nchars-bits->charPtr);
bits->nbBits -= bits->charPtr<<LOG2_BITS_PER_CHAR;
bits->charPtr=0;
}
@@ -232,8 +228,6 @@ int speex_bits_write_whole_bytes(SpeexBits *bits, char *chars, int max_nbytes)
bits->chars[0]=bits->chars[max_nchars];
else
bits->chars[0]=0;
- for (i=1;i<((bits->nbBits)>>LOG2_BITS_PER_CHAR)+1;i++)
- bits->chars[i]=0;
bits->charPtr=0;
bits->nbBits &= (BITS_PER_CHAR-1);
return max_nchars*BYTES_PER_CHAR;
diff --git a/apps/codecs/libspeex/cb_search.c b/apps/codecs/libspeex/cb_search.c
index a3857c3afa..d280757e59 100644
--- a/apps/codecs/libspeex/cb_search.c
+++ b/apps/codecs/libspeex/cb_search.c
@@ -149,8 +149,7 @@ int update_target
ALLOC(e, nsf, spx_sig_t);
/* FIXME: Do we still need to copy the target? */
- for (i=0;i<nsf;i++)
- t[i]=target[i];
+ SPEEX_COPY(t, target, nsf);
compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);
@@ -344,11 +343,10 @@ int update_target
oind[i]=itmp+(2*i+1)*nb_subvect;
}
- for (i=0;i<nsf;i++)
- t[i]=target[i];
+ SPEEX_COPY(t, target, nsf);
for (j=0;j<N;j++)
- speex_move(&ot[j][0], t, nsf*sizeof(spx_word16_t));
+ SPEEX_COPY(&ot[j][0], t, nsf);
/* Pre-compute codewords response and energy */
compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);
@@ -597,8 +595,7 @@ int update_target
for (i=0;i<nsf;i++)
exc[i]+=SHL32(EXTEND32(tmp[i]),8);
- for (i=0;i<nsf;i++)
- target[i]=0;
+ SPEEX_MEMSET(target, 0, nsf);
}
#endif /* SPEEX_DISABLE_ENCODER */
diff --git a/apps/codecs/libspeex/jitter.c b/apps/codecs/libspeex/jitter.c
index 710e36272c..61bca75ce8 100644
--- a/apps/codecs/libspeex/jitter.c
+++ b/apps/codecs/libspeex/jitter.c
@@ -120,8 +120,8 @@ static void tb_add(struct TimingBuffer *tb, spx_int16_t timing)
int move_size = tb->filled-pos;
if (tb->filled == MAX_TIMINGS)
move_size -= 1;
- speex_move(&tb->timing[pos+1], &tb->timing[pos], move_size*sizeof(tb->timing[0]));
- speex_move(&tb->counts[pos+1], &tb->counts[pos], move_size*sizeof(tb->counts[0]));
+ SPEEX_COPY(&tb->timing[pos+1], &tb->timing[pos], move_size);
+ SPEEX_COPY(&tb->counts[pos+1], &tb->counts[pos], move_size);
}
/* Insert */
tb->timing[pos] = timing;
@@ -153,7 +153,8 @@ struct JitterBuffer_ {
int buffer_margin; /**< How many frames we want to keep in the buffer (lower bound) */
int late_cutoff; /**< How late must a packet be for it not to be considered at all */
int interp_requested; /**< An interpolation is requested by speex_jitter_update_delay() */
-
+ int auto_adjust; /**< Whether to automatically adjust the delay at any time */
+
struct TimingBuffer _tb[MAX_BUFFERS]; /**< Don't use those directly */
struct TimingBuffer *timeBuffers[MAX_BUFFERS]; /**< Storing arrival time of latest frames so we can compute some stats */
int window_size; /**< Total window over which the late frames are counted */
@@ -268,7 +269,7 @@ static spx_int16_t compute_opt_delay(JitterBuffer *jitter)
/** Initialise jitter buffer */
-JitterBuffer *jitter_buffer_init(void)
+JitterBuffer *jitter_buffer_init(int step_size)
{
JitterBuffer *jitter = (JitterBuffer*)speex_alloc(sizeof(JitterBuffer));
if (jitter)
@@ -277,13 +278,14 @@ JitterBuffer *jitter_buffer_init(void)
spx_int32_t tmp;
for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++)
jitter->packets[i].data=NULL;
- jitter->delay_step = 1;
- jitter->concealment_size = 1;
+ jitter->delay_step = step_size;
+ jitter->concealment_size = step_size;
/*FIXME: Should this be 0 or 1?*/
jitter->buffer_margin = 0;
jitter->late_cutoff = 50;
jitter->destroy = NULL;
jitter->latency_tradeoff = 0;
+ jitter->auto_adjust = 1;
tmp = 4;
jitter_buffer_ctl(jitter, JITTER_BUFFER_SET_MAX_LATE_RATE, &tmp);
jitter_buffer_reset(jitter);
@@ -369,33 +371,27 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet)
int late;
/*fprintf (stderr, "put packet %d %d\n", timestamp, span);*/
- /* Syncing on the first packet to arrive */
- if (jitter->reset_state)
- {
- jitter->reset_state=0;
- jitter->pointer_timestamp = packet->timestamp;
- jitter->next_stop = packet->timestamp;
- /*fprintf(stderr, "reset to %d\n", timestamp);*/
- }
-
/* Cleanup buffer (remove old packets that weren't played) */
- for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++)
+ if (!jitter->reset_state)
{
- /* Make sure we don't discard a "just-late" packet in case we want to play it next (if we interpolate). */
- if (jitter->packets[i].data && LE32(jitter->packets[i].timestamp + jitter->packets[i].span, jitter->pointer_timestamp))
+ for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++)
{
- /*fprintf (stderr, "cleaned (not played)\n");*/
- if (jitter->destroy)
- jitter->destroy(jitter->packets[i].data);
- else
- speex_free(jitter->packets[i].data);
- jitter->packets[i].data = NULL;
+ /* Make sure we don't discard a "just-late" packet in case we want to play it next (if we interpolate). */
+ if (jitter->packets[i].data && LE32(jitter->packets[i].timestamp + jitter->packets[i].span, jitter->pointer_timestamp))
+ {
+ /*fprintf (stderr, "cleaned (not played)\n");*/
+ if (jitter->destroy)
+ jitter->destroy(jitter->packets[i].data);
+ else
+ speex_free(jitter->packets[i].data);
+ jitter->packets[i].data = NULL;
+ }
}
}
-
+
/*fprintf(stderr, "arrival: %d %d %d\n", packet->timestamp, jitter->next_stop, jitter->pointer_timestamp);*/
/* Check if packet is late (could still be useful though) */
- if (LT32(packet->timestamp, jitter->next_stop))
+ if (!jitter->reset_state && LT32(packet->timestamp, jitter->next_stop))
{
update_timings(jitter, ((spx_int32_t)packet->timestamp) - ((spx_int32_t)jitter->next_stop) - jitter->buffer_margin);
late = 1;
@@ -404,7 +400,7 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet)
}
/* Only insert the packet if it's not hopelessly late (i.e. totally useless) */
- if (GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer_timestamp))
+ if (jitter->reset_state || GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer_timestamp))
{
/*Find an empty slot in the buffer*/
@@ -451,8 +447,9 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet)
jitter->packets[i].timestamp=packet->timestamp;
jitter->packets[i].span=packet->span;
jitter->packets[i].len=packet->len;
+ jitter->packets[i].sequence=packet->sequence;
jitter->packets[i].user_data=packet->user_data;
- if (late)
+ if (jitter->reset_state || late)
jitter->arrival[i] = 0;
else
jitter->arrival[i] = jitter->next_stop;
@@ -469,12 +466,40 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
int incomplete = 0;
spx_int16_t opt;
+ if (start_offset != NULL)
+ *start_offset = 0;
+
+ /* Syncing on the first call */
+ if (jitter->reset_state)
+ {
+ int found = 0;
+ /* Find the oldest packet */
+ spx_uint32_t oldest=0;
+ for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++)
+ {
+ if (jitter->packets[i].data && (!found || LT32(jitter->packets[i].timestamp,oldest)))
+ {
+ oldest = jitter->packets[i].timestamp;
+ found = 1;
+ }
+ }
+ if (found)
+ {
+ jitter->reset_state=0;
+ jitter->pointer_timestamp = oldest;
+ jitter->next_stop = oldest;
+ } else {
+ packet->timestamp = 0;
+ packet->span = jitter->interp_requested;
+ return JITTER_BUFFER_MISSING;
+ }
+ }
+
+
jitter->last_returned_timestamp = jitter->pointer_timestamp;
if (jitter->interp_requested != 0)
{
- if (start_offset)
- *start_offset = 0;
packet->timestamp = jitter->pointer_timestamp;
packet->span = jitter->interp_requested;
@@ -487,7 +512,7 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
jitter->buffered = packet->span - desired_span;
- return JITTER_BUFFER_MISSING;
+ return JITTER_BUFFER_INSERTION;
}
/* Searching for the packet that fits best */
@@ -551,7 +576,7 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
/* If we find something */
if (i!=SPEEX_JITTER_MAX_BUFFER_SIZE)
{
-
+ spx_int32_t offset;
/* We (obviously) haven't lost this packet */
jitter->lost_count = 0;
@@ -563,8 +588,12 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
}
- /* FIXME: Check for potential overflow */
- packet->len = jitter->packets[i].len;
+ if (jitter->packets[i].len > packet->len)
+ {
+ speex_warning_int("jitter_buffer_get(): packet too large to fit. Size is", jitter->packets[i].len);
+ } else {
+ packet->len = jitter->packets[i].len;
+ }
/* Copy packet */
if (jitter->destroy)
{
@@ -577,23 +606,27 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
}
jitter->packets[i].data = NULL;
/* Set timestamp and span (if requested) */
- if (start_offset)
- *start_offset = (spx_int32_t)jitter->packets[i].timestamp-(spx_int32_t)jitter->pointer_timestamp;
+ offset = (spx_int32_t)jitter->packets[i].timestamp-(spx_int32_t)jitter->pointer_timestamp;
+ if (start_offset != NULL)
+ *start_offset = offset;
+ else if (offset != 0)
+ speex_warning_int("jitter_buffer_get() discarding non-zero start_offset", offset);
packet->timestamp = jitter->packets[i].timestamp;
jitter->last_returned_timestamp = packet->timestamp;
packet->span = jitter->packets[i].span;
+ packet->sequence = jitter->packets[i].sequence;
packet->user_data = jitter->packets[i].user_data;
/* Point to the end of the current packet */
jitter->pointer_timestamp = jitter->packets[i].timestamp+jitter->packets[i].span;
- jitter->buffered = *start_offset + packet->span - desired_span;
-
- if (incomplete)
- return JITTER_BUFFER_INCOMPLETE;
- else
- return JITTER_BUFFER_OK;
+ jitter->buffered = packet->span - desired_span;
+
+ if (start_offset != NULL)
+ jitter->buffered += *start_offset;
+
+ return JITTER_BUFFER_OK;
}
@@ -603,8 +636,6 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
jitter->lost_count++;
/*fprintf (stderr, "m");*/
/*fprintf (stderr, "lost_count = %d\n", jitter->lost_count);*/
- if (start_offset)
- *start_offset = 0;
opt = compute_opt_delay(jitter);
@@ -621,6 +652,8 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
/* Don't move the pointer_timestamp forward */
packet->len = 0;
+ jitter->buffered = packet->span - desired_span;
+ return JITTER_BUFFER_INSERTION;
/*jitter->pointer_timestamp -= jitter->delay_step;*/
/*fprintf (stderr, "Forced to interpolate\n");*/
} else {
@@ -631,11 +664,12 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3
packet->span = desired_span;
jitter->pointer_timestamp += desired_span;
packet->len = 0;
+
+ jitter->buffered = packet->span - desired_span;
+ return JITTER_BUFFER_MISSING;
/*fprintf (stderr, "Normal loss\n");*/
}
- jitter->buffered = packet->span - desired_span;
- return JITTER_BUFFER_MISSING;
}
@@ -663,6 +697,7 @@ int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet)
jitter->packets[i].data = NULL;
packet->timestamp = jitter->packets[i].timestamp;
packet->span = jitter->packets[i].span;
+ packet->sequence = jitter->packets[i].sequence;
packet->user_data = jitter->packets[i].user_data;
return JITTER_BUFFER_OK;
} else {
@@ -673,6 +708,39 @@ int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet)
}
}
+/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
+static int _jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
+{
+ spx_int16_t opt = compute_opt_delay(jitter);
+ /*fprintf(stderr, "opt adjustment is %d ", opt);*/
+
+ if (opt < 0)
+ {
+ shift_timings(jitter, -opt);
+
+ jitter->pointer_timestamp += opt;
+ jitter->interp_requested = -opt;
+ /*fprintf (stderr, "Decision to interpolate %d samples\n", -opt);*/
+ } else if (opt > 0)
+ {
+ shift_timings(jitter, -opt);
+ jitter->pointer_timestamp += opt;
+ /*fprintf (stderr, "Decision to drop %d samples\n", opt);*/
+ }
+
+ return opt;
+}
+
+/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
+int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
+{
+ /* If the programmer calls jitter_buffer_update_delay() directly,
+ automatically disable auto-adjustment */
+ jitter->auto_adjust = 0;
+
+ return _jitter_buffer_update_delay(jitter, packet, start_offset);
+}
+
/** Get pointer timestamp of jitter buffer */
int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter)
{
@@ -681,45 +749,31 @@ int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter)
void jitter_buffer_tick(JitterBuffer *jitter)
{
+ /* Automatically-adjust the buffering delay if requested */
+ if (jitter->auto_adjust)
+ _jitter_buffer_update_delay(jitter, NULL, NULL);
+
if (jitter->buffered >= 0)
{
jitter->next_stop = jitter->pointer_timestamp - jitter->buffered;
} else {
jitter->next_stop = jitter->pointer_timestamp;
- speex_warning_int("jitter buffer sees negative buffering, you code might be broken. Value is ", jitter->buffered);
+ speex_warning_int("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered);
}
jitter->buffered = 0;
}
void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem)
{
+ /* Automatically-adjust the buffering delay if requested */
+ if (jitter->auto_adjust)
+ _jitter_buffer_update_delay(jitter, NULL, NULL);
+
if (jitter->buffered < 0)
- speex_warning_int("jitter buffer sees negative buffering, you code might be broken. Value is ", jitter->buffered);
+ speex_warning_int("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered);
jitter->next_stop = jitter->pointer_timestamp - rem;
}
-/* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */
-int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset)
-{
- spx_int16_t opt = compute_opt_delay(jitter);
- /*fprintf(stderr, "opt adjustment is %d ", opt);*/
-
- if (opt < 0)
- {
- shift_timings(jitter, -opt);
-
- jitter->pointer_timestamp += opt;
- jitter->interp_requested = -opt;
- /*fprintf (stderr, "Decision to interpolate %d samples\n", -opt);*/
- } else if (opt > 0)
- {
- shift_timings(jitter, -opt);
- jitter->pointer_timestamp += opt;
- /*fprintf (stderr, "Decision to drop %d samples\n", opt);*/
- }
-
- return opt;
-}
/* Used like the ioctl function to control the jitter buffer parameters */
int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr)
diff --git a/apps/codecs/libspeex/kiss_fft.c b/apps/codecs/libspeex/kiss_fft.c
index 775edfff36..bff826d754 100644
--- a/apps/codecs/libspeex/kiss_fft.c
+++ b/apps/codecs/libspeex/kiss_fft.c
@@ -509,7 +509,7 @@ void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,
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);*/
+ SPEEX_MOVE(fout,tmpbuf,st->nfft);*/
} else {
kf_shuffle( fout, fin, 1,in_stride, st->factors,st);
kf_work( fout, fin, 1,in_stride, st->factors,st, 1, in_stride, 1);
diff --git a/apps/codecs/libspeex/ltp.c b/apps/codecs/libspeex/ltp.c
index 2f86b678d9..04c1115b3f 100644
--- a/apps/codecs/libspeex/ltp.c
+++ b/apps/codecs/libspeex/ltp.c
@@ -40,6 +40,7 @@
#include "filters.h"
#include <speex/speex_bits.h>
#include "math_approx.h"
+#include "os_support.h"
#ifndef NULL
#define NULL 0
@@ -498,8 +499,7 @@ int scaledown
*cdbk_index=best_cdbk;
}
- for (i=0;i<nsf;i++)
- exc[i]=0;
+ SPEEX_MEMSET(exc, 0, nsf);
for (i=0;i<3;i++)
{
int j;
@@ -551,7 +551,7 @@ int plc_tuning,
spx_word32_t *cumul_gain
)
{
- int i,j;
+ int i;
int cdbk_index, pitch=0, best_gain_index=0;
VARDECL(spx_sig_t *best_exc);
VARDECL(spx_word16_t *new_target);
@@ -583,8 +583,7 @@ spx_word32_t *cumul_gain
{
speex_bits_pack(bits, 0, params->pitch_bits);
speex_bits_pack(bits, 0, params->gain_bits);
- for (i=0;i<nsf;i++)
- exc[i]=0;
+ SPEEX_MEMSET(exc, 0, nsf);
return start;
}
@@ -621,16 +620,13 @@ spx_word32_t *cumul_gain
for (i=0;i<N;i++)
{
pitch=nbest[i];
- for (j=0;j<nsf;j++)
- exc[j]=0;
+ SPEEX_MEMSET(exc, 0, nsf);
err=pitch_gain_search_3tap(target, ak, awk1, awk2, exc, gain_cdbk, gain_cdbk_size, pitch, p, nsf,
bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain, scaledown);
if (err<best_err || best_err<0)
{
- for (j=0;j<nsf;j++)
- best_exc[j]=exc[j];
- for (j=0;j<nsf;j++)
- best_target[j]=new_target[j];
+ SPEEX_COPY(best_exc, exc, nsf);
+ SPEEX_COPY(best_target, new_target, nsf);
best_err=err;
best_pitch=pitch;
best_gain_index=cdbk_index;
@@ -646,10 +642,8 @@ spx_word32_t *cumul_gain
#endif
/*printf ("%f\n", cumul_gain);*/
/*printf ("encode pitch: %d %d\n", best_pitch, best_gain_index);*/
- for (i=0;i<nsf;i++)
- exc[i]=best_exc[i];
- for (i=0;i<nsf;i++)
- target[i]=best_target[i];
+ SPEEX_COPY(exc, best_exc, nsf);
+ SPEEX_COPY(target, best_target, nsf);
#ifdef FIXED_POINT
/* Scale target back up if needed */
if (scaledown)
@@ -739,8 +733,7 @@ int cdbk_offset
gain[0] = SHL16(gain[0],7);
gain[1] = SHL16(gain[1],7);
gain[2] = SHL16(gain[2],7);
- for (i=0;i<nsf;i++)
- exc_out[i]=0;
+ SPEEX_MEMSET(exc_out, 0, nsf);
for (i=0;i<3;i++)
{
int j;
diff --git a/apps/codecs/libspeex/mdf.c b/apps/codecs/libspeex/mdf.c
index 2e863cf274..1994f2a886 100644
--- a/apps/codecs/libspeex/mdf.c
+++ b/apps/codecs/libspeex/mdf.c
@@ -1042,7 +1042,7 @@ void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const sp
#endif
/* We consider that the filter has had minimal adaptation if the following is true*/
- if (!st->adapted && st->sum_adapt > QCONST32(M,15) && MULT16_32_Q15(st->leak_estimate,Syy) > MULT16_32_Q15(QCONST16(.03f,15),Syy))
+ if (!st->adapted && st->sum_adapt > SHL32(EXTEND32(M),15) && MULT16_32_Q15(st->leak_estimate,Syy) > MULT16_32_Q15(QCONST16(.03f,15),Syy))
{
st->adapted = 1;
}
diff --git a/apps/codecs/libspeex/nb_celp.c b/apps/codecs/libspeex/nb_celp.c
index 84cf1bb6d7..d29b9ae540 100644
--- a/apps/codecs/libspeex/nb_celp.c
+++ b/apps/codecs/libspeex/nb_celp.c
@@ -293,8 +293,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
ALLOC(interp_qlpc, st->lpcSize, spx_coef_t);
/* Move signals 1 frame towards the past */
- speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t));
- speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t));
+ SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, st->max_pitch+2);
+ SPEEX_MOVE(st->swBuf, st->swBuf+st->frameSize, st->max_pitch+2);
if (st->highpass_enabled)
highpass(in, in, st->frameSize, (st->isWideband?HIGHPASS_WIDEBAND:HIGHPASS_NARROWBAND)|HIGHPASS_INPUT, st->mem_hp);
@@ -337,6 +337,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
/* Whole frame analysis (open-loop estimation of pitch and excitation gain) */
{
+ int diff = st->windowSize-st->frameSize;
if (st->first)
for (i=0;i<st->lpcSize;i++)
interp_lsp[i] = lsp[i];
@@ -361,11 +362,9 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize);
bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize);
-
- for (i=0;i<st->windowSize-st->frameSize;i++)
- st->sw[i] = st->winBuf[i];
- for (;i<st->frameSize;i++)
- st->sw[i] = in[i-st->windowSize+st->frameSize];
+
+ SPEEX_COPY(st->sw, st->winBuf, diff);
+ SPEEX_COPY(st->sw+diff, in, st->frameSize-diff);
filter_mem16(st->sw, bw_lpc1, bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole, stack);
open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize,
@@ -397,10 +396,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
}
/*Compute "real" excitation*/
- for (i=0;i<st->windowSize-st->frameSize;i++)
- st->exc[i] = st->winBuf[i];
- for (;i<st->frameSize;i++)
- st->exc[i] = in[i-st->windowSize+st->frameSize];
+ SPEEX_COPY(st->exc, st->winBuf, diff);
+ SPEEX_COPY(st->exc+diff, in, st->frameSize-diff);
fir_mem16(st->exc, interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc, stack);
/* Compute open-loop excitation gain */
@@ -415,15 +412,12 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
}
#ifdef VORBIS_PSYCHO
- for(i=0;i<256-st->frameSize;i++)
- st->psy_window[i] = st->psy_window[i+st->frameSize];
- for(i=0;i<st->frameSize;i++)
- st->psy_window[256-st->frameSize+i] = in[i];
+ SPEEX_MOVE(st->psy_window, st->psy_window+st->frameSize, 256-st->frameSize);
+ SPEEX_COPY(&st->psy_window[256-st->frameSize], in, st->frameSize);
compute_curve(st->psy, st->psy_window, st->curve);
/*print_vec(st->curve, 128, "curve");*/
if (st->first)
- for (i=0;i<128;i++)
- st->old_curve[i] = st->curve[i];
+ SPEEX_COPY(st->old_curve, st->curve, 128);
#endif
/*VBR stuff*/
@@ -562,7 +556,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
st->first=1;
st->bounded_pitch = 1;
- speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t));
+ SPEEX_COPY(st->winBuf, in+2*st->frameSize-st->windowSize, st->windowSize-st->frameSize);
/* Clear memory (no need to really compute it) */
for (i=0;i<st->lpcSize;i++)
@@ -739,8 +733,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
for (i=0;i<st->lpcSize;i++)
mem[i]=SHL32(st->mem_sw[i],1);
filter_mem16(ringing, st->bw_lpc1, st->bw_lpc2, ringing, response_bound, st->lpcSize, mem, stack);
- for (i=response_bound;i<st->subframeSize;i++)
- ringing[i]=0;
+ SPEEX_MEMSET(&ringing[response_bound], 0, st->subframeSize-response_bound);
#else
iir_mem16(ringing, interp_qlpc, ringing, st->subframeSize, st->lpcSize, mem, stack);
for (i=0;i<st->lpcSize;i++)
@@ -762,8 +755,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
target[i]=EXTRACT16(SATURATE(SUB32(sw[i],PSHR32(ringing[i],1)),32767));
/* Reset excitation */
- for (i=0;i<st->subframeSize;i++)
- exc[i]=0;
+ SPEEX_MEMSET(exc, 0, st->subframeSize);
/* If we have a long-term predictor (otherwise, something's wrong) */
speex_assert (SUBMODE(ltp_quant));
@@ -804,8 +796,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
st->pitch[sub]=pitch;
}
/* Quantization of innovation */
- for (i=0;i<st->subframeSize;i++)
- innov[i]=0;
+ SPEEX_MEMSET(innov, 0, st->subframeSize);
/* FIXME: Make sure this is save from overflows (so far so good) */
for (i=0;i<st->subframeSize;i++)
@@ -867,8 +858,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
char *tmp_stack=stack;
VARDECL(spx_sig_t *innov2);
ALLOC(innov2, st->subframeSize, spx_sig_t);
- for (i=0;i<st->subframeSize;i++)
- innov2[i]=0;
+ SPEEX_MEMSET(innov2, 0, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
target[i]=MULT16_16_P13(QCONST16(2.2f,13), target[i]);
SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2,
@@ -887,10 +877,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
}
}
- for (i=0;i<st->subframeSize;i++)
- sw[i] = exc[i];
/* Final signal synthesis from excitation */
- iir_mem16(sw, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack);
+ iir_mem16(exc, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack);
/* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */
if (st->complexity!=0)
@@ -909,10 +897,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
#ifdef VORBIS_PSYCHO
if (st->submodeID>=1)
- {
- for (i=0;i<128;i++)
- st->old_curve[i] = st->curve[i];
- }
+ SPEEX_COPY(st->old_curve, st->curve, 128);
#endif
if (st->submodeID==1)
@@ -927,7 +912,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
/* The next frame will not be the first (Duh!) */
st->first = 0;
- speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t));
+ SPEEX_COPY(st->winBuf, in+2*st->frameSize-st->windowSize, st->windowSize-st->frameSize);
if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0)
st->bounded_pitch = 1;
@@ -980,8 +965,7 @@ void *nb_decoder_init(const SpeexMode *m)
/* st->excBuf = (spx_word16_t*)speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); */
st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6;
- for (i=0;i<st->frameSize + st->max_pitch + 1;i++)
- st->excBuf[i]=0;
+ SPEEX_MEMSET(st->excBuf, 0, st->frameSize + st->max_pitch);
/* st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); */
/* st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); */
@@ -1079,7 +1063,7 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack)
innov_gain = compute_rms16(st->exc, st->frameSize);
noise_gain = MULT16_16_Q15(innov_gain, MULT16_16_Q15(fact, SUB16(Q15ONE,MULT16_16_Q15(pitch_gain,pitch_gain))));
/* Shift all buffers by one frame */
- speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t));
+ SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, 2*st->max_pitch + st->subframeSize + 12);
pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT);
@@ -1094,8 +1078,8 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack)
}
bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize);
- iir_mem16(&st->exc[-st->subframeSize], st->interp_qlpc, out,
- st->frameSize, st->lpcSize, st->mem_sp, stack);
+ iir_mem16(&st->exc[-st->subframeSize], st->interp_qlpc, out, st->frameSize,
+ st->lpcSize, st->mem_sp, stack);
highpass(out, out, st->frameSize, HIGHPASS_NARROWBAND|HIGHPASS_OUTPUT, st->mem_hp);
st->first = 0;
@@ -1229,7 +1213,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
}
/* Shift all buffers by one frame */
- speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t));
+ SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, 2*st->max_pitch + st->subframeSize + 12);
/* If null mode (no transmission), just set a couple things to zero*/
if (st->submodes[st->submodeID] == NULL)
@@ -1346,8 +1330,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
/* Reset excitation */
- for (i=0;i<st->subframeSize;i++)
- exc[i]=0;
+ SPEEX_MEMSET(exc, 0, st->subframeSize);
/*Adaptive codebook contribution*/
speex_assert (SUBMODE(ltp_unquant));
@@ -1411,8 +1394,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
int q_energy;
spx_word32_t ener;
- for (i=0;i<st->subframeSize;i++)
- innov[i]=0;
+ SPEEX_MEMSET(innov, 0, st->subframeSize);
/* Decode sub-frame gain correction */
if (SUBMODE(have_subframe_gain)==3)
@@ -1441,8 +1423,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
char *tmp_stack=stack;
VARDECL(spx_sig_t *innov2);
ALLOC(innov2, st->subframeSize, spx_sig_t);
- for (i=0;i<st->subframeSize;i++)
- innov2[i]=0;
+ SPEEX_MEMSET(innov2, 0, st->subframeSize);
SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed);
signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize);
for (i=0;i<st->subframeSize;i++)
@@ -1469,8 +1450,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
if (g>GAIN_SCALING)
g=GAIN_SCALING;
- for (i=0;i<st->subframeSize;i++)
- exc[i]=0;
+ SPEEX_MEMSET(exc, 0, st->subframeSize);
while (st->voc_offset<st->subframeSize)
{
/* exc[st->voc_offset]= g*sqrt(2*ol_pitch)*ol_gain;
@@ -1505,8 +1485,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
multicomb(st->exc-st->subframeSize, out, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack);
multicomb(st->exc+st->subframeSize, out+2*st->subframeSize, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack);
} else {
- for (i=0;i<st->frameSize;i++)
- out[i]=st->exc[i-st->subframeSize];
+ SPEEX_COPY(out, &st->exc[-st->subframeSize], st->frameSize);
}
/* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */
diff --git a/apps/codecs/libspeex/os_support.h b/apps/codecs/libspeex/os_support.h
index 7e4b25b3d9..71d24753c1 100644
--- a/apps/codecs/libspeex/os_support.h
+++ b/apps/codecs/libspeex/os_support.h
@@ -86,20 +86,20 @@ static inline void speex_free_scratch (void *ptr)
}
#endif
-/** 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);
-}
+/** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */
+#ifndef OVERRIDE_SPEEX_COPY
+#define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
#endif
-/** Print warning message with integer argument to stderr */
+/** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term
+ provides compile-time type checking */
#ifndef OVERRIDE_SPEEX_MOVE
-static inline void *speex_memset (void *s, int c, int n)
-{
- return memset(s,c,n);
-}
+#define SPEEX_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
+#endif
+
+/** Set n bytes of memory to value of c, starting at address s */
+#ifndef OVERRIDE_SPEEX_MEMSET
+#define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
#endif
diff --git a/apps/codecs/libspeex/resample.c b/apps/codecs/libspeex/resample.c
index 82e85bef43..65dfef28a3 100644
--- a/apps/codecs/libspeex/resample.c
+++ b/apps/codecs/libspeex/resample.c
@@ -337,13 +337,16 @@ static int resampler_basic_direct_single(SpeexResamplerState *st, spx_uint32_t c
}
/* Do the new part */
- ptr = in+st->in_stride*(last_sample-N+1+j);
- for (;j<N;j++)
+ if (in != NULL)
{
- sum += MULT16_16(*ptr,st->sinc_table[samp_frac_num*st->filt_len+j]);
- ptr += st->in_stride;
+ ptr = in+st->in_stride*(last_sample-N+1+j);
+ for (;j<N;j++)
+ {
+ sum += MULT16_16(*ptr,st->sinc_table[samp_frac_num*st->filt_len+j]);
+ ptr += st->in_stride;
+ }
}
-
+
*out = PSHR32(sum,15);
out += st->out_stride;
out_sample++;
@@ -385,13 +388,16 @@ static int resampler_basic_direct_double(SpeexResamplerState *st, spx_uint32_t c
}
/* Do the new part */
- ptr = in+st->in_stride*(last_sample-N+1+j);
- for (;j<N;j++)
+ if (in != NULL)
{
- sum += MULT16_16(*ptr,(double)st->sinc_table[samp_frac_num*st->filt_len+j]);
- ptr += st->in_stride;
+ ptr = in+st->in_stride*(last_sample-N+1+j);
+ for (;j<N;j++)
+ {
+ sum += MULT16_16(*ptr,(double)st->sinc_table[samp_frac_num*st->filt_len+j]);
+ ptr += st->in_stride;
+ }
}
-
+
*out = sum;
out += st->out_stride;
out_sample++;
@@ -445,16 +451,20 @@ static int resampler_basic_interpolate_single(SpeexResamplerState *st, spx_uint3
accum[2] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset]);
accum[3] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
}
- ptr = in+st->in_stride*(last_sample-N+1+j);
- /* Do the new part */
- for (;j<N;j++)
+
+ if (in != NULL)
{
- spx_word16_t curr_in = *ptr;
- ptr += st->in_stride;
- accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);
- accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]);
- accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]);
- accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
+ ptr = in+st->in_stride*(last_sample-N+1+j);
+ /* Do the new part */
+ for (;j<N;j++)
+ {
+ spx_word16_t curr_in = *ptr;
+ ptr += st->in_stride;
+ accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);
+ accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]);
+ accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]);
+ accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
+ }
}
cubic_coef(frac, interp);
sum = MULT16_32_Q15(interp[0],accum[0]) + MULT16_32_Q15(interp[1],accum[1]) + MULT16_32_Q15(interp[2],accum[2]) + MULT16_32_Q15(interp[3],accum[3]);
@@ -509,16 +519,19 @@ static int resampler_basic_interpolate_double(SpeexResamplerState *st, spx_uint3
accum[2] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset]);
accum[3] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
}
- ptr = in+st->in_stride*(last_sample-N+1+j);
- /* Do the new part */
- for (;j<N;j++)
+ if (in != NULL)
{
- double curr_in = *ptr;
- ptr += st->in_stride;
- accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);
- accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]);
- accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]);
- accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
+ ptr = in+st->in_stride*(last_sample-N+1+j);
+ /* Do the new part */
+ for (;j<N;j++)
+ {
+ double curr_in = *ptr;
+ ptr += st->in_stride;
+ accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);
+ accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]);
+ accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]);
+ accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
+ }
}
cubic_coef(frac, interp);
sum = interp[0]*accum[0] + interp[1]*accum[1] + interp[2]*accum[2] + interp[3]*accum[3];
@@ -966,7 +979,10 @@ int speex_resampler_process_interleaved_float(SpeexResamplerState *st, const flo
for (i=0;i<st->nb_channels;i++)
{
*out_len = bak_len;
- speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
+ if (in != NULL)
+ speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
+ else
+ speex_resampler_process_float(st, i, NULL, in_len, out+i, out_len);
}
st->in_stride = istride_save;
st->out_stride = ostride_save;
@@ -985,7 +1001,10 @@ int speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_i
for (i=0;i<st->nb_channels;i++)
{
*out_len = bak_len;
- speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len);
+ if (in != NULL)
+ speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len);
+ else
+ speex_resampler_process_int(st, i, NULL, in_len, out+i, out_len);
}
st->in_stride = istride_save;
st->out_stride = ostride_save;
diff --git a/apps/codecs/libspeex/rockbox.h b/apps/codecs/libspeex/rockbox.h
index be441e3c3a..3f3319c5b0 100644
--- a/apps/codecs/libspeex/rockbox.h
+++ b/apps/codecs/libspeex/rockbox.h
@@ -70,12 +70,6 @@ static inline void speex_free_scratch (void *ptr)
codec_free(ptr);
}
-#define OVERRIDE_SPEEX_MOVE 1
-static inline void *speex_move (void *dest, void *src, int n)
-{
- return memmove(dest,src,n);
-}
-
#define OVERRIDE_SPEEX_FATAL 1
static inline void _speex_fatal(const char *str, const char *file, int line)
{
diff --git a/apps/codecs/libspeex/sb_celp.c b/apps/codecs/libspeex/sb_celp.c
index 313a62e93f..51f255661f 100644
--- a/apps/codecs/libspeex/sb_celp.c
+++ b/apps/codecs/libspeex/sb_celp.c
@@ -354,10 +354,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
speex_encode_native(st->st_low, low, bits);
high = high - (st->windowSize-st->frame_size);
- for (i=0;i<st->windowSize-st->frame_size;i++)
- high[i] = st->high[i];
- for (i=0;i<st->windowSize-st->frame_size;i++)
- st->high[i] = high[i+st->frame_size];
+ SPEEX_COPY(high, st->high, st->windowSize-st->frame_size);
+ SPEEX_COPY(st->high, &high[st->frame_size], st->windowSize-st->frame_size);
ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t);
@@ -690,8 +688,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
signal_div(target, target, scale, st->subframeSize);
/* Reset excitation */
- for (i=0;i<st->subframeSize;i++)
- innov[i]=0;
+ SPEEX_MEMSET(innov, 0, st->subframeSize);
/*print_vec(target, st->subframeSize, "\ntarget");*/
SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2,
@@ -705,8 +702,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
char *tmp_stack=stack;
VARDECL(spx_sig_t *innov2);
ALLOC(innov2, st->subframeSize, spx_sig_t);
- for (i=0;i<st->subframeSize;i++)
- innov2[i]=0;
+ SPEEX_MEMSET(innov2, 0, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
target[i]=MULT16_16_P13(QCONST16(2.5f,13), target[i]);
@@ -1018,8 +1014,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
if (st->innov_save)
{
innov_save = st->innov_save+2*offset;
- for (i=0;i<2*st->subframeSize;i++)
- innov_save[i]=0;
+ SPEEX_MEMSET(innov_save, 0, 2*st->subframeSize);
}
/* LSP interpolation */
@@ -1048,8 +1043,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
filter_ratio=(rl+.01)/(rh+.01);
#endif
- for (i=0;i<st->subframeSize;i++)
- exc[i]=0;
+ SPEEX_MEMSET(exc, 0, st->subframeSize);
if (!SUBMODE(innovation_unquant))
{
spx_word32_t g;
@@ -1087,8 +1081,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
char *tmp_stack=stack;
VARDECL(spx_sig_t *innov2);
ALLOC(innov2, st->subframeSize, spx_sig_t);
- for (i=0;i<st->subframeSize;i++)
- innov2[i]=0;
+ SPEEX_MEMSET(innov2, 0, st->subframeSize);
SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize,
bits, stack, &st->seed);
signal_mul(innov2, innov2, MULT16_32_P15(QCONST16(0.4f,15),scale), st->subframeSize);
diff --git a/apps/codecs/libspeex/speex/speex_jitter.h b/apps/codecs/libspeex/speex/speex_jitter.h
index d1af5b0210..03bac15636 100644
--- a/apps/codecs/libspeex/speex/speex_jitter.h
+++ b/apps/codecs/libspeex/speex/speex_jitter.h
@@ -63,16 +63,15 @@ struct _JitterBufferPacket {
spx_uint32_t timestamp; /**< Timestamp for the packet */
spx_uint32_t span; /**< Time covered by the packet (same units as timestamp) */
spx_uint16_t sequence; /**< RTP Sequence number if available (0 otherwise) */
- spx_uint16_t flags; /**< Info about the returned packet */
spx_uint32_t user_data; /**< Put whatever data you like here (it's ignored by the jitter buffer) */
};
/** Packet has been retrieved */
#define JITTER_BUFFER_OK 0
-/** Packet is missing */
+/** Packet is lost or is late */
#define JITTER_BUFFER_MISSING 1
-/** Packet is incomplete (does not cover the entire tick */
-#define JITTER_BUFFER_INCOMPLETE 2
+/** A "fake" packet is meant to be inserted here to increase buffering */
+#define JITTER_BUFFER_INSERTION 2
/** There was an error in the jitter buffer */
#define JITTER_BUFFER_INTERNAL_ERROR -1
/** Invalid argument */
@@ -117,10 +116,12 @@ struct _JitterBufferPacket {
/** Initialises jitter buffer
*
- * @param tick Number of samples per "tick", i.e. the time period of the elements that will be retrieved
+ * @param step_size Starting value for the size of concleanment packets and delay
+ adjustment steps. Can be changed at any time using JITTER_BUFFER_SET_DELAY_STEP
+ and JITTER_BUFFER_GET_CONCEALMENT_SIZE.
* @return Newly created jitter buffer state
*/
-JitterBuffer *jitter_buffer_init(void);
+JitterBuffer *jitter_buffer_init(int step_size);
/** Restores jitter buffer to its original state
*
diff --git a/apps/codecs/libspeex/speex_header.c b/apps/codecs/libspeex/speex_header.c
index a96e2a24c5..1d1d07731c 100644
--- a/apps/codecs/libspeex/speex_header.c
+++ b/apps/codecs/libspeex/speex_header.c
@@ -126,7 +126,7 @@ char *speex_header_to_packet(SpeexHeader *header, int *size)
SpeexHeader *le_header;
le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader));
- speex_move(le_header, header, sizeof(SpeexHeader));
+ SPEEX_COPY(le_header, header, 1);
/*Make sure everything is now little-endian*/
ENDIAN_SWITCH(le_header->speex_version_id);
@@ -168,7 +168,7 @@ SpeexHeader *speex_packet_to_header(char *packet, int size)
/* le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); */
- speex_move(le_header, packet, sizeof(SpeexHeader));
+ SPEEX_COPY(le_header, (SpeexHeader*)packet, 1);
/*Make sure everything is converted correctly from little-endian*/
ENDIAN_SWITCH(le_header->speex_version_id);