diff --git a/libcelt/bands.c b/libcelt/bands.c
index 75ede9452449c03263eb35b2ca6a152dafa1380a..fe03eb7c0258f04623bcee05b4ecef06338aff5f 100644
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -53,7 +53,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank
    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 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor
    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 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank
    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 @@ void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_wor
    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 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor
    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 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
    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 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
    }
 }
 
-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 @@ int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P,
    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 @@ int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P,
    }
 }
 
-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 @@ void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id,
    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 @@ int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int
    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++)
    {
diff --git a/libcelt/bands.h b/libcelt/bands.h
index f0cc0c60918322f075e030a783ee4b8bc9561f9b..f42171d8029ff1d16763daac272471a598b47cb0 100644
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -73,9 +73,9 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
  * @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);
 
diff --git a/libcelt/celt.c b/libcelt/celt.c
index e5a0312f8d64c3ba38aee12483e51cda31268c54..c5ac3e978d2dfec746be5a32ac910558ffe36d89 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -334,7 +334,7 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * rest
    } 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 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
 {
    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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
       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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
    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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
       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 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p
       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 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int
    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;
diff --git a/libcelt/celt.h b/libcelt/celt.h
index 67c15e60a4d5b0ce78ae465605c9979ed30a8bb0..14dd3f8a3ef0659c7ba1571887cc49c5e31e647a 100644
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -95,8 +95,6 @@ extern "C" {
 #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 */
diff --git a/libcelt/modes.c b/libcelt/modes.c
index 198de47ea09555709ad55791d6389316d7e5128c..46b027a2b6eec34868a6dbe0b5bb20727292b919 100644
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -61,9 +61,6 @@ int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value)
       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 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
    
    /* 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;
 
diff --git a/libcelt/pitch.c b/libcelt/pitch.c
index 4b121696972dc95002fa2a2215d651a0011023c5..804b94121a283667559770244c888b346d8daa41 100644
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -148,11 +148,11 @@ void pitch_downsample(const celt_sig * restrict x, celt_word16 * restrict x_lp,
 
 }
 
-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);
diff --git a/libcelt/pitch.h b/libcelt/pitch.h
index 8f3bc0d86a69e155efdd3a8055e50a8f7ea20626..f94c441c99de204be86b59d7e305381fd41c7500 100644
--- 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
diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c
index ddd851bdd99636288a5de3212496d65e02a4b7d4..44b87523464e468fddc18f58a821927625c58033 100644
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -126,7 +126,6 @@ int main(int argc, char *argv[])
       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))
diff --git a/tools/celtdec.c b/tools/celtdec.c
index 191336be6ec0611db1fa52c54694f5cb84237234..b12b50a1e42400e02ebbb8abaf4c648e88f6477d 100644
--- a/tools/celtdec.c
+++ b/tools/celtdec.c
@@ -322,7 +322,8 @@ static CELTDecoder *process_header(ogg_packet *op, celt_int32 enh_enabled, celt_
       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)
diff --git a/tools/celtenc.c b/tools/celtenc.c
index 7123a399f1c65978b4ec9be80c0737c1c23b2dca..8cf71ad9696c8714c35da4270ac8140b435ffb49 100644
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -500,7 +500,7 @@ int main(int argc, char **argv)
    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;