[xiph-commits] r14220 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Fri Nov 23 04:05:00 PST 2007


Author: jm
Date: 2007-11-23 04:04:59 -0800 (Fri, 23 Nov 2007)
New Revision: 14220

Modified:
   trunk/speex/libspeex/bits.c
   trunk/speex/libspeex/buffer.c
   trunk/speex/libspeex/cb_search.c
   trunk/speex/libspeex/jitter.c
   trunk/speex/libspeex/kiss_fft.c
   trunk/speex/libspeex/ltp.c
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/os_support.h
   trunk/speex/libspeex/sb_celp.c
   trunk/speex/libspeex/speex_header.c
Log:
Patch by Thom Johansen: define and use SPEEX_MEMSET, SPEEX_MEMMOVE and
SPEEX_MEMCPY.


Modified: trunk/speex/libspeex/bits.c
===================================================================
--- trunk/speex/libspeex/bits.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/bits.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -149,10 +149,7 @@
    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;
 }
@@ -225,8 +222,6 @@
       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;

Modified: trunk/speex/libspeex/buffer.c
===================================================================
--- trunk/speex/libspeex/buffer.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/buffer.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -79,11 +79,11 @@
    end1 = end;
    if (end1 > st->size)
       end1 = st->size;
-   speex_move(st->data + st->write_ptr, data, end1 - st->write_ptr);
+   SPEEX_COPY(st->data + st->write_ptr, data, end1 - st->write_ptr);
    if (end > st->size)
    {
       end -= st->size;
-      speex_move(st->data, data+end1 - st->write_ptr, end);
+      SPEEX_COPY(st->data, data+end1 - st->write_ptr, end);
    }
    st->available += len;
    if (st->available > st->size)
@@ -100,7 +100,7 @@
 int speex_buffer_writezeros(SpeexBuffer *st, int len)
 {
    /* This is almost the same as for speex_buffer_write() but using 
-   speex_memset() instead of speex_move(). Update accordingly. */
+   SPEEX_MEMSET() instead of SPEEX_COPY(). Update accordingly. */
    int end;
    int end1;
    if (len > st->size)
@@ -111,11 +111,11 @@
    end1 = end;
    if (end1 > st->size)
       end1 = st->size;
-   speex_memset(st->data + st->write_ptr, 0, end1 - st->write_ptr);
+   SPEEX_MEMSET(st->data + st->write_ptr, 0, end1 - st->write_ptr);
    if (end > st->size)
    {
       end -= st->size;
-      speex_memset(st->data, 0, end);
+      SPEEX_MEMSET(st->data, 0, end);
    }
    st->available += len;
    if (st->available > st->size)
@@ -135,19 +135,19 @@
    char *data = _data;
    if (len > st->available)
    {
-      speex_memset(data+st->available, 0, st->size-st->available);
+      SPEEX_MEMSET(data+st->available, 0, st->size-st->available);
       len = st->available;
    }
    end = st->read_ptr + len;
    end1 = end;
    if (end1 > st->size)
       end1 = st->size;
-   speex_move(data, st->data + st->read_ptr, end1 - st->read_ptr);
+   SPEEX_COPY(data, st->data + st->read_ptr, end1 - st->read_ptr);
 
    if (end > st->size)
    {
       end -= st->size;
-      speex_move(data+end1 - st->read_ptr, st->data, end);
+      SPEEX_COPY(data+end1 - st->read_ptr, st->data, end);
    }
    st->available -= len;
    st->read_ptr += len;

Modified: trunk/speex/libspeex/cb_search.c
===================================================================
--- trunk/speex/libspeex/cb_search.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/cb_search.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -148,8 +148,7 @@
    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);
 
@@ -343,11 +342,10 @@
       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);
@@ -594,8 +592,7 @@
 
    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);
 }
 
 

Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/jitter.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -120,8 +120,8 @@
       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;

Modified: trunk/speex/libspeex/kiss_fft.c
===================================================================
--- trunk/speex/libspeex/kiss_fft.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/kiss_fft.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -509,7 +509,7 @@
        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);

Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/ltp.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -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
@@ -495,8 +496,7 @@
       *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;
@@ -580,8 +580,7 @@
    {
       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;
    }
    
@@ -618,16 +617,13 @@
    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;
@@ -643,10 +639,8 @@
 #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)
@@ -735,8 +729,7 @@
    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;

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/nb_celp.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -292,8 +292,8 @@
    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);
@@ -336,6 +336,7 @@
 
    /* 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];
@@ -360,11 +361,9 @@
          
          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, 
@@ -396,10 +395,8 @@
       }
       
       /*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 */
@@ -414,15 +411,12 @@
    }
 
 #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*/
@@ -561,7 +555,7 @@
       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++)
@@ -738,8 +732,7 @@
       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++)
@@ -761,8 +754,7 @@
          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));
@@ -803,8 +795,7 @@
          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++)
@@ -866,9 +857,8 @@
             char *tmp_stack=stack;
             VARDECL(spx_sig_t *innov2);
             ALLOC(innov2, st->subframeSize, spx_sig_t);
+            SPEEX_MEMSET(innov2, 0, st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
-               innov2[i]=0;
-            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, 
                                       SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
@@ -886,10 +876,8 @@
          }
       }
 
-      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)
@@ -908,10 +896,7 @@
 
 #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)
@@ -926,7 +911,7 @@
 
    /* 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;
@@ -973,8 +958,7 @@
 
    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));
@@ -1067,7 +1051,7 @@
    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);
@@ -1081,11 +1065,9 @@
             speex_rand(noise_gain, &st->seed);
    }
 
-   for (i=0;i<st->frameSize;i++)
-      out[i]=st->exc[i-st->subframeSize];
    bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize);
-   iir_mem16(out, 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;
@@ -1216,7 +1198,7 @@
    }
 
    /* 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)
@@ -1235,10 +1217,8 @@
 
       st->first=1;
 
-      for (i=0;i<st->frameSize;i++)
-         out[i] = st->exc[i];
       /* Final signal synthesis from excitation */
-      iir_mem16(out, lpc, out, st->frameSize, st->lpcSize, st->mem_sp, stack);
+      iir_mem16(st->exc, lpc, out, st->frameSize, st->lpcSize, st->mem_sp, stack);
 
       st->count_lost=0;
       return 0;
@@ -1335,8 +1315,7 @@
 
 
       /* 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));
@@ -1400,8 +1379,7 @@
          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)
@@ -1430,8 +1408,7 @@
                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++)
@@ -1458,8 +1435,7 @@
             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;
@@ -1494,8 +1470,7 @@
       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 */

Modified: trunk/speex/libspeex/os_support.h
===================================================================
--- trunk/speex/libspeex/os_support.h	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/os_support.h	2007-11-23 12:04:59 UTC (rev 14220)
@@ -83,23 +83,23 @@
 }
 #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
 
+
 #ifndef OVERRIDE_SPEEX_FATAL
 static inline void _speex_fatal(const char *str, const char *file, int line)
 {

Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/sb_celp.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -354,10 +354,8 @@
    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 @@
          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,9 +702,8 @@
             char *tmp_stack=stack;
             VARDECL(spx_sig_t *innov2);
             ALLOC(innov2, st->subframeSize, spx_sig_t);
+            SPEEX_MEMSET(innov2, 0, st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
-               innov2[i]=0;
-            for (i=0;i<st->subframeSize;i++)
                target[i]=MULT16_16_P13(QCONST16(2.5f,13), target[i]);
 
             SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, 
@@ -997,8 +993,7 @@
       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 */
@@ -1027,8 +1022,7 @@
          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;
@@ -1066,8 +1060,7 @@
             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);
@@ -1084,9 +1077,7 @@
             innov_save[2*i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT));
       }
       
-      for (i=0;i<st->subframeSize;i++)
-         sp[i]=st->excBuf[i];
-      iir_mem16(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
+      iir_mem16(st->excBuf, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
                st->mem_sp, stack);
       for (i=0;i<st->subframeSize;i++)
          st->excBuf[i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT));

Modified: trunk/speex/libspeex/speex_header.c
===================================================================
--- trunk/speex/libspeex/speex_header.c	2007-11-23 03:17:39 UTC (rev 14219)
+++ trunk/speex/libspeex/speex_header.c	2007-11-23 12:04:59 UTC (rev 14220)
@@ -123,7 +123,7 @@
    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);
@@ -163,7 +163,7 @@
    
    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);



More information about the commits mailing list