shithub: opus

Download patch

ref: 16ca18b9b087fffb7fec386115e759e334a629ad
parent: 9d1decd1bbdd0eba00697bee95d53d7e0d454c57
author: Jean-Marc Valin <[email protected]>
date: Wed Jun 18 19:44:48 EDT 2008

Automatically choosing the overlap based on the frame size.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -373,7 +373,7 @@
          transient_time = -1;
          maxR = 0;
       }
-      if (maxR > 10)
+      if (maxR > 30)
       {
          float gain_1;
          ec_enc_bits(&st->enc, 1, 1);
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -108,7 +108,7 @@
  @param error Returned error code (if NULL, no error will be returned)
  @return A newly created mode
 */
-EXPORT CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lookahead, int *error);
+EXPORT CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *error);
 
 /** Destroys a mode struct. Only call this after all encoders and decoders
     using this mode are destroyed as well.
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -231,12 +231,11 @@
    m = malloc(nb*sizeof(CELTMode*));
    for (i=0;i<nb;i++)
    {
-      int Fs, ch, frame, overlap;
-      Fs      = atoi(argv[4*i+1]);
-      ch      = atoi(argv[4*i+2]);
-      frame   = atoi(argv[4*i+3]);
-      overlap = atoi(argv[4*i+4]);
-      m[i] = celt_mode_create(Fs, ch, frame, overlap, NULL);
+      int Fs, ch, frame;
+      Fs      = atoi(argv[3*i+1]);
+      ch      = atoi(argv[3*i+2]);
+      frame   = atoi(argv[3*i+3]);
+      m[i] = celt_mode_create(Fs, ch, frame, NULL);
    }
    file = fopen("static_modes.c", "w");
    dump_modes(file, m, nb);
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -270,7 +270,7 @@
    mode->energy_alloc = alloc;
 }
 
-CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lookahead, int *error)
+CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *error)
 {
    int i;
 #ifdef STDIN_TUNING
@@ -335,18 +335,10 @@
          *error = CELT_BAD_ARG;
       return NULL;
    }
-   if (lookahead < 32 || lookahead > frame_size)
-   {
-      celt_warning("The overlap must be between 32 and the frame size");
-      if (error)
-         *error = CELT_BAD_ARG;
-      return NULL;
-   }
    res = (Fs+frame_size)/(2*frame_size);
    
    mode = celt_alloc(sizeof(CELTMode));
    mode->Fs = Fs;
-   mode->overlap = lookahead;
    mode->mdctSize = frame_size;
    mode->nbChannels = channels;
    mode->eBands = compute_ebands(Fs, frame_size, &mode->nbEBands);
@@ -353,6 +345,23 @@
    compute_pbands(mode, res);
    mode->ePredCoef = QCONST16(.8f,15);
    
+   if (frame_size <= 64)
+   {
+      mode->nbShortMdcts = 1;
+   } else if (frame_size <= 256)
+   {
+      mode->nbShortMdcts = 2;
+   } else if (frame_size <= 384)
+   {
+      mode->nbShortMdcts = 3;
+   } else {
+      mode->nbShortMdcts = 4;
+   }
+   if (mode->nbShortMdcts > 1)
+      mode->overlap = frame_size/mode->nbShortMdcts;
+   else
+      mode->overlap = frame_size/2;
+   
    compute_allocation_table(mode, res);
    /*printf ("%d bands\n", mode->nbEBands);*/
    
@@ -380,7 +389,6 @@
    mdct_init(&mode->mdct, 2*mode->mdctSize);
    mode->fft = pitch_state_alloc(MAX_PERIOD);
 
-   mode->nbShortMdcts = 4;
    mode->shortMdctSize = mode->mdctSize/mode->nbShortMdcts;
    mdct_init(&mode->shortMdct, 2*mode->shortMdctSize);
    mode->shortWindow = mode->window;
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -39,7 +39,7 @@
 #include "psy.h"
 #include "pitch.h"
 
-#define CELT_BITSTREAM_VERSION 0x80000002
+#define CELT_BITSTREAM_VERSION 0x80000003
 
 #ifdef STATIC_MODES
 #include "static_modes.h"
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -51,17 +51,17 @@
    celt_int32_t frame_size, channels;
    int bytes_per_packet;
    unsigned char data[1024];
-   int rate, overlap;
+   int rate;
 #if !(defined (FIXED_POINT) && defined(STATIC_MODES))
    int i;
    double rmsd = 0;
 #endif
    int count = 0;
-   int skip;
+   celt_int32_t skip;
    celt_int16_t *in, *out;
-   if (argc != 9 && argc != 8)
+   if (argc != 8 && argc != 7)
    {
-      fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> <overlap> <bytes per packet> <input> <output>\n");
+      fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> <bytes per packet> <input> <output>\n");
       return 1;
    }
    
@@ -68,9 +68,8 @@
    rate = atoi(argv[1]);
    channels = atoi(argv[2]);
    frame_size = atoi(argv[3]);
-   overlap = atoi(argv[4]);
-   skip = overlap;
-   mode = celt_mode_create(rate, channels, frame_size, overlap, NULL);
+   mode = celt_mode_create(rate, channels, frame_size, NULL);
+   celt_mode_info(mode, CELT_GET_LOOKAHEAD, &skip);
    
    if (mode == NULL)
    {
@@ -78,13 +77,13 @@
       return 1;
    }
    
-   bytes_per_packet = atoi(argv[5]);
+   bytes_per_packet = atoi(argv[4]);
    if (bytes_per_packet < 0 || bytes_per_packet > 200)
    {
       fprintf (stderr, "bytes per packet must be between 10 and 200\n");
       return 1;
    }
-   inFile = argv[6];
+   inFile = argv[5];
    fin = fopen(inFile, "rb");
    if (!fin)
    {
@@ -91,7 +90,7 @@
       fprintf (stderr, "Could not open input file %s\n", argv[6]);
       return 1;
    }
-   outFile = argv[7];
+   outFile = argv[6];
    fout = fopen(outFile, "wb+");
    if (!fout)
    {
@@ -141,7 +140,7 @@
          data[rand()%8] ^= 1<<rand()%8;
 #endif
       /* This is to simulate packet loss */
-      if (argc==9 && rand()%1000<atoi(argv[8]))
+      if (argc==9 && rand()%1000<atoi(argv[7]))
       /*if (errors && (errors%2==0))*/
          celt_decode(dec, NULL, len, out);
       else
--- a/tools/celtdec.c
+++ b/tools/celtdec.c
@@ -298,7 +298,7 @@
       fprintf (stderr, "Unsupported number of channels: %d\n", header.nb_channels);
       return NULL;
    }
-   *mode = celt_mode_create(header.sample_rate, header.nb_channels, header.frame_size, header.overlap, NULL);
+   *mode = celt_mode_create(header.sample_rate, header.nb_channels, header.frame_size, NULL);
    if (*mode == NULL)
    {
       fprintf (stderr, "Mode initialization failed.\n");
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -455,7 +455,7 @@
       fprintf (stderr, "Only mono and stereo are supported\n");
       return 1;
    }
-   mode = celt_mode_create(rate, chan, 256, 128, NULL);
+   mode = celt_mode_create(rate, chan, 256, NULL);
    if (!mode)
       return 1;
    celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);