shithub: opus

Download patch

ref: 62290065100f4f7af379b839deb54089847900c0
parent: 1a3ed79cbe547b53693bc79ca3a7af07fbb919cc
author: Jean-Marc Valin <[email protected]>
date: Sun Apr 20 18:16:02 EDT 2008

Better indexing of pre/de-emphasis in celt_{en|de}code().

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -256,11 +256,16 @@
    CELT_COPY(in, st->in_mem, C*st->overlap);
    for (c=0;c<C;c++)
    {
+      const celt_int16_t * restrict pcmp = pcm+c;
+      celt_sig_t * restrict inp = in+C*st->overlap+c;
       for (i=0;i<N;i++)
       {
-         celt_sig_t tmp = SHL32(EXTEND32(pcm[C*i+c]), SIG_SHIFT);
-         in[C*(i+st->overlap)+c] = SUB32(tmp, SHR32(MULT16_16(preemph,st->preemph_memE[c]),1));
-         st->preemph_memE[c] = pcm[C*i+c];
+         /* Apply pre-emphasis */
+         celt_sig_t tmp = SHL32(EXTEND32(*pcmp), SIG_SHIFT);
+         *inp = SUB32(tmp, SHR32(MULT16_16(preemph,st->preemph_memE[c]),1));
+         st->preemph_memE[c] = *pcmp;
+         inp += C;
+         pcmp += C;
       }
    }
    CELT_COPY(st->in_mem, in+C*(2*N-2*N4-st->overlap), C*st->overlap);
@@ -373,12 +378,15 @@
    for (c=0;c<C;c++)
    {
       int j;
+      const celt_sig_t * restrict outp=st->out_mem+C*(MAX_PERIOD-N)+c;
+      celt_int16_t * restrict pcmp = pcm+c;
       for (j=0;j<N;j++)
       {
-         celt_sig_t tmp = ADD32(st->out_mem[C*(MAX_PERIOD-N)+C*j+c],
-                                MULT16_32_Q15(preemph,st->preemph_memD[c]));
+         celt_sig_t tmp = ADD32(*outp, MULT16_32_Q15(preemph,st->preemph_memD[c]));
          st->preemph_memD[c] = tmp;
-         pcm[C*j+c] = SIG2INT16(tmp);
+         *pcmp = SIG2INT16(tmp);
+         pcmp += C;
+         outp += C;
       }
    }
    
@@ -626,12 +634,15 @@
    for (c=0;c<C;c++)
    {
       int j;
+      const celt_sig_t * restrict outp=st->out_mem+C*(MAX_PERIOD-N)+c;
+      celt_int16_t * restrict pcmp = pcm+c;
       for (j=0;j<N;j++)
       {
-         celt_sig_t tmp = ADD32(st->out_mem[C*(MAX_PERIOD-N)+C*j+c],
-                                MULT16_32_Q15(preemph,st->preemph_memD[c]));
+         celt_sig_t tmp = ADD32(*outp, MULT16_32_Q15(preemph,st->preemph_memD[c]));
          st->preemph_memD[c] = tmp;
-         pcm[C*j+c] = SIG2INT16(tmp);
+         *pcmp = SIG2INT16(tmp);
+         pcmp += C;
+         outp += C;
       }
    }