shithub: opus

Download patch

ref: 827f93175bc532beab5c5d49eed6649282795708
parent: 52824c7931456beacb4354f2e3ad2a638fcb1d60
author: Jean-Marc Valin <[email protected]>
date: Tue May 6 19:21:55 EDT 2008

Packing the pitch parameters first to improve robustness to bit errors with
(hopefully) no other side effect

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -292,14 +292,7 @@
    /* Compute MDCTs of the pitch part */
    compute_mdcts(st->mode, st->mode->window, st->out_mem+pitch_index*C, freq);
 
-   quant_energy(st->mode, bandE, st->oldBandE, nbCompressedBytes*8/3, st->mode->prob, &st->enc);
-
-   if (C==2)
    {
-      stereo_mix(st->mode, X, bandE, 1);
-   }
-
-   {
       /* Normalise the pitch vector as well (discard the energies) */
       VARDECL(celt_ener_t, bandEp);
       ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, celt_ener_t);
@@ -311,8 +304,6 @@
    /* Check if we can safely use the pitch (i.e. effective gain isn't too high) */
    if (MULT16_32_Q15(QCONST16(.1f, 15),curr_power) + QCONST32(10.f,ENER_SHIFT) < pitch_power)
    {
-      if (C==2)
-         stereo_mix(st->mode, P, bandE, 1);
       /* Simulates intensity stereo */
       /*for (i=30;i<N*B;i++)
          X[i*C+1] = P[i*C+1] = 0;*/
@@ -330,8 +321,14 @@
       for (i=0;i<C*N;i++)
          P[i] = 0;
    }
-   
+   quant_energy(st->mode, bandE, st->oldBandE, nbCompressedBytes*8/3, st->mode->prob, &st->enc);
 
+   if (C==2)
+   {
+      stereo_mix(st->mode, X, bandE, 1);
+      stereo_mix(st->mode, P, bandE, 1);
+   }
+
    pitch_quant_bands(st->mode, P, gains);
 
    /*for (i=0;i<B*N;i++) printf("%f ",P[i]);printf("\n");*/
@@ -578,9 +575,6 @@
    ec_byte_readinit(&buf,data,len);
    ec_dec_init(&dec,&buf);
    
-   /* Get band energies */
-   unquant_energy(st->mode, bandE, st->oldBandE, len*8/3, st->mode->prob, &dec);
-   
    /* Get the pitch gains */
    has_pitch = unquant_pitch(gains, st->mode->nbPBands, &dec);
    
@@ -593,7 +587,10 @@
       /* FIXME: We could be more intelligent here and just not compute the MDCT */
       pitch_index = 0;
    }
-   
+
+   /* Get band energies */
+   unquant_energy(st->mode, bandE, st->oldBandE, len*8/3, st->mode->prob, &dec);
+
    /* Pitch MDCT */
    compute_mdcts(st->mode, st->mode->window, st->out_mem+pitch_index*C, freq);