shithub: opus

Download patch

ref: ce4dd367c2b9ffc2b079cde28dd724b94776376d
parent: 017fa857754e15a91910f711c9d3c99d3f7d8752
author: Jean-Marc Valin <[email protected]>
date: Fri May 7 03:45:18 EDT 2010

More work on variable frame size (getting rid of FRAMESIZE() )

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -53,7 +53,7 @@
    int i, c, N;
    const celt_int16 *eBands = m->eBands;
    const int C = CHANNELS(_C);
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    for (c=0;c<C;c++)
    {
       for (i=0;i<m->nbEBands;i++)
@@ -92,7 +92,7 @@
    int i, c, N;
    const celt_int16 *eBands = m->eBands;
    const int C = CHANNELS(_C);
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    for (c=0;c<C;c++)
    {
       i=0; do {
@@ -116,7 +116,7 @@
    int i, c, N;
    const celt_int16 *eBands = m->eBands;
    const int C = CHANNELS(_C);
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    for (c=0;c<C;c++)
    {
       for (i=0;i<m->nbEBands;i++)
@@ -138,7 +138,7 @@
    int i, c, N;
    const celt_int16 *eBands = m->eBands;
    const int C = CHANNELS(_C);
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    for (c=0;c<C;c++)
    {
       for (i=0;i<m->nbEBands;i++)
@@ -161,7 +161,7 @@
    int i, c, N;
    const celt_int16 *eBands = m->eBands;
    const int C = CHANNELS(_C);
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    for (c=0;c<C;c++)
    {
       for (i=0;i<m->nbEBands;i++)
@@ -195,7 +195,7 @@
    int i, c, N;
    const celt_int16 *eBands = m->eBands;
    const int C = CHANNELS(_C);
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    if (C>2)
       celt_fatal("denormalise_bands() not implemented for >2 channels");
    for (c=0;c<C;c++)
@@ -220,7 +220,7 @@
    }
 }
 
-int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod)
+int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod, int M)
 {
    int j, c;
    celt_word16 g;
@@ -228,7 +228,7 @@
    const int C = CHANNELS(_C);
    celt_word32 Sxy=0, Sxx=0, Syy=0;
    int len = m->pitchEnd;
-   const int N = FRAMESIZE(m);
+   int N = M*m->eBands[m->nbEBands+1];
 #ifdef FIXED_POINT
    int shift = 0;
    celt_word32 maxabs=0;
@@ -313,7 +313,7 @@
    }
 }
 
-void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C)
+void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C, int M)
 {
    int j, c, N;
    celt_word16 gain;
@@ -321,7 +321,7 @@
    const int C = CHANNELS(_C);
    int len = m->pitchEnd;
 
-   N = FRAMESIZE(m);
+   N = M*m->eBands[m->nbEBands+1];
    gain = ADD16(QCONST16(.5f,14), MULT16_16_16(QCONST16(.05f,14),gain_id));
    delta = PDIV32_16(gain, len);
    if (pred)
@@ -385,7 +385,7 @@
    const int C = CHANNELS(_C);
    const celt_int16 * restrict eBands = m->eBands;
    
-   N0 = FRAMESIZE(m);
+   N0 = M*m->eBands[m->nbEBands+1];
 
    for (c=0;c<C;c++)
    {
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -73,9 +73,9 @@
  * @param gains Gain computed for each pitch band (returned)
  * @param bank Square root of the energy for each band
  */
-int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod);
+int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod, int M);
 
-void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C);
+void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C, int M);
 
 int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int _C, int M);
 
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -334,7 +334,7 @@
    } else {
       const mdct_lookup *lookup = &mode->mdct[LM];
       const int overlap = OVERLAP(mode);
-      int N = FRAMESIZE(mode);
+      int N = mode->shortMdctSize<<LM;
       int B = 1;
       int b, c;
       VARDECL(celt_word32, x);
@@ -371,7 +371,7 @@
 {
    int c, N4;
    const int C = CHANNELS(_C);
-   const int N = FRAMESIZE(mode);
+   const int N = mode->shortMdctSize<<LM;
    const int overlap = OVERLAP(mode);
    N4 = (N-overlap)>>1;
    for (c=0;c<C;c++)
@@ -687,7 +687,7 @@
       SAVE_STACK;
       ALLOC(x_lp, (2*N-2*N4)>>1, celt_word16);
       pitch_downsample(in, x_lp, 2*N-2*N4, N, C, &st->xmem, &st->pitch_buf[MAX_PERIOD>>1]);
-      pitch_search(st->mode, x_lp, st->pitch_buf, 2*N-2*N4, MAX_PERIOD-(2*N-2*N4), &pitch_index, &st->xmem);
+      pitch_search(st->mode, x_lp, st->pitch_buf, 2*N-2*N4, MAX_PERIOD-(2*N-2*N4), &pitch_index, &st->xmem, M);
       RESTORE_STACK;
    }
 
@@ -699,11 +699,11 @@
    if (has_pitch)
    {
       compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, pitch_freq, C, LM);
-      has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id, C, &st->gain_prod);
+      has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id, C, &st->gain_prod, M);
    }
    
    if (has_pitch)
-      apply_pitch(st->mode, freq, pitch_freq, gain_id, 1, C);
+      apply_pitch(st->mode, freq, pitch_freq, gain_id, 1, C, M);
 
    compute_band_energies(st->mode, freq, bandE, C, M);
    for (i=0;i<st->mode->nbEBands*C;i++)
@@ -904,7 +904,7 @@
       CELT_MOVE(st->out_mem, st->out_mem+C*N, C*(MAX_PERIOD+st->overlap-N));
 
       if (has_pitch)
-         apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C);
+         apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C, M);
       
       compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem, C, LM);
 
@@ -1311,7 +1311,7 @@
       pitch_downsample(st->out_mem, pitch_buf, MAX_PERIOD, MAX_PERIOD,
                        C, mem0, mem1);
       pitch_search(st->mode, pitch_buf+((MAX_PERIOD-len)>>1), pitch_buf, len,
-                   MAX_PERIOD-len-100, &pitch_index, &tmp);
+                   MAX_PERIOD-len-100, &pitch_index, &tmp, 1<<LM);
       pitch_index = MAX_PERIOD-len-pitch_index;
       st->last_pitch_index = pitch_index;
    } else {
@@ -1596,7 +1596,7 @@
    CELT_MOVE(st->decode_mem, st->decode_mem+C*N, C*(DECODE_BUFFER_SIZE+st->overlap-N));
 
    if (has_pitch)
-      apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C);
+      apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C, M);
 
    for (i=0;i<M*st->mode->eBands[start];i++)
       freq[i] = 0;
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -95,8 +95,6 @@
 #define CELT_RESET_STATE_REQUEST        8
 #define CELT_RESET_STATE       CELT_RESET_STATE_REQUEST
 
-/** GET the frame size used in the current mode */
-#define CELT_GET_FRAME_SIZE   1000
 /** GET the lookahead used in the current mode */
 #define CELT_GET_LOOKAHEAD    1001
 /** GET the sample rate used in the current mode */
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -61,9 +61,6 @@
       return CELT_INVALID_MODE;
    switch (request)
    {
-      case CELT_GET_FRAME_SIZE:
-         *value = mode->mdctSize;
-         break;
       case CELT_GET_LOOKAHEAD:
          *value = mode->overlap;
          break;
@@ -350,7 +347,7 @@
    
    /* Overlap must be divisible by 4 */
    if (mode->nbShortMdcts > 1)
-      mode->overlap = ((frame_size/mode->nbShortMdcts)>>2)<<2; 
+      mode->overlap = (mode->shortMdctSize>>2)<<2;
    else
       mode->overlap = (frame_size>>3)<<2;
 
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -148,11 +148,11 @@
 
 }
 
-void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem)
+void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem, int M)
 {
    int i, j;
    const int lag = MAX_PERIOD;
-   const int N = FRAMESIZE(m);
+   const int N = M*m->eBands[m->nbEBands+1];
    int best_pitch[2]={0};
    VARDECL(celt_word16, x_lp4);
    VARDECL(celt_word16, y_lp4);
--- a/libcelt/pitch.h
+++ b/libcelt/pitch.h
@@ -43,6 +43,6 @@
 
 void pitch_downsample(const celt_sig * restrict x, celt_word16 * restrict x_lp, int len, int end, int _C, celt_sig * restrict xmem, celt_word16 * restrict filt_mem);
 
-void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem);
+void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem, int M);
 
 #endif
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -126,7 +126,6 @@
       celt_encoder_ctl(enc,CELT_SET_COMPLEXITY(complexity));
    }
    
-   celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);
    in = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16));
    out = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16));
    while (!feof(fin))
--- a/tools/celtdec.c
+++ b/tools/celtdec.c
@@ -322,7 +322,8 @@
       return NULL;
    }
    
-   celt_mode_info(*mode, CELT_GET_FRAME_SIZE, frame_size);
+   /*celt_mode_info(*mode, CELT_GET_FRAME_SIZE, frame_size);*/
+   *frame_size = header.frame_size;
    *granule_frame_size = *frame_size;
 
    if (!*rate)
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -500,7 +500,7 @@
    snprintf(vendor_string, sizeof(vendor_string), "Encoded with CELT %s (bitstream: %d)\n",CELT_VERSION,bitstream);
    comment_init(&comments, &comments_length, vendor_string);
 
-   celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);   
+   /*celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);*/
    
    celt_header_init(&header, mode, chan);
    header.nb_channels = chan;