shithub: opus

Download patch

ref: cb7a2a3d52f562792c2efe81b204048ef9a5065c
parent: 6c1f60494408fb4fd70ae4f6a1c788489bcc9c21
author: Jean-Marc Valin <[email protected]>
date: Mon Feb 11 11:44:48 EST 2008

Re-ordered the parameters in the stream: [energy, pitch index, pitch gains]
Also fixed a bug that was exposed by the change (and removed some warnings)

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -258,7 +258,6 @@
       }
    }
    find_spectral_pitch(st->fft, &st->psy, in, st->out_mem, MAX_PERIOD, (B+1)*N, C, &pitch_index);
-   ec_enc_uint(&st->enc, pitch_index, MAX_PERIOD-(B+1)*N);
    
    /* Compute MDCTs of the pitch part */
    compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C);
@@ -298,6 +297,9 @@
    /* Pitch prediction */
    compute_pitch_gain(st->mode, X, P, gains, bandE);
    quant_pitch(gains, st->mode->nbPBands, &st->enc);
+   
+   ec_enc_uint(&st->enc, pitch_index, MAX_PERIOD-(B+1)*N);
+
    pitch_quant_bands(st->mode, X, P, gains);
 
    //for (i=0;i<B*N;i++) printf("%f ",P[i]);printf("\n");
@@ -509,7 +511,7 @@
    }
 }
 
-int celt_decode(CELTDecoder *st, char *data, int len, celt_int16_t *pcm)
+int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm)
 {
    int i, c, N, B, C;
    N = st->block_size;
@@ -533,18 +535,21 @@
    ec_byte_readinit(&buf,data,len);
    ec_dec_init(&dec,&buf);
    
+   /* Get band energies */
+   unquant_energy(st->mode, bandE, st->oldBandE, &dec);
+   
+   /* Get the pitch gains */
+   unquant_pitch(gains, st->mode->nbPBands, &dec);
+   
    /* Get the pitch index */
    pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(B+1)*N);
    st->last_pitch_index = pitch_index;
    
-   /* Get band energies */
-   unquant_energy(st->mode, bandE, st->oldBandE, &dec);
-   
    /* Pitch MDCT */
    compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C);
 
    {
-      float bandEp[st->mode->nbEBands];
+      float bandEp[st->mode->nbEBands*C];
       compute_band_energies(st->mode, P, bandEp);
       normalise_bands(st->mode, P, bandEp);
    }
@@ -551,9 +556,6 @@
 
    if (C==2)
       stereo_mix(st->mode, P, bandE, 1);
-
-   /* Get the pitch gains */
-   unquant_pitch(gains, st->mode->nbPBands, &dec);
 
    /* Apply pitch gains */
    pitch_quant_bands(st->mode, X, P, gains);
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -70,7 +70,7 @@
 
 void celt_decoder_destroy(CELTDecoder *st);
 
-int celt_decode(CELTDecoder *st, char *data, int len, celt_int16_t *pcm);
+int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm);
 
 
 /* Mode calls */
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -39,7 +39,6 @@
 {
    kiss_fft_cpx * Fout2;
    kiss_fft_cpx * tw1;
-   kiss_fft_cpx t;
    int i,j;
    kiss_fft_cpx * Fout_beg = Fout;
    for (i=0;i<N;i++)
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -160,6 +160,9 @@
       case CELT_GET_NB_CHANNELS:
          *value = mode->nbChannels;
          break;
+      default:
+         return CELT_BAD_ARG;
    }
+   return CELT_OK;
 }
 
--- a/libcelt/pgain_table.h
+++ b/libcelt/pgain_table.h
@@ -1,8 +1,8 @@
 float pgain_table[1024] = {
+0., 0., 0., 0., 0., 0., 0., 0., 
 0.0787638, 0.0502377, 0.0370167, 0.0322025, 0.356783, 0.0669546, 0.0574281, 0.0260472, 
 0.5126, 0.499592, 0.460184, 0.032245, 0.0312514, 0.0289121, 0.0265145, 0.0207962, 
 0.373555, 0.468631, 0.0241895, 0.0194926, 0.0256133, 0.0238522, 0.0211873, 0.0148774, 
-0.00139974, 0.000760276, 0.00107237, 0.00095473, 0.00115105, 0.001434, 0.00173201, 0.00274601, 
 0.513634, 0.467355, 0.255641, 0.091945, 0.319676, 0.0593489, 0.0488637, 0.02425, 
 0.297209, 0.0228254, 0.189478, 0.0192015, 0.0263458, 0.0241322, 0.0262124, 0.015507, 
 0.0575023, 0.297549, 0.022103, 0.0219353, 0.0442874, 0.043595, 0.0413361, 0.0220558, 
--- a/libcelt/psy.c
+++ b/libcelt/psy.c
@@ -135,7 +135,6 @@
 {
    int i;
    float psd[len];
-   float mem;
    for (i=0;i<len;i++)
       mask[i] = X[i]*X[i];
    for (i=1;i<len-1;i++)
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -101,7 +101,6 @@
    int i;
    float prev = 0;
    float coef = m->ePredCoef;
-   float error[m->nbEBands];
    /* The .7 is a heuristic */
    float beta = .7*coef;
    for (i=0;i<m->nbEBands;i++)
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -192,7 +192,6 @@
 
    for (i=0;i<len;i++)
    {
-      int N = (bands[i+1]-bands[i])*BC;
       pulses[i] = bits2pulses(alloc, i, bits[i]);
       sum += alloc->bits[i][pulses[i]];
    }
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <string.h>
 
 int main(int argc, char *argv[])
 {
@@ -46,7 +47,7 @@
    int len;
    celt_int32_t frame_size, channels;
    int bytes_per_packet;
-   char data[1024];
+   unsigned char data[1024];
 
    double rmsd = 0;
    int count = 0;