diff options
Diffstat (limited to 'apps/codecs/libspeex')
-rw-r--r-- | apps/codecs/libspeex/arch.h | 4 | ||||
-rw-r--r-- | apps/codecs/libspeex/bits.c | 8 | ||||
-rw-r--r-- | apps/codecs/libspeex/cb_search.c | 11 | ||||
-rw-r--r-- | apps/codecs/libspeex/jitter.c | 194 | ||||
-rw-r--r-- | apps/codecs/libspeex/kiss_fft.c | 2 | ||||
-rw-r--r-- | apps/codecs/libspeex/ltp.c | 27 | ||||
-rw-r--r-- | apps/codecs/libspeex/mdf.c | 2 | ||||
-rw-r--r-- | apps/codecs/libspeex/nb_celp.c | 79 | ||||
-rw-r--r-- | apps/codecs/libspeex/os_support.h | 22 | ||||
-rw-r--r-- | apps/codecs/libspeex/resample.c | 79 | ||||
-rw-r--r-- | apps/codecs/libspeex/rockbox.h | 6 | ||||
-rw-r--r-- | apps/codecs/libspeex/sb_celp.c | 21 | ||||
-rw-r--r-- | apps/codecs/libspeex/speex/speex_jitter.h | 13 | ||||
-rw-r--r-- | apps/codecs/libspeex/speex_header.c | 4 |
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 @@ | |||
42 | #define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */ | 42 | #define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */ |
43 | #define SPEEX_MICRO_VERSION 15 /**< Micro Speex version. */ | 43 | #define SPEEX_MICRO_VERSION 15 /**< Micro Speex version. */ |
44 | #define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */ | 44 | #define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */ |
45 | #define SPEEX_VERSION "speex-1.2beta3" /**< Speex version string. */ | 45 | #define SPEEX_VERSION "speex-1.2beta4" /**< Speex version string. */ |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | /* A couple test to catch stupid option combinations */ | 48 | /* A couple test to catch stupid option combinations */ |
@@ -127,8 +127,6 @@ typedef spx_word32_t spx_sig_t; | |||
127 | #include "fixed_arm5e.h" | 127 | #include "fixed_arm5e.h" |
128 | #elif defined (ARM4_ASM) | 128 | #elif defined (ARM4_ASM) |
129 | #include "fixed_arm4.h" | 129 | #include "fixed_arm4.h" |
130 | #elif defined (ARM5E_ASM) | ||
131 | #include "fixed_arm5e.h" | ||
132 | #elif defined (BFIN_ASM) | 130 | #elif defined (BFIN_ASM) |
133 | #include "fixed_bfin.h" | 131 | #include "fixed_bfin.h" |
134 | #endif | 132 | #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) | |||
151 | 151 | ||
152 | static void speex_bits_flush(SpeexBits *bits) | 152 | static void speex_bits_flush(SpeexBits *bits) |
153 | { | 153 | { |
154 | int i; | ||
155 | int nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR); | 154 | int nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR); |
156 | if (bits->charPtr>0) | 155 | if (bits->charPtr>0) |
157 | { | 156 | SPEEX_MOVE(bits->chars, &bits->chars[bits->charPtr], nchars-bits->charPtr); |
158 | for (i=bits->charPtr;i<nchars; i++) | ||
159 | bits->chars[i-bits->charPtr]=bits->chars[i]; | ||
160 | } | ||
161 | bits->nbBits -= bits->charPtr<<LOG2_BITS_PER_CHAR; | 157 | bits->nbBits -= bits->charPtr<<LOG2_BITS_PER_CHAR; |
162 | bits->charPtr=0; | 158 | bits->charPtr=0; |
163 | } | 159 | } |
@@ -232,8 +228,6 @@ int speex_bits_write_whole_bytes(SpeexBits *bits, char *chars, int max_nbytes) | |||
232 | bits->chars[0]=bits->chars[max_nchars]; | 228 | bits->chars[0]=bits->chars[max_nchars]; |
233 | else | 229 | else |
234 | bits->chars[0]=0; | 230 | bits->chars[0]=0; |
235 | for (i=1;i<((bits->nbBits)>>LOG2_BITS_PER_CHAR)+1;i++) | ||
236 | bits->chars[i]=0; | ||
237 | bits->charPtr=0; | 231 | bits->charPtr=0; |
238 | bits->nbBits &= (BITS_PER_CHAR-1); | 232 | bits->nbBits &= (BITS_PER_CHAR-1); |
239 | return max_nchars*BYTES_PER_CHAR; | 233 | 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 | |||
149 | ALLOC(e, nsf, spx_sig_t); | 149 | ALLOC(e, nsf, spx_sig_t); |
150 | 150 | ||
151 | /* FIXME: Do we still need to copy the target? */ | 151 | /* FIXME: Do we still need to copy the target? */ |
152 | for (i=0;i<nsf;i++) | 152 | SPEEX_COPY(t, target, nsf); |
153 | t[i]=target[i]; | ||
154 | 153 | ||
155 | compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack); | 154 | compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack); |
156 | 155 | ||
@@ -344,11 +343,10 @@ int update_target | |||
344 | oind[i]=itmp+(2*i+1)*nb_subvect; | 343 | oind[i]=itmp+(2*i+1)*nb_subvect; |
345 | } | 344 | } |
346 | 345 | ||
347 | for (i=0;i<nsf;i++) | 346 | SPEEX_COPY(t, target, nsf); |
348 | t[i]=target[i]; | ||
349 | 347 | ||
350 | for (j=0;j<N;j++) | 348 | for (j=0;j<N;j++) |
351 | speex_move(&ot[j][0], t, nsf*sizeof(spx_word16_t)); | 349 | SPEEX_COPY(&ot[j][0], t, nsf); |
352 | 350 | ||
353 | /* Pre-compute codewords response and energy */ | 351 | /* Pre-compute codewords response and energy */ |
354 | compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack); | 352 | compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack); |
@@ -597,8 +595,7 @@ int update_target | |||
597 | 595 | ||
598 | for (i=0;i<nsf;i++) | 596 | for (i=0;i<nsf;i++) |
599 | exc[i]+=SHL32(EXTEND32(tmp[i]),8); | 597 | exc[i]+=SHL32(EXTEND32(tmp[i]),8); |
600 | for (i=0;i<nsf;i++) | 598 | SPEEX_MEMSET(target, 0, nsf); |
601 | target[i]=0; | ||
602 | } | 599 | } |
603 | #endif /* SPEEX_DISABLE_ENCODER */ | 600 | #endif /* SPEEX_DISABLE_ENCODER */ |
604 | 601 | ||
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) | |||
120 | int move_size = tb->filled-pos; | 120 | int move_size = tb->filled-pos; |
121 | if (tb->filled == MAX_TIMINGS) | 121 | if (tb->filled == MAX_TIMINGS) |
122 | move_size -= 1; | 122 | move_size -= 1; |
123 | speex_move(&tb->timing[pos+1], &tb->timing[pos], move_size*sizeof(tb->timing[0])); | 123 | SPEEX_COPY(&tb->timing[pos+1], &tb->timing[pos], move_size); |
124 | speex_move(&tb->counts[pos+1], &tb->counts[pos], move_size*sizeof(tb->counts[0])); | 124 | SPEEX_COPY(&tb->counts[pos+1], &tb->counts[pos], move_size); |
125 | } | 125 | } |
126 | /* Insert */ | 126 | /* Insert */ |
127 | tb->timing[pos] = timing; | 127 | tb->timing[pos] = timing; |
@@ -153,7 +153,8 @@ struct JitterBuffer_ { | |||
153 | int buffer_margin; /**< How many frames we want to keep in the buffer (lower bound) */ | 153 | int buffer_margin; /**< How many frames we want to keep in the buffer (lower bound) */ |
154 | int late_cutoff; /**< How late must a packet be for it not to be considered at all */ | 154 | int late_cutoff; /**< How late must a packet be for it not to be considered at all */ |
155 | int interp_requested; /**< An interpolation is requested by speex_jitter_update_delay() */ | 155 | int interp_requested; /**< An interpolation is requested by speex_jitter_update_delay() */ |
156 | 156 | int auto_adjust; /**< Whether to automatically adjust the delay at any time */ | |
157 | |||
157 | struct TimingBuffer _tb[MAX_BUFFERS]; /**< Don't use those directly */ | 158 | struct TimingBuffer _tb[MAX_BUFFERS]; /**< Don't use those directly */ |
158 | struct TimingBuffer *timeBuffers[MAX_BUFFERS]; /**< Storing arrival time of latest frames so we can compute some stats */ | 159 | struct TimingBuffer *timeBuffers[MAX_BUFFERS]; /**< Storing arrival time of latest frames so we can compute some stats */ |
159 | int window_size; /**< Total window over which the late frames are counted */ | 160 | 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) | |||
268 | 269 | ||
269 | 270 | ||
270 | /** Initialise jitter buffer */ | 271 | /** Initialise jitter buffer */ |
271 | JitterBuffer *jitter_buffer_init(void) | 272 | JitterBuffer *jitter_buffer_init(int step_size) |
272 | { | 273 | { |
273 | JitterBuffer *jitter = (JitterBuffer*)speex_alloc(sizeof(JitterBuffer)); | 274 | JitterBuffer *jitter = (JitterBuffer*)speex_alloc(sizeof(JitterBuffer)); |
274 | if (jitter) | 275 | if (jitter) |
@@ -277,13 +278,14 @@ JitterBuffer *jitter_buffer_init(void) | |||
277 | spx_int32_t tmp; | 278 | spx_int32_t tmp; |
278 | for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++) | 279 | for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++) |
279 | jitter->packets[i].data=NULL; | 280 | jitter->packets[i].data=NULL; |
280 | jitter->delay_step = 1; | 281 | jitter->delay_step = step_size; |
281 | jitter->concealment_size = 1; | 282 | jitter->concealment_size = step_size; |
282 | /*FIXME: Should this be 0 or 1?*/ | 283 | /*FIXME: Should this be 0 or 1?*/ |
283 | jitter->buffer_margin = 0; | 284 | jitter->buffer_margin = 0; |
284 | jitter->late_cutoff = 50; | 285 | jitter->late_cutoff = 50; |
285 | jitter->destroy = NULL; | 286 | jitter->destroy = NULL; |
286 | jitter->latency_tradeoff = 0; | 287 | jitter->latency_tradeoff = 0; |
288 | jitter->auto_adjust = 1; | ||
287 | tmp = 4; | 289 | tmp = 4; |
288 | jitter_buffer_ctl(jitter, JITTER_BUFFER_SET_MAX_LATE_RATE, &tmp); | 290 | jitter_buffer_ctl(jitter, JITTER_BUFFER_SET_MAX_LATE_RATE, &tmp); |
289 | jitter_buffer_reset(jitter); | 291 | jitter_buffer_reset(jitter); |
@@ -369,33 +371,27 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet) | |||
369 | int late; | 371 | int late; |
370 | /*fprintf (stderr, "put packet %d %d\n", timestamp, span);*/ | 372 | /*fprintf (stderr, "put packet %d %d\n", timestamp, span);*/ |
371 | 373 | ||
372 | /* Syncing on the first packet to arrive */ | ||
373 | if (jitter->reset_state) | ||
374 | { | ||
375 | jitter->reset_state=0; | ||
376 | jitter->pointer_timestamp = packet->timestamp; | ||
377 | jitter->next_stop = packet->timestamp; | ||
378 | /*fprintf(stderr, "reset to %d\n", timestamp);*/ | ||
379 | } | ||
380 | |||
381 | /* Cleanup buffer (remove old packets that weren't played) */ | 374 | /* Cleanup buffer (remove old packets that weren't played) */ |
382 | for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++) | 375 | if (!jitter->reset_state) |
383 | { | 376 | { |
384 | /* Make sure we don't discard a "just-late" packet in case we want to play it next (if we interpolate). */ | 377 | for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++) |
385 | if (jitter->packets[i].data && LE32(jitter->packets[i].timestamp + jitter->packets[i].span, jitter->pointer_timestamp)) | ||
386 | { | 378 | { |
387 | /*fprintf (stderr, "cleaned (not played)\n");*/ | 379 | /* Make sure we don't discard a "just-late" packet in case we want to play it next (if we interpolate). */ |
388 | if (jitter->destroy) | 380 | if (jitter->packets[i].data && LE32(jitter->packets[i].timestamp + jitter->packets[i].span, jitter->pointer_timestamp)) |
389 | jitter->destroy(jitter->packets[i].data); | 381 | { |
390 | else | 382 | /*fprintf (stderr, "cleaned (not played)\n");*/ |
391 | speex_free(jitter->packets[i].data); | 383 | if (jitter->destroy) |
392 | jitter->packets[i].data = NULL; | 384 | jitter->destroy(jitter->packets[i].data); |
385 | else | ||
386 | speex_free(jitter->packets[i].data); | ||
387 | jitter->packets[i].data = NULL; | ||
388 | } | ||
393 | } | 389 | } |
394 | } | 390 | } |
395 | 391 | ||
396 | /*fprintf(stderr, "arrival: %d %d %d\n", packet->timestamp, jitter->next_stop, jitter->pointer_timestamp);*/ | 392 | /*fprintf(stderr, "arrival: %d %d %d\n", packet->timestamp, jitter->next_stop, jitter->pointer_timestamp);*/ |
397 | /* Check if packet is late (could still be useful though) */ | 393 | /* Check if packet is late (could still be useful though) */ |
398 | if (LT32(packet->timestamp, jitter->next_stop)) | 394 | if (!jitter->reset_state && LT32(packet->timestamp, jitter->next_stop)) |
399 | { | 395 | { |
400 | update_timings(jitter, ((spx_int32_t)packet->timestamp) - ((spx_int32_t)jitter->next_stop) - jitter->buffer_margin); | 396 | update_timings(jitter, ((spx_int32_t)packet->timestamp) - ((spx_int32_t)jitter->next_stop) - jitter->buffer_margin); |
401 | late = 1; | 397 | late = 1; |
@@ -404,7 +400,7 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet) | |||
404 | } | 400 | } |
405 | 401 | ||
406 | /* Only insert the packet if it's not hopelessly late (i.e. totally useless) */ | 402 | /* Only insert the packet if it's not hopelessly late (i.e. totally useless) */ |
407 | if (GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer_timestamp)) | 403 | if (jitter->reset_state || GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer_timestamp)) |
408 | { | 404 | { |
409 | 405 | ||
410 | /*Find an empty slot in the buffer*/ | 406 | /*Find an empty slot in the buffer*/ |
@@ -451,8 +447,9 @@ void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet) | |||
451 | jitter->packets[i].timestamp=packet->timestamp; | 447 | jitter->packets[i].timestamp=packet->timestamp; |
452 | jitter->packets[i].span=packet->span; | 448 | jitter->packets[i].span=packet->span; |
453 | jitter->packets[i].len=packet->len; | 449 | jitter->packets[i].len=packet->len; |
450 | jitter->packets[i].sequence=packet->sequence; | ||
454 | jitter->packets[i].user_data=packet->user_data; | 451 | jitter->packets[i].user_data=packet->user_data; |
455 | if (late) | 452 | if (jitter->reset_state || late) |
456 | jitter->arrival[i] = 0; | 453 | jitter->arrival[i] = 0; |
457 | else | 454 | else |
458 | jitter->arrival[i] = jitter->next_stop; | 455 | jitter->arrival[i] = jitter->next_stop; |
@@ -469,12 +466,40 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
469 | int incomplete = 0; | 466 | int incomplete = 0; |
470 | spx_int16_t opt; | 467 | spx_int16_t opt; |
471 | 468 | ||
469 | if (start_offset != NULL) | ||
470 | *start_offset = 0; | ||
471 | |||
472 | /* Syncing on the first call */ | ||
473 | if (jitter->reset_state) | ||
474 | { | ||
475 | int found = 0; | ||
476 | /* Find the oldest packet */ | ||
477 | spx_uint32_t oldest=0; | ||
478 | for (i=0;i<SPEEX_JITTER_MAX_BUFFER_SIZE;i++) | ||
479 | { | ||
480 | if (jitter->packets[i].data && (!found || LT32(jitter->packets[i].timestamp,oldest))) | ||
481 | { | ||
482 | oldest = jitter->packets[i].timestamp; | ||
483 | found = 1; | ||
484 | } | ||
485 | } | ||
486 | if (found) | ||
487 | { | ||
488 | jitter->reset_state=0; | ||
489 | jitter->pointer_timestamp = oldest; | ||
490 | jitter->next_stop = oldest; | ||
491 | } else { | ||
492 | packet->timestamp = 0; | ||
493 | packet->span = jitter->interp_requested; | ||
494 | return JITTER_BUFFER_MISSING; | ||
495 | } | ||
496 | } | ||
497 | |||
498 | |||
472 | jitter->last_returned_timestamp = jitter->pointer_timestamp; | 499 | jitter->last_returned_timestamp = jitter->pointer_timestamp; |
473 | 500 | ||
474 | if (jitter->interp_requested != 0) | 501 | if (jitter->interp_requested != 0) |
475 | { | 502 | { |
476 | if (start_offset) | ||
477 | *start_offset = 0; | ||
478 | packet->timestamp = jitter->pointer_timestamp; | 503 | packet->timestamp = jitter->pointer_timestamp; |
479 | packet->span = jitter->interp_requested; | 504 | packet->span = jitter->interp_requested; |
480 | 505 | ||
@@ -487,7 +512,7 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
487 | 512 | ||
488 | jitter->buffered = packet->span - desired_span; | 513 | jitter->buffered = packet->span - desired_span; |
489 | 514 | ||
490 | return JITTER_BUFFER_MISSING; | 515 | return JITTER_BUFFER_INSERTION; |
491 | } | 516 | } |
492 | 517 | ||
493 | /* Searching for the packet that fits best */ | 518 | /* Searching for the packet that fits best */ |
@@ -551,7 +576,7 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
551 | /* If we find something */ | 576 | /* If we find something */ |
552 | if (i!=SPEEX_JITTER_MAX_BUFFER_SIZE) | 577 | if (i!=SPEEX_JITTER_MAX_BUFFER_SIZE) |
553 | { | 578 | { |
554 | 579 | spx_int32_t offset; | |
555 | 580 | ||
556 | /* We (obviously) haven't lost this packet */ | 581 | /* We (obviously) haven't lost this packet */ |
557 | jitter->lost_count = 0; | 582 | jitter->lost_count = 0; |
@@ -563,8 +588,12 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
563 | } | 588 | } |
564 | 589 | ||
565 | 590 | ||
566 | /* FIXME: Check for potential overflow */ | 591 | if (jitter->packets[i].len > packet->len) |
567 | packet->len = jitter->packets[i].len; | 592 | { |
593 | speex_warning_int("jitter_buffer_get(): packet too large to fit. Size is", jitter->packets[i].len); | ||
594 | } else { | ||
595 | packet->len = jitter->packets[i].len; | ||
596 | } | ||
568 | /* Copy packet */ | 597 | /* Copy packet */ |
569 | if (jitter->destroy) | 598 | if (jitter->destroy) |
570 | { | 599 | { |
@@ -577,23 +606,27 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
577 | } | 606 | } |
578 | jitter->packets[i].data = NULL; | 607 | jitter->packets[i].data = NULL; |
579 | /* Set timestamp and span (if requested) */ | 608 | /* Set timestamp and span (if requested) */ |
580 | if (start_offset) | 609 | offset = (spx_int32_t)jitter->packets[i].timestamp-(spx_int32_t)jitter->pointer_timestamp; |
581 | *start_offset = (spx_int32_t)jitter->packets[i].timestamp-(spx_int32_t)jitter->pointer_timestamp; | 610 | if (start_offset != NULL) |
611 | *start_offset = offset; | ||
612 | else if (offset != 0) | ||
613 | speex_warning_int("jitter_buffer_get() discarding non-zero start_offset", offset); | ||
582 | 614 | ||
583 | packet->timestamp = jitter->packets[i].timestamp; | 615 | packet->timestamp = jitter->packets[i].timestamp; |
584 | jitter->last_returned_timestamp = packet->timestamp; | 616 | jitter->last_returned_timestamp = packet->timestamp; |
585 | 617 | ||
586 | packet->span = jitter->packets[i].span; | 618 | packet->span = jitter->packets[i].span; |
619 | packet->sequence = jitter->packets[i].sequence; | ||
587 | packet->user_data = jitter->packets[i].user_data; | 620 | packet->user_data = jitter->packets[i].user_data; |
588 | /* Point to the end of the current packet */ | 621 | /* Point to the end of the current packet */ |
589 | jitter->pointer_timestamp = jitter->packets[i].timestamp+jitter->packets[i].span; | 622 | jitter->pointer_timestamp = jitter->packets[i].timestamp+jitter->packets[i].span; |
590 | 623 | ||
591 | jitter->buffered = *start_offset + packet->span - desired_span; | 624 | jitter->buffered = packet->span - desired_span; |
592 | 625 | ||
593 | if (incomplete) | 626 | if (start_offset != NULL) |
594 | return JITTER_BUFFER_INCOMPLETE; | 627 | jitter->buffered += *start_offset; |
595 | else | 628 | |
596 | return JITTER_BUFFER_OK; | 629 | return JITTER_BUFFER_OK; |
597 | } | 630 | } |
598 | 631 | ||
599 | 632 | ||
@@ -603,8 +636,6 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
603 | jitter->lost_count++; | 636 | jitter->lost_count++; |
604 | /*fprintf (stderr, "m");*/ | 637 | /*fprintf (stderr, "m");*/ |
605 | /*fprintf (stderr, "lost_count = %d\n", jitter->lost_count);*/ | 638 | /*fprintf (stderr, "lost_count = %d\n", jitter->lost_count);*/ |
606 | if (start_offset) | ||
607 | *start_offset = 0; | ||
608 | 639 | ||
609 | opt = compute_opt_delay(jitter); | 640 | opt = compute_opt_delay(jitter); |
610 | 641 | ||
@@ -621,6 +652,8 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
621 | /* Don't move the pointer_timestamp forward */ | 652 | /* Don't move the pointer_timestamp forward */ |
622 | packet->len = 0; | 653 | packet->len = 0; |
623 | 654 | ||
655 | jitter->buffered = packet->span - desired_span; | ||
656 | return JITTER_BUFFER_INSERTION; | ||
624 | /*jitter->pointer_timestamp -= jitter->delay_step;*/ | 657 | /*jitter->pointer_timestamp -= jitter->delay_step;*/ |
625 | /*fprintf (stderr, "Forced to interpolate\n");*/ | 658 | /*fprintf (stderr, "Forced to interpolate\n");*/ |
626 | } else { | 659 | } else { |
@@ -631,11 +664,12 @@ int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int3 | |||
631 | packet->span = desired_span; | 664 | packet->span = desired_span; |
632 | jitter->pointer_timestamp += desired_span; | 665 | jitter->pointer_timestamp += desired_span; |
633 | packet->len = 0; | 666 | packet->len = 0; |
667 | |||
668 | jitter->buffered = packet->span - desired_span; | ||
669 | return JITTER_BUFFER_MISSING; | ||
634 | /*fprintf (stderr, "Normal loss\n");*/ | 670 | /*fprintf (stderr, "Normal loss\n");*/ |
635 | } | 671 | } |
636 | 672 | ||
637 | jitter->buffered = packet->span - desired_span; | ||
638 | return JITTER_BUFFER_MISSING; | ||
639 | 673 | ||
640 | } | 674 | } |
641 | 675 | ||
@@ -663,6 +697,7 @@ int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet) | |||
663 | jitter->packets[i].data = NULL; | 697 | jitter->packets[i].data = NULL; |
664 | packet->timestamp = jitter->packets[i].timestamp; | 698 | packet->timestamp = jitter->packets[i].timestamp; |
665 | packet->span = jitter->packets[i].span; | 699 | packet->span = jitter->packets[i].span; |
700 | packet->sequence = jitter->packets[i].sequence; | ||
666 | packet->user_data = jitter->packets[i].user_data; | 701 | packet->user_data = jitter->packets[i].user_data; |
667 | return JITTER_BUFFER_OK; | 702 | return JITTER_BUFFER_OK; |
668 | } else { | 703 | } else { |
@@ -673,6 +708,39 @@ int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet) | |||
673 | } | 708 | } |
674 | } | 709 | } |
675 | 710 | ||
711 | /* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */ | ||
712 | static int _jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset) | ||
713 | { | ||
714 | spx_int16_t opt = compute_opt_delay(jitter); | ||
715 | /*fprintf(stderr, "opt adjustment is %d ", opt);*/ | ||
716 | |||
717 | if (opt < 0) | ||
718 | { | ||
719 | shift_timings(jitter, -opt); | ||
720 | |||
721 | jitter->pointer_timestamp += opt; | ||
722 | jitter->interp_requested = -opt; | ||
723 | /*fprintf (stderr, "Decision to interpolate %d samples\n", -opt);*/ | ||
724 | } else if (opt > 0) | ||
725 | { | ||
726 | shift_timings(jitter, -opt); | ||
727 | jitter->pointer_timestamp += opt; | ||
728 | /*fprintf (stderr, "Decision to drop %d samples\n", opt);*/ | ||
729 | } | ||
730 | |||
731 | return opt; | ||
732 | } | ||
733 | |||
734 | /* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */ | ||
735 | int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset) | ||
736 | { | ||
737 | /* If the programmer calls jitter_buffer_update_delay() directly, | ||
738 | automatically disable auto-adjustment */ | ||
739 | jitter->auto_adjust = 0; | ||
740 | |||
741 | return _jitter_buffer_update_delay(jitter, packet, start_offset); | ||
742 | } | ||
743 | |||
676 | /** Get pointer timestamp of jitter buffer */ | 744 | /** Get pointer timestamp of jitter buffer */ |
677 | int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter) | 745 | int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter) |
678 | { | 746 | { |
@@ -681,45 +749,31 @@ int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter) | |||
681 | 749 | ||
682 | void jitter_buffer_tick(JitterBuffer *jitter) | 750 | void jitter_buffer_tick(JitterBuffer *jitter) |
683 | { | 751 | { |
752 | /* Automatically-adjust the buffering delay if requested */ | ||
753 | if (jitter->auto_adjust) | ||
754 | _jitter_buffer_update_delay(jitter, NULL, NULL); | ||
755 | |||
684 | if (jitter->buffered >= 0) | 756 | if (jitter->buffered >= 0) |
685 | { | 757 | { |
686 | jitter->next_stop = jitter->pointer_timestamp - jitter->buffered; | 758 | jitter->next_stop = jitter->pointer_timestamp - jitter->buffered; |
687 | } else { | 759 | } else { |
688 | jitter->next_stop = jitter->pointer_timestamp; | 760 | jitter->next_stop = jitter->pointer_timestamp; |
689 | speex_warning_int("jitter buffer sees negative buffering, you code might be broken. Value is ", jitter->buffered); | 761 | speex_warning_int("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered); |
690 | } | 762 | } |
691 | jitter->buffered = 0; | 763 | jitter->buffered = 0; |
692 | } | 764 | } |
693 | 765 | ||
694 | void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem) | 766 | void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem) |
695 | { | 767 | { |
768 | /* Automatically-adjust the buffering delay if requested */ | ||
769 | if (jitter->auto_adjust) | ||
770 | _jitter_buffer_update_delay(jitter, NULL, NULL); | ||
771 | |||
696 | if (jitter->buffered < 0) | 772 | if (jitter->buffered < 0) |
697 | speex_warning_int("jitter buffer sees negative buffering, you code might be broken. Value is ", jitter->buffered); | 773 | speex_warning_int("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered); |
698 | jitter->next_stop = jitter->pointer_timestamp - rem; | 774 | jitter->next_stop = jitter->pointer_timestamp - rem; |
699 | } | 775 | } |
700 | 776 | ||
701 | /* Let the jitter buffer know it's the right time to adjust the buffering delay to the network conditions */ | ||
702 | int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset) | ||
703 | { | ||
704 | spx_int16_t opt = compute_opt_delay(jitter); | ||
705 | /*fprintf(stderr, "opt adjustment is %d ", opt);*/ | ||
706 | |||
707 | if (opt < 0) | ||
708 | { | ||
709 | shift_timings(jitter, -opt); | ||
710 | |||
711 | jitter->pointer_timestamp += opt; | ||
712 | jitter->interp_requested = -opt; | ||
713 | /*fprintf (stderr, "Decision to interpolate %d samples\n", -opt);*/ | ||
714 | } else if (opt > 0) | ||
715 | { | ||
716 | shift_timings(jitter, -opt); | ||
717 | jitter->pointer_timestamp += opt; | ||
718 | /*fprintf (stderr, "Decision to drop %d samples\n", opt);*/ | ||
719 | } | ||
720 | |||
721 | return opt; | ||
722 | } | ||
723 | 777 | ||
724 | /* Used like the ioctl function to control the jitter buffer parameters */ | 778 | /* Used like the ioctl function to control the jitter buffer parameters */ |
725 | int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr) | 779 | 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, | |||
509 | speex_fatal("In-place FFT not supported"); | 509 | speex_fatal("In-place FFT not supported"); |
510 | /*CHECKBUF(tmpbuf,ntmpbuf,st->nfft); | 510 | /*CHECKBUF(tmpbuf,ntmpbuf,st->nfft); |
511 | kf_work(tmpbuf,fin,1,in_stride, st->factors,st); | 511 | kf_work(tmpbuf,fin,1,in_stride, st->factors,st); |
512 | speex_move(fout,tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);*/ | 512 | SPEEX_MOVE(fout,tmpbuf,st->nfft);*/ |
513 | } else { | 513 | } else { |
514 | kf_shuffle( fout, fin, 1,in_stride, st->factors,st); | 514 | kf_shuffle( fout, fin, 1,in_stride, st->factors,st); |
515 | kf_work( fout, fin, 1,in_stride, st->factors,st, 1, in_stride, 1); | 515 | 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 @@ | |||
40 | #include "filters.h" | 40 | #include "filters.h" |
41 | #include <speex/speex_bits.h> | 41 | #include <speex/speex_bits.h> |
42 | #include "math_approx.h" | 42 | #include "math_approx.h" |
43 | #include "os_support.h" | ||
43 | 44 | ||
44 | #ifndef NULL | 45 | #ifndef NULL |
45 | #define NULL 0 | 46 | #define NULL 0 |
@@ -498,8 +499,7 @@ int scaledown | |||
498 | *cdbk_index=best_cdbk; | 499 | *cdbk_index=best_cdbk; |
499 | } | 500 | } |
500 | 501 | ||
501 | for (i=0;i<nsf;i++) | 502 | SPEEX_MEMSET(exc, 0, nsf); |
502 | exc[i]=0; | ||
503 | for (i=0;i<3;i++) | 503 | for (i=0;i<3;i++) |
504 | { | 504 | { |
505 | int j; | 505 | int j; |
@@ -551,7 +551,7 @@ int plc_tuning, | |||
551 | spx_word32_t *cumul_gain | 551 | spx_word32_t *cumul_gain |
552 | ) | 552 | ) |
553 | { | 553 | { |
554 | int i,j; | 554 | int i; |
555 | int cdbk_index, pitch=0, best_gain_index=0; | 555 | int cdbk_index, pitch=0, best_gain_index=0; |
556 | VARDECL(spx_sig_t *best_exc); | 556 | VARDECL(spx_sig_t *best_exc); |
557 | VARDECL(spx_word16_t *new_target); | 557 | VARDECL(spx_word16_t *new_target); |
@@ -583,8 +583,7 @@ spx_word32_t *cumul_gain | |||
583 | { | 583 | { |
584 | speex_bits_pack(bits, 0, params->pitch_bits); | 584 | speex_bits_pack(bits, 0, params->pitch_bits); |
585 | speex_bits_pack(bits, 0, params->gain_bits); | 585 | speex_bits_pack(bits, 0, params->gain_bits); |
586 | for (i=0;i<nsf;i++) | 586 | SPEEX_MEMSET(exc, 0, nsf); |
587 | exc[i]=0; | ||
588 | return start; | 587 | return start; |
589 | } | 588 | } |
590 | 589 | ||
@@ -621,16 +620,13 @@ spx_word32_t *cumul_gain | |||
621 | for (i=0;i<N;i++) | 620 | for (i=0;i<N;i++) |
622 | { | 621 | { |
623 | pitch=nbest[i]; | 622 | pitch=nbest[i]; |
624 | for (j=0;j<nsf;j++) | 623 | SPEEX_MEMSET(exc, 0, nsf); |
625 | exc[j]=0; | ||
626 | err=pitch_gain_search_3tap(target, ak, awk1, awk2, exc, gain_cdbk, gain_cdbk_size, pitch, p, nsf, | 624 | err=pitch_gain_search_3tap(target, ak, awk1, awk2, exc, gain_cdbk, gain_cdbk_size, pitch, p, nsf, |
627 | bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain, scaledown); | 625 | bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain, scaledown); |
628 | if (err<best_err || best_err<0) | 626 | if (err<best_err || best_err<0) |
629 | { | 627 | { |
630 | for (j=0;j<nsf;j++) | 628 | SPEEX_COPY(best_exc, exc, nsf); |
631 | best_exc[j]=exc[j]; | 629 | SPEEX_COPY(best_target, new_target, nsf); |
632 | for (j=0;j<nsf;j++) | ||
633 | best_target[j]=new_target[j]; | ||
634 | best_err=err; | 630 | best_err=err; |
635 | best_pitch=pitch; | 631 | best_pitch=pitch; |
636 | best_gain_index=cdbk_index; | 632 | best_gain_index=cdbk_index; |
@@ -646,10 +642,8 @@ spx_word32_t *cumul_gain | |||
646 | #endif | 642 | #endif |
647 | /*printf ("%f\n", cumul_gain);*/ | 643 | /*printf ("%f\n", cumul_gain);*/ |
648 | /*printf ("encode pitch: %d %d\n", best_pitch, best_gain_index);*/ | 644 | /*printf ("encode pitch: %d %d\n", best_pitch, best_gain_index);*/ |
649 | for (i=0;i<nsf;i++) | 645 | SPEEX_COPY(exc, best_exc, nsf); |
650 | exc[i]=best_exc[i]; | 646 | SPEEX_COPY(target, best_target, nsf); |
651 | for (i=0;i<nsf;i++) | ||
652 | target[i]=best_target[i]; | ||
653 | #ifdef FIXED_POINT | 647 | #ifdef FIXED_POINT |
654 | /* Scale target back up if needed */ | 648 | /* Scale target back up if needed */ |
655 | if (scaledown) | 649 | if (scaledown) |
@@ -739,8 +733,7 @@ int cdbk_offset | |||
739 | gain[0] = SHL16(gain[0],7); | 733 | gain[0] = SHL16(gain[0],7); |
740 | gain[1] = SHL16(gain[1],7); | 734 | gain[1] = SHL16(gain[1],7); |
741 | gain[2] = SHL16(gain[2],7); | 735 | gain[2] = SHL16(gain[2],7); |
742 | for (i=0;i<nsf;i++) | 736 | SPEEX_MEMSET(exc_out, 0, nsf); |
743 | exc_out[i]=0; | ||
744 | for (i=0;i<3;i++) | 737 | for (i=0;i<3;i++) |
745 | { | 738 | { |
746 | int j; | 739 | 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 | |||
1042 | #endif | 1042 | #endif |
1043 | 1043 | ||
1044 | /* We consider that the filter has had minimal adaptation if the following is true*/ | 1044 | /* We consider that the filter has had minimal adaptation if the following is true*/ |
1045 | if (!st->adapted && st->sum_adapt > QCONST32(M,15) && MULT16_32_Q15(st->leak_estimate,Syy) > MULT16_32_Q15(QCONST16(.03f,15),Syy)) | 1045 | if (!st->adapted && st->sum_adapt > SHL32(EXTEND32(M),15) && MULT16_32_Q15(st->leak_estimate,Syy) > MULT16_32_Q15(QCONST16(.03f,15),Syy)) |
1046 | { | 1046 | { |
1047 | st->adapted = 1; | 1047 | st->adapted = 1; |
1048 | } | 1048 | } |
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) | |||
293 | ALLOC(interp_qlpc, st->lpcSize, spx_coef_t); | 293 | ALLOC(interp_qlpc, st->lpcSize, spx_coef_t); |
294 | 294 | ||
295 | /* Move signals 1 frame towards the past */ | 295 | /* Move signals 1 frame towards the past */ |
296 | speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t)); | 296 | SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, st->max_pitch+2); |
297 | speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t)); | 297 | SPEEX_MOVE(st->swBuf, st->swBuf+st->frameSize, st->max_pitch+2); |
298 | 298 | ||
299 | if (st->highpass_enabled) | 299 | if (st->highpass_enabled) |
300 | highpass(in, in, st->frameSize, (st->isWideband?HIGHPASS_WIDEBAND:HIGHPASS_NARROWBAND)|HIGHPASS_INPUT, st->mem_hp); | 300 | 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) | |||
337 | 337 | ||
338 | /* Whole frame analysis (open-loop estimation of pitch and excitation gain) */ | 338 | /* Whole frame analysis (open-loop estimation of pitch and excitation gain) */ |
339 | { | 339 | { |
340 | int diff = st->windowSize-st->frameSize; | ||
340 | if (st->first) | 341 | if (st->first) |
341 | for (i=0;i<st->lpcSize;i++) | 342 | for (i=0;i<st->lpcSize;i++) |
342 | interp_lsp[i] = lsp[i]; | 343 | interp_lsp[i] = lsp[i]; |
@@ -361,11 +362,9 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
361 | 362 | ||
362 | bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize); | 363 | bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize); |
363 | bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize); | 364 | bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize); |
364 | 365 | ||
365 | for (i=0;i<st->windowSize-st->frameSize;i++) | 366 | SPEEX_COPY(st->sw, st->winBuf, diff); |
366 | st->sw[i] = st->winBuf[i]; | 367 | SPEEX_COPY(st->sw+diff, in, st->frameSize-diff); |
367 | for (;i<st->frameSize;i++) | ||
368 | st->sw[i] = in[i-st->windowSize+st->frameSize]; | ||
369 | filter_mem16(st->sw, bw_lpc1, bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole, stack); | 368 | filter_mem16(st->sw, bw_lpc1, bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole, stack); |
370 | 369 | ||
371 | open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize, | 370 | 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) | |||
397 | } | 396 | } |
398 | 397 | ||
399 | /*Compute "real" excitation*/ | 398 | /*Compute "real" excitation*/ |
400 | for (i=0;i<st->windowSize-st->frameSize;i++) | 399 | SPEEX_COPY(st->exc, st->winBuf, diff); |
401 | st->exc[i] = st->winBuf[i]; | 400 | SPEEX_COPY(st->exc+diff, in, st->frameSize-diff); |
402 | for (;i<st->frameSize;i++) | ||
403 | st->exc[i] = in[i-st->windowSize+st->frameSize]; | ||
404 | fir_mem16(st->exc, interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc, stack); | 401 | fir_mem16(st->exc, interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc, stack); |
405 | 402 | ||
406 | /* Compute open-loop excitation gain */ | 403 | /* Compute open-loop excitation gain */ |
@@ -415,15 +412,12 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
415 | } | 412 | } |
416 | 413 | ||
417 | #ifdef VORBIS_PSYCHO | 414 | #ifdef VORBIS_PSYCHO |
418 | for(i=0;i<256-st->frameSize;i++) | 415 | SPEEX_MOVE(st->psy_window, st->psy_window+st->frameSize, 256-st->frameSize); |
419 | st->psy_window[i] = st->psy_window[i+st->frameSize]; | 416 | SPEEX_COPY(&st->psy_window[256-st->frameSize], in, st->frameSize); |
420 | for(i=0;i<st->frameSize;i++) | ||
421 | st->psy_window[256-st->frameSize+i] = in[i]; | ||
422 | compute_curve(st->psy, st->psy_window, st->curve); | 417 | compute_curve(st->psy, st->psy_window, st->curve); |
423 | /*print_vec(st->curve, 128, "curve");*/ | 418 | /*print_vec(st->curve, 128, "curve");*/ |
424 | if (st->first) | 419 | if (st->first) |
425 | for (i=0;i<128;i++) | 420 | SPEEX_COPY(st->old_curve, st->curve, 128); |
426 | st->old_curve[i] = st->curve[i]; | ||
427 | #endif | 421 | #endif |
428 | 422 | ||
429 | /*VBR stuff*/ | 423 | /*VBR stuff*/ |
@@ -562,7 +556,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
562 | st->first=1; | 556 | st->first=1; |
563 | st->bounded_pitch = 1; | 557 | st->bounded_pitch = 1; |
564 | 558 | ||
565 | speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t)); | 559 | SPEEX_COPY(st->winBuf, in+2*st->frameSize-st->windowSize, st->windowSize-st->frameSize); |
566 | 560 | ||
567 | /* Clear memory (no need to really compute it) */ | 561 | /* Clear memory (no need to really compute it) */ |
568 | for (i=0;i<st->lpcSize;i++) | 562 | for (i=0;i<st->lpcSize;i++) |
@@ -739,8 +733,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
739 | for (i=0;i<st->lpcSize;i++) | 733 | for (i=0;i<st->lpcSize;i++) |
740 | mem[i]=SHL32(st->mem_sw[i],1); | 734 | mem[i]=SHL32(st->mem_sw[i],1); |
741 | filter_mem16(ringing, st->bw_lpc1, st->bw_lpc2, ringing, response_bound, st->lpcSize, mem, stack); | 735 | filter_mem16(ringing, st->bw_lpc1, st->bw_lpc2, ringing, response_bound, st->lpcSize, mem, stack); |
742 | for (i=response_bound;i<st->subframeSize;i++) | 736 | SPEEX_MEMSET(&ringing[response_bound], 0, st->subframeSize-response_bound); |
743 | ringing[i]=0; | ||
744 | #else | 737 | #else |
745 | iir_mem16(ringing, interp_qlpc, ringing, st->subframeSize, st->lpcSize, mem, stack); | 738 | iir_mem16(ringing, interp_qlpc, ringing, st->subframeSize, st->lpcSize, mem, stack); |
746 | for (i=0;i<st->lpcSize;i++) | 739 | for (i=0;i<st->lpcSize;i++) |
@@ -762,8 +755,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
762 | target[i]=EXTRACT16(SATURATE(SUB32(sw[i],PSHR32(ringing[i],1)),32767)); | 755 | target[i]=EXTRACT16(SATURATE(SUB32(sw[i],PSHR32(ringing[i],1)),32767)); |
763 | 756 | ||
764 | /* Reset excitation */ | 757 | /* Reset excitation */ |
765 | for (i=0;i<st->subframeSize;i++) | 758 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
766 | exc[i]=0; | ||
767 | 759 | ||
768 | /* If we have a long-term predictor (otherwise, something's wrong) */ | 760 | /* If we have a long-term predictor (otherwise, something's wrong) */ |
769 | speex_assert (SUBMODE(ltp_quant)); | 761 | speex_assert (SUBMODE(ltp_quant)); |
@@ -804,8 +796,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
804 | st->pitch[sub]=pitch; | 796 | st->pitch[sub]=pitch; |
805 | } | 797 | } |
806 | /* Quantization of innovation */ | 798 | /* Quantization of innovation */ |
807 | for (i=0;i<st->subframeSize;i++) | 799 | SPEEX_MEMSET(innov, 0, st->subframeSize); |
808 | innov[i]=0; | ||
809 | 800 | ||
810 | /* FIXME: Make sure this is save from overflows (so far so good) */ | 801 | /* FIXME: Make sure this is save from overflows (so far so good) */ |
811 | for (i=0;i<st->subframeSize;i++) | 802 | for (i=0;i<st->subframeSize;i++) |
@@ -867,8 +858,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
867 | char *tmp_stack=stack; | 858 | char *tmp_stack=stack; |
868 | VARDECL(spx_sig_t *innov2); | 859 | VARDECL(spx_sig_t *innov2); |
869 | ALLOC(innov2, st->subframeSize, spx_sig_t); | 860 | ALLOC(innov2, st->subframeSize, spx_sig_t); |
870 | for (i=0;i<st->subframeSize;i++) | 861 | SPEEX_MEMSET(innov2, 0, st->subframeSize); |
871 | innov2[i]=0; | ||
872 | for (i=0;i<st->subframeSize;i++) | 862 | for (i=0;i<st->subframeSize;i++) |
873 | target[i]=MULT16_16_P13(QCONST16(2.2f,13), target[i]); | 863 | target[i]=MULT16_16_P13(QCONST16(2.2f,13), target[i]); |
874 | SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2, | 864 | SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2, |
@@ -887,10 +877,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
887 | } | 877 | } |
888 | } | 878 | } |
889 | 879 | ||
890 | for (i=0;i<st->subframeSize;i++) | ||
891 | sw[i] = exc[i]; | ||
892 | /* Final signal synthesis from excitation */ | 880 | /* Final signal synthesis from excitation */ |
893 | iir_mem16(sw, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack); | 881 | iir_mem16(exc, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack); |
894 | 882 | ||
895 | /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */ | 883 | /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */ |
896 | if (st->complexity!=0) | 884 | if (st->complexity!=0) |
@@ -909,10 +897,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
909 | 897 | ||
910 | #ifdef VORBIS_PSYCHO | 898 | #ifdef VORBIS_PSYCHO |
911 | if (st->submodeID>=1) | 899 | if (st->submodeID>=1) |
912 | { | 900 | SPEEX_COPY(st->old_curve, st->curve, 128); |
913 | for (i=0;i<128;i++) | ||
914 | st->old_curve[i] = st->curve[i]; | ||
915 | } | ||
916 | #endif | 901 | #endif |
917 | 902 | ||
918 | if (st->submodeID==1) | 903 | if (st->submodeID==1) |
@@ -927,7 +912,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) | |||
927 | 912 | ||
928 | /* The next frame will not be the first (Duh!) */ | 913 | /* The next frame will not be the first (Duh!) */ |
929 | st->first = 0; | 914 | st->first = 0; |
930 | speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t)); | 915 | SPEEX_COPY(st->winBuf, in+2*st->frameSize-st->windowSize, st->windowSize-st->frameSize); |
931 | 916 | ||
932 | if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0) | 917 | if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0) |
933 | st->bounded_pitch = 1; | 918 | st->bounded_pitch = 1; |
@@ -980,8 +965,7 @@ void *nb_decoder_init(const SpeexMode *m) | |||
980 | 965 | ||
981 | /* st->excBuf = (spx_word16_t*)speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); */ | 966 | /* st->excBuf = (spx_word16_t*)speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); */ |
982 | st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; | 967 | st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; |
983 | for (i=0;i<st->frameSize + st->max_pitch + 1;i++) | 968 | SPEEX_MEMSET(st->excBuf, 0, st->frameSize + st->max_pitch); |
984 | st->excBuf[i]=0; | ||
985 | 969 | ||
986 | /* st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); */ | 970 | /* st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); */ |
987 | /* st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); */ | 971 | /* 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) | |||
1079 | innov_gain = compute_rms16(st->exc, st->frameSize); | 1063 | innov_gain = compute_rms16(st->exc, st->frameSize); |
1080 | noise_gain = MULT16_16_Q15(innov_gain, MULT16_16_Q15(fact, SUB16(Q15ONE,MULT16_16_Q15(pitch_gain,pitch_gain)))); | 1064 | noise_gain = MULT16_16_Q15(innov_gain, MULT16_16_Q15(fact, SUB16(Q15ONE,MULT16_16_Q15(pitch_gain,pitch_gain)))); |
1081 | /* Shift all buffers by one frame */ | 1065 | /* Shift all buffers by one frame */ |
1082 | speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); | 1066 | SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, 2*st->max_pitch + st->subframeSize + 12); |
1083 | 1067 | ||
1084 | 1068 | ||
1085 | pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT); | 1069 | 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) | |||
1094 | } | 1078 | } |
1095 | 1079 | ||
1096 | bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize); | 1080 | bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize); |
1097 | iir_mem16(&st->exc[-st->subframeSize], st->interp_qlpc, out, | 1081 | iir_mem16(&st->exc[-st->subframeSize], st->interp_qlpc, out, st->frameSize, |
1098 | st->frameSize, st->lpcSize, st->mem_sp, stack); | 1082 | st->lpcSize, st->mem_sp, stack); |
1099 | highpass(out, out, st->frameSize, HIGHPASS_NARROWBAND|HIGHPASS_OUTPUT, st->mem_hp); | 1083 | highpass(out, out, st->frameSize, HIGHPASS_NARROWBAND|HIGHPASS_OUTPUT, st->mem_hp); |
1100 | 1084 | ||
1101 | st->first = 0; | 1085 | st->first = 0; |
@@ -1229,7 +1213,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1229 | } | 1213 | } |
1230 | 1214 | ||
1231 | /* Shift all buffers by one frame */ | 1215 | /* Shift all buffers by one frame */ |
1232 | speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); | 1216 | SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, 2*st->max_pitch + st->subframeSize + 12); |
1233 | 1217 | ||
1234 | /* If null mode (no transmission), just set a couple things to zero*/ | 1218 | /* If null mode (no transmission), just set a couple things to zero*/ |
1235 | if (st->submodes[st->submodeID] == NULL) | 1219 | if (st->submodes[st->submodeID] == NULL) |
@@ -1346,8 +1330,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1346 | 1330 | ||
1347 | 1331 | ||
1348 | /* Reset excitation */ | 1332 | /* Reset excitation */ |
1349 | for (i=0;i<st->subframeSize;i++) | 1333 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
1350 | exc[i]=0; | ||
1351 | 1334 | ||
1352 | /*Adaptive codebook contribution*/ | 1335 | /*Adaptive codebook contribution*/ |
1353 | speex_assert (SUBMODE(ltp_unquant)); | 1336 | speex_assert (SUBMODE(ltp_unquant)); |
@@ -1411,8 +1394,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1411 | int q_energy; | 1394 | int q_energy; |
1412 | spx_word32_t ener; | 1395 | spx_word32_t ener; |
1413 | 1396 | ||
1414 | for (i=0;i<st->subframeSize;i++) | 1397 | SPEEX_MEMSET(innov, 0, st->subframeSize); |
1415 | innov[i]=0; | ||
1416 | 1398 | ||
1417 | /* Decode sub-frame gain correction */ | 1399 | /* Decode sub-frame gain correction */ |
1418 | if (SUBMODE(have_subframe_gain)==3) | 1400 | if (SUBMODE(have_subframe_gain)==3) |
@@ -1441,8 +1423,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1441 | char *tmp_stack=stack; | 1423 | char *tmp_stack=stack; |
1442 | VARDECL(spx_sig_t *innov2); | 1424 | VARDECL(spx_sig_t *innov2); |
1443 | ALLOC(innov2, st->subframeSize, spx_sig_t); | 1425 | ALLOC(innov2, st->subframeSize, spx_sig_t); |
1444 | for (i=0;i<st->subframeSize;i++) | 1426 | SPEEX_MEMSET(innov2, 0, st->subframeSize); |
1445 | innov2[i]=0; | ||
1446 | SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); | 1427 | SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); |
1447 | signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); | 1428 | signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); |
1448 | for (i=0;i<st->subframeSize;i++) | 1429 | for (i=0;i<st->subframeSize;i++) |
@@ -1469,8 +1450,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1469 | if (g>GAIN_SCALING) | 1450 | if (g>GAIN_SCALING) |
1470 | g=GAIN_SCALING; | 1451 | g=GAIN_SCALING; |
1471 | 1452 | ||
1472 | for (i=0;i<st->subframeSize;i++) | 1453 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
1473 | exc[i]=0; | ||
1474 | while (st->voc_offset<st->subframeSize) | 1454 | while (st->voc_offset<st->subframeSize) |
1475 | { | 1455 | { |
1476 | /* exc[st->voc_offset]= g*sqrt(2*ol_pitch)*ol_gain; | 1456 | /* exc[st->voc_offset]= g*sqrt(2*ol_pitch)*ol_gain; |
@@ -1505,8 +1485,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) | |||
1505 | multicomb(st->exc-st->subframeSize, out, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); | 1485 | multicomb(st->exc-st->subframeSize, out, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); |
1506 | multicomb(st->exc+st->subframeSize, out+2*st->subframeSize, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); | 1486 | multicomb(st->exc+st->subframeSize, out+2*st->subframeSize, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); |
1507 | } else { | 1487 | } else { |
1508 | for (i=0;i<st->frameSize;i++) | 1488 | SPEEX_COPY(out, &st->exc[-st->subframeSize], st->frameSize); |
1509 | out[i]=st->exc[i-st->subframeSize]; | ||
1510 | } | 1489 | } |
1511 | 1490 | ||
1512 | /* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */ | 1491 | /* 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) | |||
86 | } | 86 | } |
87 | #endif | 87 | #endif |
88 | 88 | ||
89 | /** Print warning message with integer argument to stderr */ | 89 | /** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */ |
90 | #ifndef OVERRIDE_SPEEX_MOVE | 90 | #ifndef OVERRIDE_SPEEX_COPY |
91 | static inline void *speex_move (void *dest, void *src, int n) | 91 | #define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) |
92 | { | ||
93 | return memmove(dest,src,n); | ||
94 | } | ||
95 | #endif | 92 | #endif |
96 | 93 | ||
97 | /** Print warning message with integer argument to stderr */ | 94 | /** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term |
95 | provides compile-time type checking */ | ||
98 | #ifndef OVERRIDE_SPEEX_MOVE | 96 | #ifndef OVERRIDE_SPEEX_MOVE |
99 | static inline void *speex_memset (void *s, int c, int n) | 97 | #define SPEEX_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) |
100 | { | 98 | #endif |
101 | return memset(s,c,n); | 99 | |
102 | } | 100 | /** Set n bytes of memory to value of c, starting at address s */ |
101 | #ifndef OVERRIDE_SPEEX_MEMSET | ||
102 | #define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst)))) | ||
103 | #endif | 103 | #endif |
104 | 104 | ||
105 | 105 | ||
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 | |||
337 | } | 337 | } |
338 | 338 | ||
339 | /* Do the new part */ | 339 | /* Do the new part */ |
340 | ptr = in+st->in_stride*(last_sample-N+1+j); | 340 | if (in != NULL) |
341 | for (;j<N;j++) | ||
342 | { | 341 | { |
343 | sum += MULT16_16(*ptr,st->sinc_table[samp_frac_num*st->filt_len+j]); | 342 | ptr = in+st->in_stride*(last_sample-N+1+j); |
344 | ptr += st->in_stride; | 343 | for (;j<N;j++) |
344 | { | ||
345 | sum += MULT16_16(*ptr,st->sinc_table[samp_frac_num*st->filt_len+j]); | ||
346 | ptr += st->in_stride; | ||
347 | } | ||
345 | } | 348 | } |
346 | 349 | ||
347 | *out = PSHR32(sum,15); | 350 | *out = PSHR32(sum,15); |
348 | out += st->out_stride; | 351 | out += st->out_stride; |
349 | out_sample++; | 352 | out_sample++; |
@@ -385,13 +388,16 @@ static int resampler_basic_direct_double(SpeexResamplerState *st, spx_uint32_t c | |||
385 | } | 388 | } |
386 | 389 | ||
387 | /* Do the new part */ | 390 | /* Do the new part */ |
388 | ptr = in+st->in_stride*(last_sample-N+1+j); | 391 | if (in != NULL) |
389 | for (;j<N;j++) | ||
390 | { | 392 | { |
391 | sum += MULT16_16(*ptr,(double)st->sinc_table[samp_frac_num*st->filt_len+j]); | 393 | ptr = in+st->in_stride*(last_sample-N+1+j); |
392 | ptr += st->in_stride; | 394 | for (;j<N;j++) |
395 | { | ||
396 | sum += MULT16_16(*ptr,(double)st->sinc_table[samp_frac_num*st->filt_len+j]); | ||
397 | ptr += st->in_stride; | ||
398 | } | ||
393 | } | 399 | } |
394 | 400 | ||
395 | *out = sum; | 401 | *out = sum; |
396 | out += st->out_stride; | 402 | out += st->out_stride; |
397 | out_sample++; | 403 | out_sample++; |
@@ -445,16 +451,20 @@ static int resampler_basic_interpolate_single(SpeexResamplerState *st, spx_uint3 | |||
445 | accum[2] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset]); | 451 | accum[2] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset]); |
446 | accum[3] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset+1]); | 452 | accum[3] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset+1]); |
447 | } | 453 | } |
448 | ptr = in+st->in_stride*(last_sample-N+1+j); | 454 | |
449 | /* Do the new part */ | 455 | if (in != NULL) |
450 | for (;j<N;j++) | ||
451 | { | 456 | { |
452 | spx_word16_t curr_in = *ptr; | 457 | ptr = in+st->in_stride*(last_sample-N+1+j); |
453 | ptr += st->in_stride; | 458 | /* Do the new part */ |
454 | accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]); | 459 | for (;j<N;j++) |
455 | accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]); | 460 | { |
456 | accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]); | 461 | spx_word16_t curr_in = *ptr; |
457 | accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]); | 462 | ptr += st->in_stride; |
463 | accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]); | ||
464 | accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]); | ||
465 | accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]); | ||
466 | accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]); | ||
467 | } | ||
458 | } | 468 | } |
459 | cubic_coef(frac, interp); | 469 | cubic_coef(frac, interp); |
460 | 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]); | 470 | 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 | |||
509 | accum[2] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset]); | 519 | accum[2] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset]); |
510 | accum[3] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset+1]); | 520 | accum[3] += MULT16_16(curr_mem,st->sinc_table[4+(j+1)*st->oversample-offset+1]); |
511 | } | 521 | } |
512 | ptr = in+st->in_stride*(last_sample-N+1+j); | 522 | if (in != NULL) |
513 | /* Do the new part */ | ||
514 | for (;j<N;j++) | ||
515 | { | 523 | { |
516 | double curr_in = *ptr; | 524 | ptr = in+st->in_stride*(last_sample-N+1+j); |
517 | ptr += st->in_stride; | 525 | /* Do the new part */ |
518 | accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]); | 526 | for (;j<N;j++) |
519 | accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]); | 527 | { |
520 | accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]); | 528 | double curr_in = *ptr; |
521 | accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]); | 529 | ptr += st->in_stride; |
530 | accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]); | ||
531 | accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]); | ||
532 | accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]); | ||
533 | accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]); | ||
534 | } | ||
522 | } | 535 | } |
523 | cubic_coef(frac, interp); | 536 | cubic_coef(frac, interp); |
524 | sum = interp[0]*accum[0] + interp[1]*accum[1] + interp[2]*accum[2] + interp[3]*accum[3]; | 537 | 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 | |||
966 | for (i=0;i<st->nb_channels;i++) | 979 | for (i=0;i<st->nb_channels;i++) |
967 | { | 980 | { |
968 | *out_len = bak_len; | 981 | *out_len = bak_len; |
969 | speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len); | 982 | if (in != NULL) |
983 | speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len); | ||
984 | else | ||
985 | speex_resampler_process_float(st, i, NULL, in_len, out+i, out_len); | ||
970 | } | 986 | } |
971 | st->in_stride = istride_save; | 987 | st->in_stride = istride_save; |
972 | st->out_stride = ostride_save; | 988 | st->out_stride = ostride_save; |
@@ -985,7 +1001,10 @@ int speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_i | |||
985 | for (i=0;i<st->nb_channels;i++) | 1001 | for (i=0;i<st->nb_channels;i++) |
986 | { | 1002 | { |
987 | *out_len = bak_len; | 1003 | *out_len = bak_len; |
988 | speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len); | 1004 | if (in != NULL) |
1005 | speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len); | ||
1006 | else | ||
1007 | speex_resampler_process_int(st, i, NULL, in_len, out+i, out_len); | ||
989 | } | 1008 | } |
990 | st->in_stride = istride_save; | 1009 | st->in_stride = istride_save; |
991 | st->out_stride = ostride_save; | 1010 | 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) | |||
70 | codec_free(ptr); | 70 | codec_free(ptr); |
71 | } | 71 | } |
72 | 72 | ||
73 | #define OVERRIDE_SPEEX_MOVE 1 | ||
74 | static inline void *speex_move (void *dest, void *src, int n) | ||
75 | { | ||
76 | return memmove(dest,src,n); | ||
77 | } | ||
78 | |||
79 | #define OVERRIDE_SPEEX_FATAL 1 | 73 | #define OVERRIDE_SPEEX_FATAL 1 |
80 | static inline void _speex_fatal(const char *str, const char *file, int line) | 74 | static inline void _speex_fatal(const char *str, const char *file, int line) |
81 | { | 75 | { |
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) | |||
354 | speex_encode_native(st->st_low, low, bits); | 354 | speex_encode_native(st->st_low, low, bits); |
355 | 355 | ||
356 | high = high - (st->windowSize-st->frame_size); | 356 | high = high - (st->windowSize-st->frame_size); |
357 | for (i=0;i<st->windowSize-st->frame_size;i++) | 357 | SPEEX_COPY(high, st->high, st->windowSize-st->frame_size); |
358 | high[i] = st->high[i]; | 358 | SPEEX_COPY(st->high, &high[st->frame_size], st->windowSize-st->frame_size); |
359 | for (i=0;i<st->windowSize-st->frame_size;i++) | ||
360 | st->high[i] = high[i+st->frame_size]; | ||
361 | 359 | ||
362 | 360 | ||
363 | ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t); | 361 | ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t); |
@@ -690,8 +688,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) | |||
690 | signal_div(target, target, scale, st->subframeSize); | 688 | signal_div(target, target, scale, st->subframeSize); |
691 | 689 | ||
692 | /* Reset excitation */ | 690 | /* Reset excitation */ |
693 | for (i=0;i<st->subframeSize;i++) | 691 | SPEEX_MEMSET(innov, 0, st->subframeSize); |
694 | innov[i]=0; | ||
695 | 692 | ||
696 | /*print_vec(target, st->subframeSize, "\ntarget");*/ | 693 | /*print_vec(target, st->subframeSize, "\ntarget");*/ |
697 | SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, | 694 | SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, |
@@ -705,8 +702,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) | |||
705 | char *tmp_stack=stack; | 702 | char *tmp_stack=stack; |
706 | VARDECL(spx_sig_t *innov2); | 703 | VARDECL(spx_sig_t *innov2); |
707 | ALLOC(innov2, st->subframeSize, spx_sig_t); | 704 | ALLOC(innov2, st->subframeSize, spx_sig_t); |
708 | for (i=0;i<st->subframeSize;i++) | 705 | SPEEX_MEMSET(innov2, 0, st->subframeSize); |
709 | innov2[i]=0; | ||
710 | for (i=0;i<st->subframeSize;i++) | 706 | for (i=0;i<st->subframeSize;i++) |
711 | target[i]=MULT16_16_P13(QCONST16(2.5f,13), target[i]); | 707 | target[i]=MULT16_16_P13(QCONST16(2.5f,13), target[i]); |
712 | 708 | ||
@@ -1018,8 +1014,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) | |||
1018 | if (st->innov_save) | 1014 | if (st->innov_save) |
1019 | { | 1015 | { |
1020 | innov_save = st->innov_save+2*offset; | 1016 | innov_save = st->innov_save+2*offset; |
1021 | for (i=0;i<2*st->subframeSize;i++) | 1017 | SPEEX_MEMSET(innov_save, 0, 2*st->subframeSize); |
1022 | innov_save[i]=0; | ||
1023 | } | 1018 | } |
1024 | 1019 | ||
1025 | /* LSP interpolation */ | 1020 | /* LSP interpolation */ |
@@ -1048,8 +1043,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) | |||
1048 | filter_ratio=(rl+.01)/(rh+.01); | 1043 | filter_ratio=(rl+.01)/(rh+.01); |
1049 | #endif | 1044 | #endif |
1050 | 1045 | ||
1051 | for (i=0;i<st->subframeSize;i++) | 1046 | SPEEX_MEMSET(exc, 0, st->subframeSize); |
1052 | exc[i]=0; | ||
1053 | if (!SUBMODE(innovation_unquant)) | 1047 | if (!SUBMODE(innovation_unquant)) |
1054 | { | 1048 | { |
1055 | spx_word32_t g; | 1049 | spx_word32_t g; |
@@ -1087,8 +1081,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) | |||
1087 | char *tmp_stack=stack; | 1081 | char *tmp_stack=stack; |
1088 | VARDECL(spx_sig_t *innov2); | 1082 | VARDECL(spx_sig_t *innov2); |
1089 | ALLOC(innov2, st->subframeSize, spx_sig_t); | 1083 | ALLOC(innov2, st->subframeSize, spx_sig_t); |
1090 | for (i=0;i<st->subframeSize;i++) | 1084 | SPEEX_MEMSET(innov2, 0, st->subframeSize); |
1091 | innov2[i]=0; | ||
1092 | SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, | 1085 | SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, |
1093 | bits, stack, &st->seed); | 1086 | bits, stack, &st->seed); |
1094 | signal_mul(innov2, innov2, MULT16_32_P15(QCONST16(0.4f,15),scale), st->subframeSize); | 1087 | 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 { | |||
63 | spx_uint32_t timestamp; /**< Timestamp for the packet */ | 63 | spx_uint32_t timestamp; /**< Timestamp for the packet */ |
64 | spx_uint32_t span; /**< Time covered by the packet (same units as timestamp) */ | 64 | spx_uint32_t span; /**< Time covered by the packet (same units as timestamp) */ |
65 | spx_uint16_t sequence; /**< RTP Sequence number if available (0 otherwise) */ | 65 | spx_uint16_t sequence; /**< RTP Sequence number if available (0 otherwise) */ |
66 | spx_uint16_t flags; /**< Info about the returned packet */ | ||
67 | spx_uint32_t user_data; /**< Put whatever data you like here (it's ignored by the jitter buffer) */ | 66 | spx_uint32_t user_data; /**< Put whatever data you like here (it's ignored by the jitter buffer) */ |
68 | }; | 67 | }; |
69 | 68 | ||
70 | /** Packet has been retrieved */ | 69 | /** Packet has been retrieved */ |
71 | #define JITTER_BUFFER_OK 0 | 70 | #define JITTER_BUFFER_OK 0 |
72 | /** Packet is missing */ | 71 | /** Packet is lost or is late */ |
73 | #define JITTER_BUFFER_MISSING 1 | 72 | #define JITTER_BUFFER_MISSING 1 |
74 | /** Packet is incomplete (does not cover the entire tick */ | 73 | /** A "fake" packet is meant to be inserted here to increase buffering */ |
75 | #define JITTER_BUFFER_INCOMPLETE 2 | 74 | #define JITTER_BUFFER_INSERTION 2 |
76 | /** There was an error in the jitter buffer */ | 75 | /** There was an error in the jitter buffer */ |
77 | #define JITTER_BUFFER_INTERNAL_ERROR -1 | 76 | #define JITTER_BUFFER_INTERNAL_ERROR -1 |
78 | /** Invalid argument */ | 77 | /** Invalid argument */ |
@@ -117,10 +116,12 @@ struct _JitterBufferPacket { | |||
117 | 116 | ||
118 | /** Initialises jitter buffer | 117 | /** Initialises jitter buffer |
119 | * | 118 | * |
120 | * @param tick Number of samples per "tick", i.e. the time period of the elements that will be retrieved | 119 | * @param step_size Starting value for the size of concleanment packets and delay |
120 | adjustment steps. Can be changed at any time using JITTER_BUFFER_SET_DELAY_STEP | ||
121 | and JITTER_BUFFER_GET_CONCEALMENT_SIZE. | ||
121 | * @return Newly created jitter buffer state | 122 | * @return Newly created jitter buffer state |
122 | */ | 123 | */ |
123 | JitterBuffer *jitter_buffer_init(void); | 124 | JitterBuffer *jitter_buffer_init(int step_size); |
124 | 125 | ||
125 | /** Restores jitter buffer to its original state | 126 | /** Restores jitter buffer to its original state |
126 | * | 127 | * |
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) | |||
126 | SpeexHeader *le_header; | 126 | SpeexHeader *le_header; |
127 | le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); | 127 | le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); |
128 | 128 | ||
129 | speex_move(le_header, header, sizeof(SpeexHeader)); | 129 | SPEEX_COPY(le_header, header, 1); |
130 | 130 | ||
131 | /*Make sure everything is now little-endian*/ | 131 | /*Make sure everything is now little-endian*/ |
132 | ENDIAN_SWITCH(le_header->speex_version_id); | 132 | ENDIAN_SWITCH(le_header->speex_version_id); |
@@ -168,7 +168,7 @@ SpeexHeader *speex_packet_to_header(char *packet, int size) | |||
168 | 168 | ||
169 | /* le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); */ | 169 | /* le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); */ |
170 | 170 | ||
171 | speex_move(le_header, packet, sizeof(SpeexHeader)); | 171 | SPEEX_COPY(le_header, (SpeexHeader*)packet, 1); |
172 | 172 | ||
173 | /*Make sure everything is converted correctly from little-endian*/ | 173 | /*Make sure everything is converted correctly from little-endian*/ |
174 | ENDIAN_SWITCH(le_header->speex_version_id); | 174 | ENDIAN_SWITCH(le_header->speex_version_id); |